Using the Eclipse Checkstyle plugin I see this error:
使用Eclipse Checkstyle插件,我看到了这个错误:
Name 'logger' must match pattern
'^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'
.名字“记录器”必须匹配模式”^[a - z][A-Z0-9]*(_[A-Z0-9]+)*美元”。
I resolved this error by changing:
我通过改变来解决这个错误:
private static final Logger logger = Logger.getLogger(someClass.class);
私有静态最终记录器Logger = Logger. getlogger (someClass.class);
to
来
private static final Logger LOGGER = Logger.getLogger(someClass.class);
私有静态最终记录器Logger = Logger. getlogger (someClass.class);
Why is this a checkstyle warning?
为什么这是一个checkstyle警告?
2 个解决方案
#1
7
Because the field is marked final
and static
which implies that it's a constant and should be named with uppercase letters.
因为该字段标记为final和static,这意味着它是一个常量,应该用大写字母来命名。
From this link, you can see that the module ConstantName
has the format ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
which is exactly the one your Checkstyle plugin has specified.
从这个链接,你可以看到模块ConstantName格式^[a - z][A-Z0-9]*(_[A-Z0-9]+)* $这正是你的Checkstyle插件指定。
#2
1
The documentation recommends using this configuration if you wish to keep logger
as a valid option:
如果您希望将logger作为一个有效的选项,文档建议使用此配置:
<module name="ConstantName">
<property name="format"
value="^log(ger)?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
#1
7
Because the field is marked final
and static
which implies that it's a constant and should be named with uppercase letters.
因为该字段标记为final和static,这意味着它是一个常量,应该用大写字母来命名。
From this link, you can see that the module ConstantName
has the format ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
which is exactly the one your Checkstyle plugin has specified.
从这个链接,你可以看到模块ConstantName格式^[a - z][A-Z0-9]*(_[A-Z0-9]+)* $这正是你的Checkstyle插件指定。
#2
1
The documentation recommends using this configuration if you wish to keep logger
as a valid option:
如果您希望将logger作为一个有效的选项,文档建议使用此配置:
<module name="ConstantName">
<property name="format"
value="^log(ger)?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>