本文介绍了从CheckStyle生成编码指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有没有办法从现有的CheckStyle配置文件生成一个nice编码约定/指南文档? 此文档必须包含强制执行的规则的描述,和配置值(如最大行长度,违例严重性等)。 拥有这样一个文档的好处是更快地提高一个新的团队成员,阅读CheckStyle配置文件。解决方案我通常建议不要生成编码指南文档的一部分,与您的软件工程师。此外,Checkstyle规则应该,我的愚见认为,不是编码指南文档本身的一部分。相反,编码指南应该注明注意不要导致Checkstyle问题。 Checkstyle工具可以配置信息,向开发人员显示警告。这样,开发人员不会需要打开一个外部文档,以正确解决Checkstyle警告,因为所有必需的信息已经存在。 示例: LocalVariableName 检查是否检查非最终局部变量的命名约定。其默认消息文本是: 成员名称:名称'Foo'必须匹配模式'^ [ az] [a-zA-Z0-9] {0,31} $'。 如果您配置如下检查: < module name =LocalVariableName> < message key =name.invalidPattern value =本地变量名{0}不得超过32个字母数字个字符,并以小写字母开头。正则表达式:{1}/> < / module> 然后输出将是: 局部变量名Foo不能超过32个字母数字字符,必须以小写字母开头。正则表达式:'^ [az] [a-zA-Z0-9] {0,31} $' 诚然,如果全部您的开发者知道他们的正则表达式足够好,新的消息文本将不是必要的。但不是每个人都是一个正则表达式的专家,这只是一个例子,可以应用于许多检查,包括检查没有正则表达式。 Is there a way to generate a 'nice' Coding conventions / guidelines document from existing CheckStyle configuration file?This document must contain the description of the rules enforced, and the configuration values (like the max line length, violation severity, etc).The benefit of having such a document is to ramp up a new team member faster, without reading CheckStyle configuration file. 解决方案 I would generally advise against generating even parts of a coding guidelines document, because that would cause acceptance problems with your software engineers. Also, the Checkstyle rules should, in my humble opinion, not be part of the coding guidelines document itself. Instead, the coding guidelines should state something like "Take care not to cause Checkstyle issues."The Checkstyle tool can be configured with information to show to the developer with the warning. That way, developers won't need to open an external document in order to resolve Checkstyle warnings correctly, because all required information is already there.Example: The LocalVariableName check checks the naming convention for non-final local variables. Its default message text is:Member Names: Name 'Foo' must match pattern '^[a-z][a-zA-Z0-9]{0,31}$'.If you configure the check like this:<module name="LocalVariableName"> <message key="name.invalidPattern" value="Local variable name ''{0}'' must not be longer than 32 alphanumeric characters and start with a lowercase letter. Regex: ''{1}''"/></module>Then the output would be:Local variable name 'Foo' must not be longer than 32 alphanumeric characters andstart with a lowercase letter. Regex: '^[a-z][a-zA-Z0-9]{0,31}$'Admittedly, if all your developers knew their regular expressions well enough, the new message text will not be necessary. But not everybody is a regex expert, and this is just an example which can be applied to many checks, including checks without regexes. 这篇关于从CheckStyle生成编码指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 10:06
查看更多