java - CheckStyle 的行长检查是怎么回事?

标签 java eclipse checkstyle

我将 CheckStyle 设置为在 Eclipse 中检查超过 80 个字符的行,并且在我的编辑器中设置了一个 80 个字符的边距线。如果我将光标放在编辑器中一行代码的末尾,坐标读取(例如)1433、77,表示从左边开始的第 77 个字符列 - 但是当我在同一行上运行 CheckStyle 时,它​​说该行长 88 个字符!该行的末尾没有多余的制表符或其他空白字符,它肯定有 77 长。 CheckStyle 损坏了吗?

最佳答案

来自 Checkstyle 文档:

The calculation of the length of a line takes into account the number of expanded spaces for a tab character ('\t'). The default number of spaces is 8. To specify a different number of spaces, the user can set TreeWalker property tabWidth which applies to all Checks, including LineLength; or can set property tabWidth for LineLength alone.

http://checkstyle.sourceforge.net/config_sizes.html#LineLength

在 Eclipse 中执行此操作:

  • 从菜单中打开窗口 -> 首选项。
  • 选择Checkstyle
  • Known modules 下的搜索框中键入 TreeWalker
  • 在右侧的列表中选择TreeWalker
  • 点击打开
  • tabWidth 更改为 4。
  • 单击确定,然后再次单击确定

关于java - CheckStyle 的行长检查是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21758533/

相关文章:

Java:防止覆盖成员变量

android - 如何在 Eclipse 中编辑构建路径条目?

java - 将目录从 Assets 复制到数据文件夹

java - 在 eclipse 中断言条件

java - 表达可以简化。格纹

Java - 将工作拆分到多个线程

java - jsvc & Gradle - 没有控制台输出,Gradle 守护进程崩溃

spring-boot - 分析java代码时checkstyle错误

maven - 禁用 checkstyle maven 插件生成的源目录

java - GuavaCache invalidateAll() 与将变量设置为 null