diff --git a/README.md b/README.md index 1625174b92..314ee429e7 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ Main features of diktat are the following: # another option is "brew install ktlint" ``` -2. Load diKTat manually: [here](https://github.com/cqfn/diKTat/releases/download/v0.2.0/diktat.jar) +2. Load diKTat manually: [here](https://github.com/cqfn/diKTat/releases/download/v0.3.0/diktat.jar) **OR** use curl: ```bash - $ curl -sSLO https://github.com/cqfn/diKTat/releases/download/v0.2.0/diktat-0.2.0.jar + $ curl -sSLO https://github.com/cqfn/diKTat/releases/download/v0.3.0/diktat-0.3.0.jar ``` 3. Finally, run KTlint (with diKTat injected) to check your `*.kt` files in `dir/your/dir`: @@ -110,7 +110,7 @@ This plugin is available since version 0.1.5. You can see how the plugin is conf Add this plugin to your `build.gradle.kts`: ```kotlin plugins { - id("org.cqfn.diktat.diktat-gradle-plugin") version "0.2.0" + id("org.cqfn.diktat.diktat-gradle-plugin") version "0.3.0" } ``` @@ -121,7 +121,7 @@ buildscript { mavenCentral() } dependencies { - classpath("org.cqfn.diktat:diktat-gradle-plugin:0.2.0") + classpath("org.cqfn.diktat:diktat-gradle-plugin:0.3.0") } } diff --git a/diktat-common/pom.xml b/diktat-common/pom.xml index 3975344864..1638bf6a39 100644 --- a/diktat-common/pom.xml +++ b/diktat-common/pom.xml @@ -9,7 +9,7 @@ org.cqfn.diktat diktat-parent - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT diff --git a/diktat-gradle-plugin/gradle-plugin-marker/pom.xml b/diktat-gradle-plugin/gradle-plugin-marker/pom.xml index 4d62ce8342..58f011ad2c 100644 --- a/diktat-gradle-plugin/gradle-plugin-marker/pom.xml +++ b/diktat-gradle-plugin/gradle-plugin-marker/pom.xml @@ -4,7 +4,7 @@ diktat-gradle-plugin org.cqfn.diktat - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT 4.0.0 diff --git a/diktat-gradle-plugin/pom.xml b/diktat-gradle-plugin/pom.xml index 5382185aa3..e31b8792d3 100644 --- a/diktat-gradle-plugin/pom.xml +++ b/diktat-gradle-plugin/pom.xml @@ -5,7 +5,7 @@ diktat-parent org.cqfn.diktat - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT 4.0.0 diff --git a/diktat-maven-plugin/pom.xml b/diktat-maven-plugin/pom.xml index 5de05cf4cf..ba90da0a6c 100644 --- a/diktat-maven-plugin/pom.xml +++ b/diktat-maven-plugin/pom.xml @@ -5,7 +5,7 @@ diktat-parent org.cqfn.diktat - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT 4.0.0 diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index f459c5478a..2c166e9909 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -9,7 +9,7 @@ org.cqfn.diktat diktat-parent - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT diff --git a/diktat-ruleset/pom.xml b/diktat-ruleset/pom.xml index eef9baf346..221b034e8a 100644 --- a/diktat-ruleset/pom.xml +++ b/diktat-ruleset/pom.xml @@ -8,7 +8,7 @@ org.cqfn.diktat diktat-parent - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT diff --git a/diktat-test-framework/pom.xml b/diktat-test-framework/pom.xml index 9af19f8ab5..99b8aba2ff 100644 --- a/diktat-test-framework/pom.xml +++ b/diktat-test-framework/pom.xml @@ -9,7 +9,7 @@ org.cqfn.diktat diktat-parent - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT diff --git a/examples/gradle-groovy-dsl/build.gradle b/examples/gradle-groovy-dsl/build.gradle index 98d1a2cac0..87131749e9 100644 --- a/examples/gradle-groovy-dsl/build.gradle +++ b/examples/gradle-groovy-dsl/build.gradle @@ -1,5 +1,5 @@ plugins { - id "org.cqfn.diktat.diktat-gradle-plugin" version "0.2.0" + id "org.cqfn.diktat.diktat-gradle-plugin" version "0.3.0" } repositories { diff --git a/examples/gradle-groovy-dsl/diktat-analysis.yml b/examples/gradle-groovy-dsl/diktat-analysis.yml index 81489088da..cf353c0ce0 100644 --- a/examples/gradle-groovy-dsl/diktat-analysis.yml +++ b/examples/gradle-groovy-dsl/diktat-analysis.yml @@ -1,185 +1,285 @@ +# Common configuration - name: DIKTAT_COMMON configuration: # put your package name here - it will be autofixed and checked domainName: your.name.here testDirs: test +# Checks that the Class/Enum/Interface name does not match Pascal case - name: CLASS_NAME_INCORRECT enabled: true +# Checks that CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE - name: CONSTANT_UPPERCASE enabled: true +# Checks that enum value is in non UPPER_SNAKE_CASE or non PascalCase depending on the config, UPPER_SNAKE_CASE by default - name: ENUM_VALUE enabled: true + configuration: + # Two options: snakeCase(default), PascalCase + enumStyle: snakeCase +# Checks that class which extends any Exception class has Exception suffix - name: EXCEPTION_SUFFIX enabled: true +# Checks that file name has extension - name: FILE_NAME_INCORRECT enabled: true +# Checks that file name matches class name, if it is only one class in file - name: FILE_NAME_MATCH_CLASS enabled: true +# Checks that functions/methods which return boolean have special prefix like "is/should/e.t.c" - name: FUNCTION_BOOLEAN_PREFIX enabled: true + configuration: + allowedPrefixes: "" # A list of functions that return boolean and are allowed to use. Input is in a form "foo, bar". +# Checks that function/method name is in lowerCamelCase - name: FUNCTION_NAME_INCORRECT_CASE enabled: true +# Checks that generic name doesn't contain more than 1 letter (capital). It can be followed by numbers, example: T12, T - name: GENERIC_NAME enabled: true +# Identifier length should be in range [2,64] except names that used in industry like {i, j} and 'e' for catching exceptions - name: IDENTIFIER_LENGTH enabled: true +# Checks that the object matches PascalCase - name: OBJECT_NAME_INCORRECT enabled: true +# Checks that package name is in correct (lower) case - name: PACKAGE_NAME_INCORRECT_CASE - enabled: true # configuration domainName is taken from DIKTAT_COMMON + enabled: true +# Checks that package name starts with the company's domain - name: PACKAGE_NAME_INCORRECT_PREFIX enabled: false +# Checks that package name does not have incorrect symbols like underscore or non-ASCII letters/digits - name: PACKAGE_NAME_INCORRECT_SYMBOLS enabled: true +# Checks that the path for a file matches with a package name - name: PACKAGE_NAME_INCORRECT_PATH - enabled: false # configuration domainName is taken from DIKTAT_COMMON + enabled: false +# Checks that package name is in the file - name: PACKAGE_NAME_MISSING enabled: true +# Checks that variable does not have prefix (like mVariable or M_VARIABLE) - name: VARIABLE_HAS_PREFIX enabled: true +# Checks that variable does not contain one single letter, only exceptions are fixed names that used in industry like {i, j} - name: VARIABLE_NAME_INCORRECT enabled: true +# Checks that the name of variable is in lowerCamelCase and contains only ASCII letters - name: VARIABLE_NAME_INCORRECT_FORMAT enabled: true +# Checks that functions have kdoc - name: MISSING_KDOC_ON_FUNCTION enabled: true +# Checks that on file level internal or public class or function has missing KDoc - name: MISSING_KDOC_TOP_LEVEL enabled: true +# Checks that accessible internal elements (protected, public, internal) in a class are documented - name: MISSING_KDOC_CLASS_ELEMENTS enabled: true +# Checks that accessible method parameters are documented in KDoc - name: KDOC_WITHOUT_PARAM_TAG enabled: true +# Checks that accessible method explicit return type is documented in KDoc - name: KDOC_WITHOUT_RETURN_TAG enabled: true +# Checks that accessible method throw keyword is documented in KDoc - name: KDOC_WITHOUT_THROWS_TAG enabled: true +# Checks that KDoc is not empty - name: KDOC_EMPTY_KDOC enabled: true +# Checks that underscore is correctly used to split package naming - name: INCORRECT_PACKAGE_SEPARATOR enabled: true +# Checks that there is no @deprecated tag in kdoc - name: KDOC_NO_DEPRECATED_TAG enabled: true +# Checks that there is no empty content in kdoc tags - name: KDOC_NO_EMPTY_TAGS enabled: true +# Checks that there is only one space after kdoc tag - name: KDOC_WRONG_SPACES_AFTER_TAG enabled: true +# Checks tags order in kDoc. `@param`, `@return`, `@throws` - name: KDOC_WRONG_TAGS_ORDER enabled: true +# Checks that there is no newline of empty KDoc line (with leading asterisk) between `@param`, `@return`, `@throws` tags - name: KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS enabled: true +# Checks that block of tags @param, @return, @throws is separated from previous part of KDoc by exactly one empty line - name: KDOC_NEWLINES_BEFORE_BASIC_TAGS enabled: true +# Checks that special tags `@apiNote`, `@implNote`, `@implSpec` have exactly one empty line after - name: KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS enabled: true +# Checks that KDoc does not contain single line with words 'return', 'get' or 'set' - name: KDOC_TRIVIAL_KDOC_ON_FUNCTION - enabled: 'true' + enabled: true +# Checks that there is newline after header KDoc - name: HEADER_WRONG_FORMAT enabled: true +# Checks that file with zero or >1 classes has header KDoc - name: HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE enabled: true +# Checks that copyright exists on top of file and is properly formatted (as a block comment) - name: HEADER_MISSING_OR_WRONG_COPYRIGHT enabled: true configuration: isCopyrightMandatory: true copyrightText: 'Copyright (c) Your Company Name Here. 2010-2021' +# Checks that header kdoc is located before package directive - name: HEADER_NOT_BEFORE_PACKAGE enabled: true +# Checks that header kdoc does not contain @author tag ar date - name: HEADER_CONTAINS_DATE_OR_AUTHOR enabled: true +# Checks that file does not contain lines > maxSize - name: FILE_IS_TOO_LONG enabled: true configuration: + # number of lines maxSize: '2000' ignoreFolders: '' +# Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true +# Checks that file does not contain only comments, imports and package directive - name: FILE_CONTAINS_ONLY_COMMENTS enabled: true - # order imports alphabetically +# Orders imports alphabetically - name: FILE_UNORDERED_IMPORTS enabled: true configuration: # use logical imports grouping with sorting inside of a group useRecommendedImportsOrder: true +# Checks that general order of code parts is right - name: FILE_INCORRECT_BLOCKS_ORDER enabled: true +# Checks that there is exactly one line between code blocks - name: FILE_NO_BLANK_LINE_BETWEEN_BLOCKS enabled: true -# Check: warns if wildcard imports are used except allows. (e.g. import org.cqfn.diktat.*) +# Checks that there is no wildcard imports. Exception: allowedWildcards - name: FILE_WILDCARD_IMPORTS enabled: true configuration: allowedWildcards: "" # Allowed wildcards for imports (e.g. "import org.cqfn.diktat.*, import org.jetbrains.kotlin.*") useRecommendedImportsOrder: true +# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement - name: NO_BRACES_IN_CONDITIONALS_AND_LOOPS enabled: true +# Checks that the declaration part of a class-like code structures (class/interface/etc.) is in the proper order - name: WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES enabled: true +# Checks that properties with comments are separated by a blank line - name: BLANK_LINE_BETWEEN_PROPERTIES enabled: true +# Checks that non-empty code blocks with braces follow the K&R style (1TBS or OTBS style) - name: BRACES_BLOCK_STRUCTURE_ERROR enabled: true configuration: openBraceNewline: 'True' closeBraceNewline: 'True' +# Checks that indentation is correct - name: WRONG_INDENTATION enabled: true configuration: + # Is newline at the end of a file needed newlineAtEnd: true + # If true: in parameter list when parameters are split by newline they are indented with two indentations instead of one extendedIndentOfParameters: true + # If true: if first parameter in parameter list is on the same line as opening parenthesis, then other parameters can be aligned with it alignedParameters: true + # If true: if expression is split by newline after operator like +/-/`*`, then the next line is indented with two indentations instead of one extendedIndentAfterOperators: true + # The indentation size for each file indentationSize: 4 +# Checks that there is no empty blocks in a file. +# If allowEmptyBlocks is true, checks that it follows correct style (have a newline) - name: EMPTY_BLOCK_STRUCTURE_ERROR enabled: true configuration: + # Whether a newline after `{` is required in an empty block styleEmptyBlockWithNewline: 'True' allowEmptyBlocks: 'False' +# Checks that there is no more than one statement per line - name: MORE_THAN_ONE_STATEMENT_PER_LINE enabled: true +# Checks that the line length is < lineLength parameter - name: LONG_LINE enabled: true configuration: lineLength: '120' +# Checks that semicolons are not used at the end of a line - name: REDUNDANT_SEMICOLON enabled: true +# Checks that line breaks follow code style guide: rule 3.6 - name: WRONG_NEWLINES enabled: true configuration: + # If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines. maxParametersInOneLine: 2 + # 3 by default. + # maxCallsInOneLine: 3 +# Checks that there are not too many consecutive spaces in line - name: TOO_MANY_CONSECUTIVE_SPACES enabled: true configuration: - max_spaces: '1' + # Maximum allowed number of consecutive spaces (not counting indentation) + maxSpaces: '1' + # Whether formatting for enums should be kept without checking saveInitialFormattingForEnums: false +# Checks that blank lines are used correctly. +# For example: triggers when there are too many blank lines between function declaration - name: TOO_MANY_BLANK_LINES enabled: true +# Checks that usage of horizontal spaces doesn't violate code style guide - name: WRONG_WHITESPACE enabled: true +# Checks that backticks (``) are not used in the identifier name, except the case when it is test method (marked with @Test annotation) - name: BACKTICKS_PROHIBITED enabled: true +# Checks that a single line concatenation of strings is not used - name: STRING_CONCATENATION enabled: true +# Checks that each when statement have else in the end - name: WHEN_WITHOUT_ELSE enabled: true +# Checks that annotation is on a single line - name: ANNOTATION_NEW_LINE enabled: true +# Checks that enum structure is correct: enum entries should be separated by comma and line break and last entry should have semicolon in the end. - name: ENUMS_SEPARATED enabled: true +# Checks that value on integer or float constant is not too big - name: LONG_NUMERICAL_VALUES_SEPARATED enabled: true configuration: + # Maximum number of digits which are not split maxNumberLength: '5' + # Maximum number of digits between separators maxBlockLength: '3' +# Checks that order of enum values or constant property inside companion is correct - name: WRONG_DECLARATIONS_ORDER enabled: true configuration: + # Whether enum members should be sorted alphabetically sortEnum: true + # Whether class properties should be sorted alphabetically sortProperty: true +# Checks that multiple modifiers sequence is in the correct order - name: WRONG_MULTIPLE_MODIFIERS_ORDER enabled: true +# Checks that identifier has appropriate name (See table of rule 1.2 part 6) - name: CONFUSING_IDENTIFIER_NAMING enabled: true +# Checks year in the copyright +- name: WRONG_COPYRIGHT_YEAR + enabled: true +# Inspection that checks if local variables are declared close to the first usage site +- name: LOCAL_VARIABLE_EARLY_DECLARATION + enabled: true +# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) +- name: NULLABLE_PROPERTY_TYPE + enabled: true # Inspection that checks if there is a blank line before kDoc and none after - name: WRONG_NEWLINES_AROUND_KDOC enabled: true @@ -195,21 +295,15 @@ # Inspection that checks if all comment's are inside if-else code blocks. Exception is general if comment - name: IF_ELSE_COMMENTS enabled: true -- name: WRONG_COPYRIGHT_YEAR - enabled: true -# Inspection that checks if local variables are declared close to the first usage site -- name: LOCAL_VARIABLE_EARLY_DECLARATION - enabled: true -# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) -- name: NULLABLE_PROPERTY_TYPE - enabled: true # Type aliases provide alternative names for existing types when type's reference text is longer 25 chars - name: TYPE_ALIAS enabled: true configuration: typeReferenceLength: '25' # max length of type reference +# Checks if casting can be omitted - name: SMART_CAST_NEEDED enabled: true +# Checks that variables of generic types have explicit type declaration - name: GENERIC_VARIABLE_WRONG_DECLARATION enabled: true # Inspection that checks if string template has redundant curly braces @@ -251,7 +345,7 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true -# Checks that KDoc in constructor has property tag +# Checks that property in constructor doesn't contain comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true # Checks that property in KDoc present in class diff --git a/examples/gradle-kotlin-dsl/build.gradle.kts b/examples/gradle-kotlin-dsl/build.gradle.kts index 0faa2212d4..fbbdfaed8e 100644 --- a/examples/gradle-kotlin-dsl/build.gradle.kts +++ b/examples/gradle-kotlin-dsl/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("org.cqfn.diktat.diktat-gradle-plugin") version "0.2.0" + id("org.cqfn.diktat.diktat-gradle-plugin") version "0.3.0" } repositories { diff --git a/examples/gradle-kotlin-dsl/diktat-analysis.yml b/examples/gradle-kotlin-dsl/diktat-analysis.yml index 81489088da..cf353c0ce0 100644 --- a/examples/gradle-kotlin-dsl/diktat-analysis.yml +++ b/examples/gradle-kotlin-dsl/diktat-analysis.yml @@ -1,185 +1,285 @@ +# Common configuration - name: DIKTAT_COMMON configuration: # put your package name here - it will be autofixed and checked domainName: your.name.here testDirs: test +# Checks that the Class/Enum/Interface name does not match Pascal case - name: CLASS_NAME_INCORRECT enabled: true +# Checks that CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE - name: CONSTANT_UPPERCASE enabled: true +# Checks that enum value is in non UPPER_SNAKE_CASE or non PascalCase depending on the config, UPPER_SNAKE_CASE by default - name: ENUM_VALUE enabled: true + configuration: + # Two options: snakeCase(default), PascalCase + enumStyle: snakeCase +# Checks that class which extends any Exception class has Exception suffix - name: EXCEPTION_SUFFIX enabled: true +# Checks that file name has extension - name: FILE_NAME_INCORRECT enabled: true +# Checks that file name matches class name, if it is only one class in file - name: FILE_NAME_MATCH_CLASS enabled: true +# Checks that functions/methods which return boolean have special prefix like "is/should/e.t.c" - name: FUNCTION_BOOLEAN_PREFIX enabled: true + configuration: + allowedPrefixes: "" # A list of functions that return boolean and are allowed to use. Input is in a form "foo, bar". +# Checks that function/method name is in lowerCamelCase - name: FUNCTION_NAME_INCORRECT_CASE enabled: true +# Checks that generic name doesn't contain more than 1 letter (capital). It can be followed by numbers, example: T12, T - name: GENERIC_NAME enabled: true +# Identifier length should be in range [2,64] except names that used in industry like {i, j} and 'e' for catching exceptions - name: IDENTIFIER_LENGTH enabled: true +# Checks that the object matches PascalCase - name: OBJECT_NAME_INCORRECT enabled: true +# Checks that package name is in correct (lower) case - name: PACKAGE_NAME_INCORRECT_CASE - enabled: true # configuration domainName is taken from DIKTAT_COMMON + enabled: true +# Checks that package name starts with the company's domain - name: PACKAGE_NAME_INCORRECT_PREFIX enabled: false +# Checks that package name does not have incorrect symbols like underscore or non-ASCII letters/digits - name: PACKAGE_NAME_INCORRECT_SYMBOLS enabled: true +# Checks that the path for a file matches with a package name - name: PACKAGE_NAME_INCORRECT_PATH - enabled: false # configuration domainName is taken from DIKTAT_COMMON + enabled: false +# Checks that package name is in the file - name: PACKAGE_NAME_MISSING enabled: true +# Checks that variable does not have prefix (like mVariable or M_VARIABLE) - name: VARIABLE_HAS_PREFIX enabled: true +# Checks that variable does not contain one single letter, only exceptions are fixed names that used in industry like {i, j} - name: VARIABLE_NAME_INCORRECT enabled: true +# Checks that the name of variable is in lowerCamelCase and contains only ASCII letters - name: VARIABLE_NAME_INCORRECT_FORMAT enabled: true +# Checks that functions have kdoc - name: MISSING_KDOC_ON_FUNCTION enabled: true +# Checks that on file level internal or public class or function has missing KDoc - name: MISSING_KDOC_TOP_LEVEL enabled: true +# Checks that accessible internal elements (protected, public, internal) in a class are documented - name: MISSING_KDOC_CLASS_ELEMENTS enabled: true +# Checks that accessible method parameters are documented in KDoc - name: KDOC_WITHOUT_PARAM_TAG enabled: true +# Checks that accessible method explicit return type is documented in KDoc - name: KDOC_WITHOUT_RETURN_TAG enabled: true +# Checks that accessible method throw keyword is documented in KDoc - name: KDOC_WITHOUT_THROWS_TAG enabled: true +# Checks that KDoc is not empty - name: KDOC_EMPTY_KDOC enabled: true +# Checks that underscore is correctly used to split package naming - name: INCORRECT_PACKAGE_SEPARATOR enabled: true +# Checks that there is no @deprecated tag in kdoc - name: KDOC_NO_DEPRECATED_TAG enabled: true +# Checks that there is no empty content in kdoc tags - name: KDOC_NO_EMPTY_TAGS enabled: true +# Checks that there is only one space after kdoc tag - name: KDOC_WRONG_SPACES_AFTER_TAG enabled: true +# Checks tags order in kDoc. `@param`, `@return`, `@throws` - name: KDOC_WRONG_TAGS_ORDER enabled: true +# Checks that there is no newline of empty KDoc line (with leading asterisk) between `@param`, `@return`, `@throws` tags - name: KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS enabled: true +# Checks that block of tags @param, @return, @throws is separated from previous part of KDoc by exactly one empty line - name: KDOC_NEWLINES_BEFORE_BASIC_TAGS enabled: true +# Checks that special tags `@apiNote`, `@implNote`, `@implSpec` have exactly one empty line after - name: KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS enabled: true +# Checks that KDoc does not contain single line with words 'return', 'get' or 'set' - name: KDOC_TRIVIAL_KDOC_ON_FUNCTION - enabled: 'true' + enabled: true +# Checks that there is newline after header KDoc - name: HEADER_WRONG_FORMAT enabled: true +# Checks that file with zero or >1 classes has header KDoc - name: HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE enabled: true +# Checks that copyright exists on top of file and is properly formatted (as a block comment) - name: HEADER_MISSING_OR_WRONG_COPYRIGHT enabled: true configuration: isCopyrightMandatory: true copyrightText: 'Copyright (c) Your Company Name Here. 2010-2021' +# Checks that header kdoc is located before package directive - name: HEADER_NOT_BEFORE_PACKAGE enabled: true +# Checks that header kdoc does not contain @author tag ar date - name: HEADER_CONTAINS_DATE_OR_AUTHOR enabled: true +# Checks that file does not contain lines > maxSize - name: FILE_IS_TOO_LONG enabled: true configuration: + # number of lines maxSize: '2000' ignoreFolders: '' +# Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true +# Checks that file does not contain only comments, imports and package directive - name: FILE_CONTAINS_ONLY_COMMENTS enabled: true - # order imports alphabetically +# Orders imports alphabetically - name: FILE_UNORDERED_IMPORTS enabled: true configuration: # use logical imports grouping with sorting inside of a group useRecommendedImportsOrder: true +# Checks that general order of code parts is right - name: FILE_INCORRECT_BLOCKS_ORDER enabled: true +# Checks that there is exactly one line between code blocks - name: FILE_NO_BLANK_LINE_BETWEEN_BLOCKS enabled: true -# Check: warns if wildcard imports are used except allows. (e.g. import org.cqfn.diktat.*) +# Checks that there is no wildcard imports. Exception: allowedWildcards - name: FILE_WILDCARD_IMPORTS enabled: true configuration: allowedWildcards: "" # Allowed wildcards for imports (e.g. "import org.cqfn.diktat.*, import org.jetbrains.kotlin.*") useRecommendedImportsOrder: true +# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement - name: NO_BRACES_IN_CONDITIONALS_AND_LOOPS enabled: true +# Checks that the declaration part of a class-like code structures (class/interface/etc.) is in the proper order - name: WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES enabled: true +# Checks that properties with comments are separated by a blank line - name: BLANK_LINE_BETWEEN_PROPERTIES enabled: true +# Checks that non-empty code blocks with braces follow the K&R style (1TBS or OTBS style) - name: BRACES_BLOCK_STRUCTURE_ERROR enabled: true configuration: openBraceNewline: 'True' closeBraceNewline: 'True' +# Checks that indentation is correct - name: WRONG_INDENTATION enabled: true configuration: + # Is newline at the end of a file needed newlineAtEnd: true + # If true: in parameter list when parameters are split by newline they are indented with two indentations instead of one extendedIndentOfParameters: true + # If true: if first parameter in parameter list is on the same line as opening parenthesis, then other parameters can be aligned with it alignedParameters: true + # If true: if expression is split by newline after operator like +/-/`*`, then the next line is indented with two indentations instead of one extendedIndentAfterOperators: true + # The indentation size for each file indentationSize: 4 +# Checks that there is no empty blocks in a file. +# If allowEmptyBlocks is true, checks that it follows correct style (have a newline) - name: EMPTY_BLOCK_STRUCTURE_ERROR enabled: true configuration: + # Whether a newline after `{` is required in an empty block styleEmptyBlockWithNewline: 'True' allowEmptyBlocks: 'False' +# Checks that there is no more than one statement per line - name: MORE_THAN_ONE_STATEMENT_PER_LINE enabled: true +# Checks that the line length is < lineLength parameter - name: LONG_LINE enabled: true configuration: lineLength: '120' +# Checks that semicolons are not used at the end of a line - name: REDUNDANT_SEMICOLON enabled: true +# Checks that line breaks follow code style guide: rule 3.6 - name: WRONG_NEWLINES enabled: true configuration: + # If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines. maxParametersInOneLine: 2 + # 3 by default. + # maxCallsInOneLine: 3 +# Checks that there are not too many consecutive spaces in line - name: TOO_MANY_CONSECUTIVE_SPACES enabled: true configuration: - max_spaces: '1' + # Maximum allowed number of consecutive spaces (not counting indentation) + maxSpaces: '1' + # Whether formatting for enums should be kept without checking saveInitialFormattingForEnums: false +# Checks that blank lines are used correctly. +# For example: triggers when there are too many blank lines between function declaration - name: TOO_MANY_BLANK_LINES enabled: true +# Checks that usage of horizontal spaces doesn't violate code style guide - name: WRONG_WHITESPACE enabled: true +# Checks that backticks (``) are not used in the identifier name, except the case when it is test method (marked with @Test annotation) - name: BACKTICKS_PROHIBITED enabled: true +# Checks that a single line concatenation of strings is not used - name: STRING_CONCATENATION enabled: true +# Checks that each when statement have else in the end - name: WHEN_WITHOUT_ELSE enabled: true +# Checks that annotation is on a single line - name: ANNOTATION_NEW_LINE enabled: true +# Checks that enum structure is correct: enum entries should be separated by comma and line break and last entry should have semicolon in the end. - name: ENUMS_SEPARATED enabled: true +# Checks that value on integer or float constant is not too big - name: LONG_NUMERICAL_VALUES_SEPARATED enabled: true configuration: + # Maximum number of digits which are not split maxNumberLength: '5' + # Maximum number of digits between separators maxBlockLength: '3' +# Checks that order of enum values or constant property inside companion is correct - name: WRONG_DECLARATIONS_ORDER enabled: true configuration: + # Whether enum members should be sorted alphabetically sortEnum: true + # Whether class properties should be sorted alphabetically sortProperty: true +# Checks that multiple modifiers sequence is in the correct order - name: WRONG_MULTIPLE_MODIFIERS_ORDER enabled: true +# Checks that identifier has appropriate name (See table of rule 1.2 part 6) - name: CONFUSING_IDENTIFIER_NAMING enabled: true +# Checks year in the copyright +- name: WRONG_COPYRIGHT_YEAR + enabled: true +# Inspection that checks if local variables are declared close to the first usage site +- name: LOCAL_VARIABLE_EARLY_DECLARATION + enabled: true +# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) +- name: NULLABLE_PROPERTY_TYPE + enabled: true # Inspection that checks if there is a blank line before kDoc and none after - name: WRONG_NEWLINES_AROUND_KDOC enabled: true @@ -195,21 +295,15 @@ # Inspection that checks if all comment's are inside if-else code blocks. Exception is general if comment - name: IF_ELSE_COMMENTS enabled: true -- name: WRONG_COPYRIGHT_YEAR - enabled: true -# Inspection that checks if local variables are declared close to the first usage site -- name: LOCAL_VARIABLE_EARLY_DECLARATION - enabled: true -# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) -- name: NULLABLE_PROPERTY_TYPE - enabled: true # Type aliases provide alternative names for existing types when type's reference text is longer 25 chars - name: TYPE_ALIAS enabled: true configuration: typeReferenceLength: '25' # max length of type reference +# Checks if casting can be omitted - name: SMART_CAST_NEEDED enabled: true +# Checks that variables of generic types have explicit type declaration - name: GENERIC_VARIABLE_WRONG_DECLARATION enabled: true # Inspection that checks if string template has redundant curly braces @@ -251,7 +345,7 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true -# Checks that KDoc in constructor has property tag +# Checks that property in constructor doesn't contain comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true # Checks that property in KDoc present in class diff --git a/examples/maven/diktat-analysis.yml b/examples/maven/diktat-analysis.yml index 81489088da..cf353c0ce0 100644 --- a/examples/maven/diktat-analysis.yml +++ b/examples/maven/diktat-analysis.yml @@ -1,185 +1,285 @@ +# Common configuration - name: DIKTAT_COMMON configuration: # put your package name here - it will be autofixed and checked domainName: your.name.here testDirs: test +# Checks that the Class/Enum/Interface name does not match Pascal case - name: CLASS_NAME_INCORRECT enabled: true +# Checks that CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE - name: CONSTANT_UPPERCASE enabled: true +# Checks that enum value is in non UPPER_SNAKE_CASE or non PascalCase depending on the config, UPPER_SNAKE_CASE by default - name: ENUM_VALUE enabled: true + configuration: + # Two options: snakeCase(default), PascalCase + enumStyle: snakeCase +# Checks that class which extends any Exception class has Exception suffix - name: EXCEPTION_SUFFIX enabled: true +# Checks that file name has extension - name: FILE_NAME_INCORRECT enabled: true +# Checks that file name matches class name, if it is only one class in file - name: FILE_NAME_MATCH_CLASS enabled: true +# Checks that functions/methods which return boolean have special prefix like "is/should/e.t.c" - name: FUNCTION_BOOLEAN_PREFIX enabled: true + configuration: + allowedPrefixes: "" # A list of functions that return boolean and are allowed to use. Input is in a form "foo, bar". +# Checks that function/method name is in lowerCamelCase - name: FUNCTION_NAME_INCORRECT_CASE enabled: true +# Checks that generic name doesn't contain more than 1 letter (capital). It can be followed by numbers, example: T12, T - name: GENERIC_NAME enabled: true +# Identifier length should be in range [2,64] except names that used in industry like {i, j} and 'e' for catching exceptions - name: IDENTIFIER_LENGTH enabled: true +# Checks that the object matches PascalCase - name: OBJECT_NAME_INCORRECT enabled: true +# Checks that package name is in correct (lower) case - name: PACKAGE_NAME_INCORRECT_CASE - enabled: true # configuration domainName is taken from DIKTAT_COMMON + enabled: true +# Checks that package name starts with the company's domain - name: PACKAGE_NAME_INCORRECT_PREFIX enabled: false +# Checks that package name does not have incorrect symbols like underscore or non-ASCII letters/digits - name: PACKAGE_NAME_INCORRECT_SYMBOLS enabled: true +# Checks that the path for a file matches with a package name - name: PACKAGE_NAME_INCORRECT_PATH - enabled: false # configuration domainName is taken from DIKTAT_COMMON + enabled: false +# Checks that package name is in the file - name: PACKAGE_NAME_MISSING enabled: true +# Checks that variable does not have prefix (like mVariable or M_VARIABLE) - name: VARIABLE_HAS_PREFIX enabled: true +# Checks that variable does not contain one single letter, only exceptions are fixed names that used in industry like {i, j} - name: VARIABLE_NAME_INCORRECT enabled: true +# Checks that the name of variable is in lowerCamelCase and contains only ASCII letters - name: VARIABLE_NAME_INCORRECT_FORMAT enabled: true +# Checks that functions have kdoc - name: MISSING_KDOC_ON_FUNCTION enabled: true +# Checks that on file level internal or public class or function has missing KDoc - name: MISSING_KDOC_TOP_LEVEL enabled: true +# Checks that accessible internal elements (protected, public, internal) in a class are documented - name: MISSING_KDOC_CLASS_ELEMENTS enabled: true +# Checks that accessible method parameters are documented in KDoc - name: KDOC_WITHOUT_PARAM_TAG enabled: true +# Checks that accessible method explicit return type is documented in KDoc - name: KDOC_WITHOUT_RETURN_TAG enabled: true +# Checks that accessible method throw keyword is documented in KDoc - name: KDOC_WITHOUT_THROWS_TAG enabled: true +# Checks that KDoc is not empty - name: KDOC_EMPTY_KDOC enabled: true +# Checks that underscore is correctly used to split package naming - name: INCORRECT_PACKAGE_SEPARATOR enabled: true +# Checks that there is no @deprecated tag in kdoc - name: KDOC_NO_DEPRECATED_TAG enabled: true +# Checks that there is no empty content in kdoc tags - name: KDOC_NO_EMPTY_TAGS enabled: true +# Checks that there is only one space after kdoc tag - name: KDOC_WRONG_SPACES_AFTER_TAG enabled: true +# Checks tags order in kDoc. `@param`, `@return`, `@throws` - name: KDOC_WRONG_TAGS_ORDER enabled: true +# Checks that there is no newline of empty KDoc line (with leading asterisk) between `@param`, `@return`, `@throws` tags - name: KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS enabled: true +# Checks that block of tags @param, @return, @throws is separated from previous part of KDoc by exactly one empty line - name: KDOC_NEWLINES_BEFORE_BASIC_TAGS enabled: true +# Checks that special tags `@apiNote`, `@implNote`, `@implSpec` have exactly one empty line after - name: KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS enabled: true +# Checks that KDoc does not contain single line with words 'return', 'get' or 'set' - name: KDOC_TRIVIAL_KDOC_ON_FUNCTION - enabled: 'true' + enabled: true +# Checks that there is newline after header KDoc - name: HEADER_WRONG_FORMAT enabled: true +# Checks that file with zero or >1 classes has header KDoc - name: HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE enabled: true +# Checks that copyright exists on top of file and is properly formatted (as a block comment) - name: HEADER_MISSING_OR_WRONG_COPYRIGHT enabled: true configuration: isCopyrightMandatory: true copyrightText: 'Copyright (c) Your Company Name Here. 2010-2021' +# Checks that header kdoc is located before package directive - name: HEADER_NOT_BEFORE_PACKAGE enabled: true +# Checks that header kdoc does not contain @author tag ar date - name: HEADER_CONTAINS_DATE_OR_AUTHOR enabled: true +# Checks that file does not contain lines > maxSize - name: FILE_IS_TOO_LONG enabled: true configuration: + # number of lines maxSize: '2000' ignoreFolders: '' +# Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true +# Checks that file does not contain only comments, imports and package directive - name: FILE_CONTAINS_ONLY_COMMENTS enabled: true - # order imports alphabetically +# Orders imports alphabetically - name: FILE_UNORDERED_IMPORTS enabled: true configuration: # use logical imports grouping with sorting inside of a group useRecommendedImportsOrder: true +# Checks that general order of code parts is right - name: FILE_INCORRECT_BLOCKS_ORDER enabled: true +# Checks that there is exactly one line between code blocks - name: FILE_NO_BLANK_LINE_BETWEEN_BLOCKS enabled: true -# Check: warns if wildcard imports are used except allows. (e.g. import org.cqfn.diktat.*) +# Checks that there is no wildcard imports. Exception: allowedWildcards - name: FILE_WILDCARD_IMPORTS enabled: true configuration: allowedWildcards: "" # Allowed wildcards for imports (e.g. "import org.cqfn.diktat.*, import org.jetbrains.kotlin.*") useRecommendedImportsOrder: true +# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement - name: NO_BRACES_IN_CONDITIONALS_AND_LOOPS enabled: true +# Checks that the declaration part of a class-like code structures (class/interface/etc.) is in the proper order - name: WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES enabled: true +# Checks that properties with comments are separated by a blank line - name: BLANK_LINE_BETWEEN_PROPERTIES enabled: true +# Checks that non-empty code blocks with braces follow the K&R style (1TBS or OTBS style) - name: BRACES_BLOCK_STRUCTURE_ERROR enabled: true configuration: openBraceNewline: 'True' closeBraceNewline: 'True' +# Checks that indentation is correct - name: WRONG_INDENTATION enabled: true configuration: + # Is newline at the end of a file needed newlineAtEnd: true + # If true: in parameter list when parameters are split by newline they are indented with two indentations instead of one extendedIndentOfParameters: true + # If true: if first parameter in parameter list is on the same line as opening parenthesis, then other parameters can be aligned with it alignedParameters: true + # If true: if expression is split by newline after operator like +/-/`*`, then the next line is indented with two indentations instead of one extendedIndentAfterOperators: true + # The indentation size for each file indentationSize: 4 +# Checks that there is no empty blocks in a file. +# If allowEmptyBlocks is true, checks that it follows correct style (have a newline) - name: EMPTY_BLOCK_STRUCTURE_ERROR enabled: true configuration: + # Whether a newline after `{` is required in an empty block styleEmptyBlockWithNewline: 'True' allowEmptyBlocks: 'False' +# Checks that there is no more than one statement per line - name: MORE_THAN_ONE_STATEMENT_PER_LINE enabled: true +# Checks that the line length is < lineLength parameter - name: LONG_LINE enabled: true configuration: lineLength: '120' +# Checks that semicolons are not used at the end of a line - name: REDUNDANT_SEMICOLON enabled: true +# Checks that line breaks follow code style guide: rule 3.6 - name: WRONG_NEWLINES enabled: true configuration: + # If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines. maxParametersInOneLine: 2 + # 3 by default. + # maxCallsInOneLine: 3 +# Checks that there are not too many consecutive spaces in line - name: TOO_MANY_CONSECUTIVE_SPACES enabled: true configuration: - max_spaces: '1' + # Maximum allowed number of consecutive spaces (not counting indentation) + maxSpaces: '1' + # Whether formatting for enums should be kept without checking saveInitialFormattingForEnums: false +# Checks that blank lines are used correctly. +# For example: triggers when there are too many blank lines between function declaration - name: TOO_MANY_BLANK_LINES enabled: true +# Checks that usage of horizontal spaces doesn't violate code style guide - name: WRONG_WHITESPACE enabled: true +# Checks that backticks (``) are not used in the identifier name, except the case when it is test method (marked with @Test annotation) - name: BACKTICKS_PROHIBITED enabled: true +# Checks that a single line concatenation of strings is not used - name: STRING_CONCATENATION enabled: true +# Checks that each when statement have else in the end - name: WHEN_WITHOUT_ELSE enabled: true +# Checks that annotation is on a single line - name: ANNOTATION_NEW_LINE enabled: true +# Checks that enum structure is correct: enum entries should be separated by comma and line break and last entry should have semicolon in the end. - name: ENUMS_SEPARATED enabled: true +# Checks that value on integer or float constant is not too big - name: LONG_NUMERICAL_VALUES_SEPARATED enabled: true configuration: + # Maximum number of digits which are not split maxNumberLength: '5' + # Maximum number of digits between separators maxBlockLength: '3' +# Checks that order of enum values or constant property inside companion is correct - name: WRONG_DECLARATIONS_ORDER enabled: true configuration: + # Whether enum members should be sorted alphabetically sortEnum: true + # Whether class properties should be sorted alphabetically sortProperty: true +# Checks that multiple modifiers sequence is in the correct order - name: WRONG_MULTIPLE_MODIFIERS_ORDER enabled: true +# Checks that identifier has appropriate name (See table of rule 1.2 part 6) - name: CONFUSING_IDENTIFIER_NAMING enabled: true +# Checks year in the copyright +- name: WRONG_COPYRIGHT_YEAR + enabled: true +# Inspection that checks if local variables are declared close to the first usage site +- name: LOCAL_VARIABLE_EARLY_DECLARATION + enabled: true +# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) +- name: NULLABLE_PROPERTY_TYPE + enabled: true # Inspection that checks if there is a blank line before kDoc and none after - name: WRONG_NEWLINES_AROUND_KDOC enabled: true @@ -195,21 +295,15 @@ # Inspection that checks if all comment's are inside if-else code blocks. Exception is general if comment - name: IF_ELSE_COMMENTS enabled: true -- name: WRONG_COPYRIGHT_YEAR - enabled: true -# Inspection that checks if local variables are declared close to the first usage site -- name: LOCAL_VARIABLE_EARLY_DECLARATION - enabled: true -# Try to avoid initialize val by null (e.g. val a: Int? = null -> val a: Int = 0) -- name: NULLABLE_PROPERTY_TYPE - enabled: true # Type aliases provide alternative names for existing types when type's reference text is longer 25 chars - name: TYPE_ALIAS enabled: true configuration: typeReferenceLength: '25' # max length of type reference +# Checks if casting can be omitted - name: SMART_CAST_NEEDED enabled: true +# Checks that variables of generic types have explicit type declaration - name: GENERIC_VARIABLE_WRONG_DECLARATION enabled: true # Inspection that checks if string template has redundant curly braces @@ -251,7 +345,7 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true -# Checks that KDoc in constructor has property tag +# Checks that property in constructor doesn't contain comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true # Checks that property in KDoc present in class diff --git a/examples/maven/pom.xml b/examples/maven/pom.xml index 0aa1dda88e..20a2779642 100644 --- a/examples/maven/pom.xml +++ b/examples/maven/pom.xml @@ -8,7 +8,7 @@ 1.0.0-SNAPSHOT - 0.2.0 + 0.3.0 diff --git a/pom.xml b/pom.xml index c90dfa48ec..0cdcda88d0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.cqfn.diktat diktat-parent - 0.2.1-SNAPSHOT + 0.3.1-SNAPSHOT pom diktat @@ -50,7 +50,7 @@ 30.0-jre 1.7.30 1.4 - 0.2.0 + 0.3.0 1.7.1 1.15.0 1.4.20