Eclipse Checkstyle 禁用“Lline 有尾随空格”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15950671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse Checkstyle Disable "Lline has trailing spaces"
提问by James Oravec
I'm using eclipse on Win 7. I'm also using checkstyle and find that checkstyle is complaining about trailing white space in comments.
我在 Win 7 上使用 eclipse。我也在使用 checkstyle 并发现 checkstyle 抱怨注释中的尾随空格。
I wish to disable this check in checkstyle, not make any modifications to my environment as I wish to share the check style file with other developers in the office an ensure everyone can see the code in the same checkstyle "light" :)
我希望在 checkstyle 中禁用此检查,不要对我的环境进行任何修改,因为我希望与办公室中的其他开发人员共享检查样式文件,以确保每个人都可以在相同的检查样式“light”中看到代码:)
I'm okay with other built in features that would solve this problem. I've tried: Ctrl+Shift+F
and Ctrl+Alt+C
. Neither of which auto fix the trailing space automatically.
我对可以解决这个问题的其他内置功能没有意见。我试过:Ctrl+Shift+F
和Ctrl+Alt+C
。两者都不会自动修复尾随空格。
回答by James Oravec
Found the way to disable it in checkstyle:
在 checkstyle 中找到禁用它的方法:
Preferences -> CheckStyle -> Regexp -> RegexpSingleLine (Disable)
首选项 -> CheckStyle -> Regexp -> RegexpSingleLine(禁用)
回答by Alexander Pogrebnyak
Window->Preferences->Java->Editor->Save Actions.
窗口->首选项->Java->编辑器->保存操作。
Press Configurebutton.
按配置按钮。
On Code Organizingtab check Remove trailing whitespace.
在代码组织选项卡上检查Remove trailing whitespace。
回答by Thomas Hirsch
I think a better solution would be to teach Checkstyle to ignore trailing whitespaces in lines that are part of comments.
我认为更好的解决方案是教 Checkstyle 忽略作为注释一部分的行中的尾随空格。
In checkstyle.xml
:
在checkstyle.xml
:
<module name="RegexpSingleline">
<property name="format" value="(?!\*)[^$]\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
This block basically says: "Complain about lines that do not contain an asterisk (?!\*)
, followed by non-line-endings [^$]
, followed by one or more spaces \s+
followed by a line-ending $
".
这个块基本上是说:“抱怨不包含星号的行(?!\*)
,后跟非行尾[^$]
,后跟一个或多个空格,\s+
后跟行尾$
”。