From 1deee25d96b57eb4761d98a32b64a67a51b6d122 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 13 Aug 2021 07:43:50 +0100 Subject: [PATCH] Add NoCodeInFile commit-id:7b3b76fd --- README.md | 153 ++++++++++++++++++ builder/src/main/resources/application.yml | 8 + .../src/main/resources/rules/NoCodeInFile.md | 18 +++ .../net/kemitix/checkstyle-1-layout.xml | 3 + .../net/kemitix/checkstyle-2-naming.xml | 3 + .../net/kemitix/checkstyle-3-javadoc.xml | 3 + .../net/kemitix/checkstyle-4-tweaks.xml | 3 + .../net/kemitix/checkstyle-5-complexity.xml | 4 + 8 files changed, 195 insertions(+) create mode 100644 builder/src/main/resources/rules/NoCodeInFile.md diff --git a/README.md b/README.md index b27863c..d9c30d9 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ Rule|Level|Source|Enabled|Suppressible [InterfaceMemberImpliedModifier](#interfacememberimpliedmodifier)|tweaks|checkstyle|| [InterfaceTypeParameterName](#interfacetypeparametername)|naming|checkstyle|Yes| [JavadocMethod](#javadocmethod)|javadoc|checkstyle|| +[JavadocMissingLeadingAsterisk](#javadocmissingleadingasterisk)|layout|checkstyle|Yes| [JavadocPackage](#javadocpackage)|javadoc|checkstyle|Yes| [JavadocParagraph](#javadocparagraph)|javadoc|checkstyle|Yes| [JavadocStyle](#javadocstyle)|javadoc|checkstyle|Yes| @@ -171,6 +172,7 @@ Rule|Level|Source|Enabled|Suppressible [JavadocType](#javadoctype)|javadoc|checkstyle|Yes| [JavadocVariable](#javadocvariable)|javadoc|checkstyle|| [JavaNCSS](#javancss)|complexity|checkstyle|Yes| +[LambdaBodyLength](#lambdabodylength)|complexity|checkstyle|Yes| [LambdaParameterName](#lambdaparametername)|naming|checkstyle|Yes| [LeftCurly](#leftcurly)|layout|checkstyle|Yes| [LineLength](#linelength)|layout|checkstyle|Yes| @@ -203,12 +205,14 @@ Rule|Level|Source|Enabled|Suppressible [NestedTryDepth](#nestedtrydepth)|complexity|checkstyle|Yes| [NewlineAtEndOfFile](#newlineatendoffile)|layout|checkstyle|Yes| [NoClone](#noclone)|tweaks|checkstyle|Yes|No +[NoCodeInFile](#nocodeinfile)|layout|checkstyle|Yes| [NoFinalizer](#nofinalizer)|tweaks|checkstyle|Yes| [NoLineWrap](#nolinewrap)|layout|checkstyle|Yes| [NoMainMethodInAbstractClass](#nomainmethodinabstractclass)|tweaks|sevntu|Yes| [NonEmptyAtclauseDescription](#nonemptyatclausedescription)|javadoc|checkstyle|Yes| [NoWhitespaceAfter](#nowhitespaceafter)|layout|checkstyle|Yes| [NoWhitespaceBefore](#nowhitespacebefore)|layout|checkstyle|Yes| +[NoWhitespaceBeforeCaseDefaultColon](#nowhitespacebeforecasedefaultcolon)|layout|checkstyle|Yes| [NPathComplexity](#npathcomplexity)|complexity|checkstyle|Yes| [NumericLiteralNeedsUnderscore](#numericliteralneedsunderscore)|naming|sevntu|Yes| [OneStatementPerLine](#onestatementperline)|layout|checkstyle|Yes| @@ -1128,6 +1132,57 @@ Invalid: ```` interface Portable {} ```` +#### [JavadocMissingLeadingAsterisk](https://checkstyle.sourceforge.io/config_javadoc.html#JavadocMissingLeadingAsterisk) + +Checks if the javadoc has leading asterisks on each line. + +The check does not require asterisks on the first line, nor on the last line if +it is blank. All other lines in a Javadoc should start with *, including blank +lines and code blocks. + +Valid: +```` +/** + * Valid Java-style comment. + * + *
+ *   int value = 0;
+ * 
+ */ +class JavaStyle {} // ok + +/** Valid Scala-style comment. + * Some description here. + **/ +class ScalaStyle {} // ok + +/** ** + * Asterisks on first and last lines are optional. + * */ +class Asterisks {} // ok + +/** No asterisks are required for single-line comments. */ +class SingleLine {} // ok +```` + +Invalid: +```` +/** // violation on next blank line, javadoc has lines without leading asterisk. + + */ +class BlankLine {} + +/** Wrapped + single-line comment */ // violation, javadoc has lines without leading asterisk. +class Wrapped {} + +/** + *
+    int value; // violation, javadoc has lines without leading asterisk.
+  * 
+ */ +class Code {} +```` #### [JavadocPackage](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocPackage) Checks that each package has a `package-info.java` file. @@ -1145,6 +1200,55 @@ Checks the format for Javadoc for classes and enums. Javadoc must be present, no Restricts the NCSS score for methods, classes and files to 40, 1200 and 1600 respectively. The NCSS score is a measure of the number of statements within a scope. Too high an NCSS score suggests that the method or class is doing too much and should be decomposed into smaller units. +#### [LambdaBodyLength](https://checkstyle.sourceforge.io/config_sizes.html#LambdaBodyLength) + +Checks lambda body length. + +Rationale: Similar to anonymous inner classes, if lambda body becomes very long +it is hard to understand and to see the flow of the method where the lambda is +defined. Therefore, long lambda body should usually be extracted to method. + +Valid: +```` +Runnable r3 = () -> { // ok, 10 lines + System.out.println(2); // line 2 of lambda + System.out.println(3); + System.out.println(4); + System.out.println(5); + System.out.println(6); + System.out.println(7); + System.out.println(8); + System.out.println(9); +}; // line 10 +```` + +Invalid: +```` +Runnable r = () -> { // violation, 11 lines + System.out.println(2); // line 2 of lambda + System.out.println(3); + System.out.println(4); + System.out.println(5); + System.out.println(6); + System.out.println(7); + System.out.println(8); + System.out.println(9); + System.out.println(10); +}; // line 11 + +Runnable r2 = () -> // violation, 11 lines + "someString".concat("1") // line 1 of lambda + .concat("2") + .concat("3") + .concat("4") + .concat("5") + .concat("6") + .concat("7") + .concat("8") + .concat("9") + .concat("10") + .concat("11"); // line 11 +```` #### [LambdaParameterName](http://checkstyle.sourceforge.net/config_naming.html#LambdaParameterName) Checks the format of lambda parameter names. @@ -1480,6 +1584,25 @@ Checks that files end with a line-feed character, (i.e. unix-style line ending). Checks that the `clone()` method from `Object` has not been overridden. Use a copy constructor, or better yet, a static factory method. > See [Effective Java], 2nd Edition by Josh Bloch: Item 11: Override clone judiciously. +#### [NoCodeInFile](https://checkstyle.sourceforge.io/config_misc.html#NoCodeInFile) + +Checks whether file contains code. Files which are considered to have no code: + +- File with no text +- File with only single line comment(s) +- File with only a multi line comment(s). + +Invalid: +````java +// single line comment // violation +```` + +Invalid: +````java +/* // violation + block comment +*/ +```` #### [NoFinalizer](http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer) Checks that the `finalize()` method from `Object` has not been overridden. @@ -1559,6 +1682,36 @@ doSomething() ; i ++; i --; ```` +#### [NoWhitespaceBeforeCaseDefaultColon](https://checkstyle.sourceforge.io/config_whitespace.html#NoWhitespaceBeforeCaseDefaultColon) + +Checks that there is no whitespace before the colon in a switch block. . + +Valid: +```` +switch(1) { + case 1: + break; + case 2: + break; + default: + break; +} +```` + +Invalid: +```` +switch(2) { + case 2: // ok + break; + case 3, 4 + : break; // violation, whitespace before ':' is not allowed here + case 4, + 5: break; // ok + default + : // violation, whitespace before ':' is not allowed here + break; +} +```` #### [NPathComplexity](http://checkstyle.sourceforge.net/config_metrics.html#NPathComplexity) Checks that the NPATH score (number of paths) through a method is no more than 5. This is similar to [Cyclomatic Complexity](#cyclomaticcomplexity). diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 2a9c8be..00c961a 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -1559,3 +1559,11 @@ rules: enabled: true source: CHECKSTYLE uri: https://checkstyle.sourceforge.io/config_sizes.html#LambdaBodyLength + - + name: NoCodeInFile + parent: TREEWALKER + level: LAYOUT + enabled: true + source: CHECKSTYLE + uri: https://checkstyle.sourceforge.io/config_misc.html#NoCodeInFile + diff --git a/builder/src/main/resources/rules/NoCodeInFile.md b/builder/src/main/resources/rules/NoCodeInFile.md new file mode 100644 index 0000000..04a832d --- /dev/null +++ b/builder/src/main/resources/rules/NoCodeInFile.md @@ -0,0 +1,18 @@ + +Checks whether file contains code. Files which are considered to have no code: + +- File with no text +- File with only single line comment(s) +- File with only a multi line comment(s). + +Invalid: +````java +// single line comment // violation +```` + +Invalid: +````java +/* // violation + block comment +*/ +```` diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml index 94b2a1c..ffd6422 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml @@ -52,6 +52,9 @@ + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml index 2436f67..a0df65b 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml @@ -79,6 +79,9 @@ + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml index 2215de3..2e81a37 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml @@ -98,6 +98,9 @@ + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index 98655a6..3941494 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -141,6 +141,9 @@ + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index b8cbb31..f4e55ff 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -187,6 +187,10 @@ + + + +