既存の CheckStyle 構成ファイルから「優れた」コーディング規約/ガイドライン ドキュメントを生成する方法はありますか?
このドキュメントには、適用されるルールの説明と構成値 (行の最大長、違反の重大度など) を含める必要があります。
このようなドキュメントを持つことの利点は、CheckStyle 構成ファイルを読み取らずに、新しいチーム メンバーをより迅速に立ち上げることができることです。
既存の CheckStyle 構成ファイルから「優れた」コーディング規約/ガイドライン ドキュメントを生成する方法はありますか?
このドキュメントには、適用されるルールの説明と構成値 (行の最大長、違反の重大度など) を含める必要があります。
このようなドキュメントを持つことの利点は、CheckStyle 構成ファイルを読み取らずに、新しいチーム メンバーをより迅速に立ち上げることができることです。
私は一般的に、コーディング ガイドライン ドキュメントの一部でも生成しないようにアドバイスします。また、私の謙虚な意見では、Checkstyle ルールはコーディング ガイドライン ドキュメント自体の一部であってはなりません。代わりに、コーディング ガイドラインには、「Checkstyle の問題が発生しないように注意してください」などと記載する必要があります。
Checkstyle ツールは、警告とともに開発者に表示する情報を使用して構成できます。そうすれば、Checkstyle の警告を正しく解決するために、開発者は外部ドキュメントを開く必要がなくなります。必要な情報はすべてそこにあるからです。
例: LocalVariableNameチェックは、非最終ローカル変数の命名規則をチェックします。デフォルトのメッセージ テキストは次のとおりです。
Member Names: Name 'Foo' must match pattern '^[a-z][a-zA-Z0-9]{0,31}$'.
次のようにチェックを構成する場合:
<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>
出力は次のようになります。
Local variable name 'Foo' must not be longer than 32 alphanumeric characters and
start with a lowercase letter. Regex: '^[a-z][a-zA-Z0-9]{0,31}$'
確かに、すべての開発者が正規表現を十分に理解していれば、新しいメッセージ テキストは必要ありません。しかし、すべての人が正規表現の専門家というわけではありません。これは、正規表現を使用しないチェックを含む、多くのチェックに適用できる例にすぎません。
いくつかの典型的なコーディング標準を以下に示します。
Comments:
Write Javadoc comments for all classes, methods, and variables.
Naming conventions:
Class names should be nouns, in mixed case with the first letter of each internal word capitalized (MyClass).
Variable names should be nouns, in mixed case with a lowercase first letter, and with the first letter of each internal word in upper case (myVariable).
Constants should be in all uppercase with words separated by underscore (MY_CONSTANT_VALUE).
Indentation:
Spaces should be preferred to tabs for indenting purposes.
Declarations:
One declaration per line, with comments, for example:
int class; // The child's class, from 1 to 8
int age; // The child's age
rather than:
int class, age;
Statements:
Opening braces in compound statements should be at the end of the line that begins the compound statement; the closing brace should begin a line and be indented to the beginning of the compound statement, for example:
while (i < 10) {
i++;
}
Best practices:
Use the final keyword for variables and parameters that will not need to be modified.
Don't declare variables within loops