From d63c3473c37ba2720adfe3c54e56a75f2967fcb1 Mon Sep 17 00:00:00 2001 From: Denis Kumar Date: Wed, 30 Dec 2020 01:03:58 +0300 Subject: [PATCH 1/3] Available-rules corrected according out documentation (#675) ### What's done: Fixed documentation --- info/available-rules.md | 218 ++++++++++++++++++++-------------------- 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/info/available-rules.md b/info/available-rules.md index 67142a34dd..085763b398 100644 --- a/info/available-rules.md +++ b/info/available-rules.md @@ -1,110 +1,110 @@ -| Chap | Standard | Rule name | Description | Fix | Config | FixMe | -| ---- | -------- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | --- | ------ | ----- | -| 1 | 1.2 | CONFUSING_IDENTIFIER_NAMING | Check: warns if identifier has inappropriate name (See table of rule 1.2 part 6). | no | no | no | -| 1 | 1.3 | PACKAGE_NAME_MISSING | Check: warns if package name is missing in a file
Fix: automatically adds package directive with the name that starts from the domain name (in example - com.huawei) and contains the real directory | yes | no | Domain name should not be hardcoded. It should be moved to extra configuration.Recursively fix all imports in project.Fix the directory where the code is stored.Make this check isolated from domain name addition| -| 1 | 1.3 | PACKAGE_NAME_INCORRECT_CASE | Check: warns if package name is in incorrect (non-lower) case
Fix: automatically update the case in package name | yes | no | Recursively update all imports in the project.| -| 1 | 1.3 | PACKAGE_NAME_INCORRECT_PREFIX | Check: warns if package name does not start with the company's domain
Fix: automatically update the prefix in the package name | yes | no | Fix the directory where the code is stored.Recursively update all imports in the project.Domain name should not be hardcoded. It should be moved to extra configuration.| -| 1 | 1.3 | PACKAGE_NAME_INCORRECT_SYMBOLS | Check: warns if package name has incorrect symbols like underscore or non-ASCII letters/digits.Exception: underscores that are used for differentiating of keywords in a name.
Fix: no but will be | no | no | Add autofix for at least converting underscore to a dot or replacing itFix the directory where the code is stored.Cover autofix with tests| -| 1 | 1.3 | PACKAGE_NAME_INCORRECT_PATH | Check: warns if the path for a file does not match with a package name
Fix: replacing incorrect package name with the name constructed from a path to the file. | yes | no | Make this check isolated from domain name creationRecursively update all imports in the project.Fix the directory where the code is stored.Add test mechanism to test checker| -| 1 | 1.3 | INCORRECT_PACKAGE_SEPARATOR | Check: warns if underscore is incorrectly used to split package naming
Fix: fixing all nodes in AST and the package name to remove all underscores | no | no | Recursively update usages of this class in the project| -| 1 | 1.4 | CLASS_NAME_INCORRECT | Check: warns if the Class/Enum/Interface name does not match Pascal case ("([A-Z][a-z0-9]+)+")
Fix: fixing the case: if the it is some fixed case (like snake/camel) - with word saving. If not - will restore PascalCase as is. | yes | no | Recursively update usages of this class in the projectCheck and decide the better way on converting identifier to PascalCaseNeed to add checks using natural language processing to check that class name contains only nouns| -| 1 | 1.2 | OBJECT_NAME_INCORRECT | Check: warns if the object does not match Pascal case ("([A-Z][a-z0-9]+)+")
Fix: fixing the case in the same way as for classes | yes | no | Recursively update usages of this class in the project| -| 1 | 1.2 | VARIABLE_NAME_INCORRECT_FORMAT | Check: warns if the name of variable is not in lowerCamelCase or contains non-ASCII letters
Fix: fixing the case format to lowerCamelCase | | no | -| -| 1 | 1.2 | BACKTICKS_PROHIBITED | Check: warns if backticks (``) are used in the identifier name, except the case when it is test method (marked with @Test annotation) | no | no | - | | -| 1 | 1.7 | VARIABLE_NAME_INCORRECT | Check: warns if variable contains one single letter, only exceptions are fixed names that used in industry like {i, j}
Fix: no fix as we are not able to imagine good name by machine | no | no | Recursively update usages of this class in the projectMake exceptions configurable| -| 1 | 1.6 | CONSTANT_UPPERCASE | Check: warns if CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE
Fix: name is changed to UPPER_SNAKE_CASE | yes | no | Recursively update usages of this identifier in the project| -| 1 | 1.5 | VARIABLE_HAS_PREFIX | Check: warns if variable has prefix (like mVariable or M_VARIABLE), generally it is a bad code style (Android - is the only exception
Fix: no fix as we are not able to imagine good name by machine | no | no | may be we can fix it, but I do not see any sense for it| -| 1 | 1.2 | IDENTIFIER_LENGTH | Check: identifier length should be in range [2,64] except names that used in industry like {i, j} and 'e' for catching exceptions.
Fix: no fix as we are not able to imagine good name by machine | no | no | May be make this rule configurable (length)| -| 1 | 1.4 | ENUM_VALUE | Check: warns if enum value is in non UPPER_SNAKE_CASE or non PascalCase depending on the config, UPPER_SNAKE_CASE by default
Fix: automatically converting case to selected case | yes | enumStyle: snakeCase, pascalCase | Recursively update usages of this identifier in the project| -| 1 | 1.2 | GENERIC_NAME | Check: warns if generic name contains more than 1 letter (capital). It can be followed by numbers, example: T12, T
Fix: | yes | no | Recursively update usages of this identifier in the project| -| 1 | 1.5 | FUNCTION_NAME_INCORRECT_CASE | Check: function/method name should be in lowerCamelCase:
Fix: | yes | no | Recursively update usages of this function in the project| -| 1 | 1.5 | FUNCTION_BOOLEAN_PREFIX | Check: functions/methods that return boolean should have special prefix like "is/should/e.t.c"
Fix: | yes | no | Recursively update usages of this function in the projectAggressive fix - what if new name will not be valid| -| 1 | 1.2 | FILE_NAME_INCORRECT | Check: warns if file name does not have extension .kt/.kts
Fix: no | no | no | Extensions should be configurableIt can be aggressively autofixed| -| 1 | 1.2 | FILE_NAME_MATCH_CLASS | Check: warns
Fix: no | no | no | Probably it can be autofixed, but it will be aggressive fix| -| 1 | 1.2 | EXCEPTION_SUFFIX | Check: warns if class that extends any Exception class does not have Exception suffix
Fix: Adding suffix "Exception" to a class name | yes | no | Need to add tests for this| -| 2 | 2.1 | MISSING_KDOC_TOP_LEVEL | Check: warns on file level internal or public class or function has missing KDoc
Fix: no | no | no | Support extension for setters/gettersSupport extension for method "override"| -| 2 | 2.1.1 | KDOC_EXTRA_PROPERTY | Check: warn if there is property in KDoc which is not present in the class | no | no | - | -| 2 | 2.1 | MISSING_KDOC_CLASS_ELEMENTS | Check: warns if accessible internal elements (protected, public, internal) in a class are not documented
Fix: no | no | no | May be need to add exception cases for setters and getters. There is no sense in adding KDoc to them.| -| 2 | 2.1 | MISSING_KDOC_ON_FUNCTION | Check: warns if accessible function doesn't have KDoc
Fix: adds KDoc template if it is not empty | yes | no | | -| 2 | 2.2 | KDOC_WITHOUT_PARAM_TAG | Check: warns if accessible method has parameters and they are not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place| -| 2 | 2.2 | KDOC_WITHOUT_RETURN_TAG | Check: warns if accessible method has explicit return type they it is not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place | -| 2 | 2.2 | KDOC_WITHOUT_THROWS_TAG | Check: warns if accessible method has throw keyword and it is not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place | -| 2 | 2.3 | KDOC_EMPTY_KDOC | Check: warns if KDoc is empty
Fix: no | no | no | | -| 2 | 2.3 | KDOC_WRONG_SPACES_AFTER_TAG | Check: warns if there is more than one space after KDoc tag
Fix: removes redundant spaces | yes | no | | -| 2 | 2.3 | KDOC_WRONG_TAGS_ORDER | Check: warns if basic KDoc tags are not oredered properly
Fix: reorders them `@param`, `@return`, `@throws` | yes | no | Ensure basic tags are at the end of KDoc| -| 2 | 2.3 | KDOC_NEWLINES_BEFORE_BASIC_TAGS | Check: warns if block of tags @param, @return, @throws is not separated from previous part of KDoc by exactly one empty line
Fix: adds empty line or removes redundant | yes | no | | -| 2 | 2.3 | KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS | Check: if there is newline of empty KDoc line (with leading asterisk) between `@param`, `@return`, `@throws` tags
Fix: removes line | yes | no | | -| 2 | 2.3 | KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS | Check: warns if special tags `@apiNote`, `@implNote`, `@implSpec` don't have exactly one empty line after
Fix: removes redundant lines or adds one | yes | no | Handle empty lines without leading asterisk| -| 2 | 2.3 | KDOC_NO_EMPTY_TAGS | Check: warns if KDoc tags have empty content | no | no | | -| 2 | 2.3 | KDOC_NO_DEPRECATED_TAG | Check: warns if `@deprecated` is used in KDoc
Fix: adds `@Deprecated` annotation with message, removes tag | yes | no | Annotation's `replaceWith` field can be filled too| -| 2 | 2.3 | KDOC_NO_CONSTRUCTOR_PROPERTY | Check: warns if there is no property tag inside KDoc before constructor | yes | no | -| 2 | 2.3 | KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT | Check: warns if there is comment before property in constructor | yes | no | -| 2 | 2.5 | KDOC_TRIVIAL_KDOC_ON_FUNCTION | Check: warns if KDoc contains single line with words 'return', 'get' or 'set' | no | no | | -| 2 | 2.4 | HEADER_WRONG_FORMAT | Checks: warns if there is no newline after header KDoc
Fix: adds newline | yes | no | Check if header is on the very top of file. It's hard to determine when it's not.| -| 2 | 2.4 | HEADER_MISSING_OR_WRONG_COPYRIGHT | Checks: copyright exists on top of file and is properly formatted (as a block comment)
Fix: adds copyright if it is missing and required | yes | mandatoryCopyright | Allow setting copyright patterns via configuration| -| 2 | 2.4 | WRONG_COPYRIGHT_YEAR | Checks: copyright have a valid year
Fix: makes a year valid | yes | no | - | -| 2 | 2.4 | HEADER_CONTAINS_DATE_OR_AUTHOR | Check: warns if header KDoc contains `@author` tag | no | no | Detect author by other patterns (e.g. 'created by' etc.)Detect creation date (no standard tag even in javadoc)| -| 2 | 2.4 | HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE | Check: warns if file with zero or >1 classes doesn't have header KDoc | no | no | | -| 2 | 2.7 | COMMENTED_OUT_CODE | Check: warns if commented code is detected (when un-commented, can be parsed) | no | no | Offset is lost when joined EOL comments are split again| -| 2 | 2.6 | COMMENT_WHITE_SPACE | Check: warns if there is no space between // and comment, if there is no space between code and comment
Fix: adds a white space | yes | maxSpaces | - | -| 2 | 2.6 | WRONG_NEWLINES_AROUND_KDOC | Check: warns if there is no new line above and under comment. Exception first comment
Fix: adds a new line | yes | no | - | -| 2 | 2.6 | FIRST_COMMENT_NO_SPACES | Check: warns if there is a new line before first comment
Fix: deletes a new line | yes | no | - | -| 2 | 2.6 | IF_ELSE_COMMENTS | Check: warns if there is a comment not in the else block
Fix: adds the comment to the first line in else block | yes | no | - | -| 2 | 2.4 | HEADER_NOT_BEFORE_PACKAGE | Check: warns if header KDoc if file is located not before package directive
Fix: moves this KDoc | yes | no | | -| 3 | 3.1 | FILE_IS_TOO_LONG | Check: warns if file has too many lines
Fix: no | no | maxSize
ignoreFolders | - | -| 3 | 3.2 | FILE_CONTAINS_ONLY_COMMENTS | Check: warns if file contains only comments, imports and package directive. | no | no | - | -| 3 | 3.2 | FILE_INCORRECT_BLOCKS_ORDER | Check: warns if general order of code parts is wrong.
Fix: rearranges them. | yes | no | handle other elements that could be present before package directive (other comments) | -| 3 | 3.2 | FILE_NO_BLANK_LINE_BETWEEN_BLOCKS | Check: warns if there is not exactly one blank line between code parts.
Fix: leaves single empty line | yes | no | - | -| 3 | 3.2 | FILE_UNORDERED_IMPORTS | Check: warns if imports are not sorted alphabetically or contain empty lines among them
Fix: reorders imports. | yes | no | - | -| 3 | 3.2 | FILE_WILDCARD_IMPORTS | Check: warns if wildcard imports are used except allows. | no | allowedWildcards | - | -| 3 | 3.3 | NO_BRACES_IN_CONDITIONALS_AND_LOOPS | Check: warns if braces are not used in if, else, when, for, do, and while statements. Exception: single line if statement.
Fix: adds missing braces. | yes | no | - | -| 3 | 3.2 | WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES | Check: warns if the declaration part of a class-like code structures (class/interface/etc.) is not in the proper order.
Fix: restores order according to code style guide. | yes | no | - | -| 3 | 3.2 | BLANK_LINE_BETWEEN_PROPERTIES | Check: warns if properties with comments are not separated by a blank line, properties without comments are
Fix: fixes number of blank lines | yes | no | - | -| 3 | 3.4 | BRACES_BLOCK_STRUCTURE_ERROR | Check: warns if non-empty code blocks with braces don't follow the K&R style (1TBS or OTBS style) | yes | openBraceNewline closeBraceNewline | - | -| 3 | 3.4 | EMPTY_BLOCK_STRUCTURE_ERROR | Check: warns if empty block exist or if it's style is incorrect | yes | allowEmptyBlocks styleEmptyBlockWithNewline | - | -| 3 | 3.4 | MORE_THAN_ONE_STATEMENT_PER_LINE | Check: warns if there is more than one statement per line | yes | no | - | -| 3 | 3.5 | WRONG_INDENTATION | Check: warns if indentation is incorrect
Fix: corrects indentation.

Basic cases are covered currently. | yes | extendedIndentOfParameters
alignedParameters
extendedIndentAfterOperators
extendedIndentBeforeDot
indentationSize | - | -| 3 | (rec) 3.4 | LONG_LINE | Check: warns if length doesn't exceed the specified length | no | lineLength | handle json method in KDoc | -| 3 | 3.6 | REDUNDANT_SEMICOLON | Check: warns if semicolons are used at the end of line.
Fix: removes semicolon. | yes | no | - | -| 3 | 3.6 | WRONG_NEWLINES | Check: warns if line breaks do not follow code style guid.
Fix: fixes incorrect line breaks. | yes | no | - | -| 3 | 3.8 | STRING_CONCATENATION | Check: warns if in a single line concatenation of strings is used | yes | no | - | -| 3 | 3.6 | TOO_MANY_BLANK_LINES | Check: warns if blank lines are used placed incorrectly.
Fix: removes redundant blank lines. | yes | no | | -| 3 | 3.7 | WRONG_WHITESPACE | Check: warns if usage of horizontal spaces violates code style guide.
Fix: fixes incorrect whitespaces. | yes | no | - | -| 3 | 3.8 | TOO_MANY_CONSECUTIVE_SPACES | Check: warns if there are too many consecutive spaces in line. Exception: in enum if configured and single eol comments
Fix: squeezes spaces to 1. | yes | maxSpaces saveInitialFormattingForEnums | - | -| 3 | 3.9 | ENUMS_SEPARATED | Check: warns if enum structure is incorrect: enum entries should be separated by comma and line break and last entry should have semicolon in the end. | yes | no | Replace variable to enum if it possible | -| 3 | 3.10 | WHEN_WITHOUT_ELSE | Check: warns if when statement don't have else in the end.
Fix: adds else if when doesn't have it. | yes | no | - | If a when statement of type enum or sealed contains all values of a enum - there is no need to have "else" branch. | -| 3 | 3.10 | LOCAL_VARIABLE_EARLY_DECLARATION | Check: warns if local variable is declared not immediately before it's usage
Fix (not implemented yet): moves variable declaration | no | no | add auto fix | -| 3 | 3.13 | LONG_NUMERICAL_VALUES_SEPARATED | Check: warns if value on integer or float constant is too big | no | maxNumberLength maxBlockLength | - | -| 3 | 3.2 | WRONG_DECLARATIONS_ORDER | Check: if order of enum values or constant property inside companion isn't correct | yes | no | - | -| 3 | 3.11 | ANNOTATION_NEW_LINE | Check: warns if annotation not on a new single line | yes | no | - | -| 3 | 3.2 | WRONG_MULTIPLE_MODIFIERS_ORDER | Check: if multiple modifiers sequence is in the wrong order | yes | no | - | -| 3 | 3.14.2 | STRING_TEMPLATE_CURLY_BRACES | Check: warns if there is redundant curly braces in string template
Fix: deletes curly braces | yes | no | + | -| 3 | 3.14.2 | STRING_TEMPLATE_QUOTES | Check: warns if there are redundant quotes in string template
Fix: deletes quotes and $ symbol | yes | no | + | -| 4 | 4.2.1 | SMART_CAST_NEEDED | Check: warns if casting can be omitted
Fix: Deletes casting | yes | no | - | | -| 4 | 4.3.1 | NULLABLE_PROPERTY_TYPE | Check: warns if immutable property is initialized with null or if immutable property can have non-nullable type instead of nullable
Fix: suggests initial value instead of null or changes immutable property type | yes | no | - | -| 4 | 4.2.2 | TYPE_ALIAS | Check: if type reference of property is longer than expected | yes | typeReferenceLength | -| -| 4 | 4.1.3 | SAY_NO_TO_VAR | Check: raises a warning if `var` modifier is used on local variable (not in class, not on file level). And this var is not used in accumulators | no | no | no | several fixmes related to the search mechanism (VariablesSearch) and fixme for checking reassinment of this var | +| Chap | Standard | Rule name | Description | Fix | Config | FixMe | +| ----- | ---------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | --- | ------ | ----- | +| 1 | 1.1.1 | CONFUSING_IDENTIFIER_NAMING | Check: warns if identifier has inappropriate name (See table of rule 1.2 part 6). | no | no | no | +| 1 | 1.2.1 | PACKAGE_NAME_MISSING | Check: warns if package name is missing in a file
Fix: automatically adds package directive with the name that starts from the domain name (in example - com.huawei) and contains the real directory | yes | no | Domain name should not be hardcoded. It should be moved to extra configuration.Recursively fix all imports in project.Fix the directory where the code is stored.Make this check isolated from domain name addition| +| 1 | 1.2.1 | PACKAGE_NAME_INCORRECT_CASE | Check: warns if package name is in incorrect (non-lower) case
Fix: automatically update the case in package name | yes | no | Recursively update all imports in the project.| +| 1 | 1.2.1 | PACKAGE_NAME_INCORRECT_PREFIX | Check: warns if package name does not start with the company's domain
Fix: automatically update the prefix in the package name | yes | no | Fix the directory where the code is stored.Recursively update all imports in the project.Domain name should not be hardcoded. It should be moved to extra configuration.| +| 1 | 1.2.1 | PACKAGE_NAME_INCORRECT_SYMBOLS | Check: warns if package name has incorrect symbols like underscore or non-ASCII letters/digits.Exception: underscores that are used for differentiating of keywords in a name.
Fix: no but will be | no | no | Add autofix for at least converting underscore to a dot or replacing itFix the directory where the code is stored.Cover autofix with tests| +| 1 | 1.2.1 | PACKAGE_NAME_INCORRECT_PATH | Check: warns if the path for a file does not match with a package name
Fix: replacing incorrect package name with the name constructed from a path to the file. | yes | no | Make this check isolated from domain name creationRecursively update all imports in the project.Fix the directory where the code is stored.Add test mechanism to test checker| +| 1 | 1.2.1 | INCORRECT_PACKAGE_SEPARATOR | Check: warns if underscore is incorrectly used to split package naming
Fix: fixing all nodes in AST and the package name to remove all underscores | no | no | Recursively update usages of this class in the project| +| 1 | 1.3.1 | CLASS_NAME_INCORRECT | Check: warns if the Class/Enum/Interface name does not match Pascal case ("([A-Z][a-z0-9]+)+")
Fix: fixing the case: if the it is some fixed case (like snake/camel) - with word saving. If not - will restore PascalCase as is. | yes | no | Recursively update usages of this class in the projectCheck and decide the better way on converting identifier to PascalCaseNeed to add checks using natural language processing to check that class name contains only nouns| +| 1 | 1.3.1 | OBJECT_NAME_INCORRECT | Check: warns if the object does not match Pascal case ("([A-Z][a-z0-9]+)+")
Fix: fixing the case in the same way as for classes | yes | no | Recursively update usages of this class in the project| +| 1 | 1.6.1 | VARIABLE_NAME_INCORRECT_FORMAT | Check: warns if the name of variable is not in lowerCamelCase or contains non-ASCII letters
Fix: fixing the case format to lowerCamelCase | | no | -| +| 1 | 1.1.1 | BACKTICKS_PROHIBITED | Check: warns if backticks (``) are used in the identifier name, except the case when it is test method (marked with @Test annotation) | no | no | - | | +| 1 | 1.1.1 | VARIABLE_NAME_INCORRECT | Check: warns if variable contains one single letter, only exceptions are fixed names that used in industry like {i, j}
Fix: no fix as we are not able to imagine good name by machine | no | no | Recursively update usages of this class in the projectMake exceptions configurable| +| 1 | 1.5.1 | CONSTANT_UPPERCASE | Check: warns if CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE
Fix: name is changed to UPPER_SNAKE_CASE | yes | no | Recursively update usages of this identifier in the project| +| 1 | 1.1.1 | VARIABLE_HAS_PREFIX | Check: warns if variable has prefix (like mVariable or M_VARIABLE), generally it is a bad code style (Android - is the only exception
Fix: no fix as we are not able to imagine good name by machine | no | no | may be we can fix it, but I do not see any sense for it| +| 1 | 1.1.1 | IDENTIFIER_LENGTH | Check: identifier length should be in range [2,64] except names that used in industry like {i, j} and 'e' for catching exceptions.
Fix: no fix as we are not able to imagine good name by machine | no | no | May be make this rule configurable (length)| +| 1 | 1.3.1 | ENUM_VALUE | Check: warns if enum value is in non UPPER_SNAKE_CASE or non PascalCase depending on the config, UPPER_SNAKE_CASE by default
Fix: automatically converting case to selected case | yes | enumStyle: snakeCase, pascalCase | Recursively update usages of this identifier in the project| +| 1 | 1.1.1 | GENERIC_NAME | Check: warns if generic name contains more than 1 letter (capital). It can be followed by numbers, example: T12, T
Fix: | yes | no | Recursively update usages of this identifier in the project| +| 1 | 1.4.1 | FUNCTION_NAME_INCORRECT_CASE | Check: function/method name should be in lowerCamelCase:
Fix: | yes | no | Recursively update usages of this function in the project| +| 1 | 1.6.2 | FUNCTION_BOOLEAN_PREFIX | Check: functions/methods that return boolean should have special prefix like "is/should/e.t.c"
Fix: | yes | no | Recursively update usages of this function in the projectAggressive fix - what if new name will not be valid| +| 1 | 1.1.1 | FILE_NAME_INCORRECT | Check: warns if file name does not have extension .kt/.kts
Fix: no | no | no | Extensions should be configurableIt can be aggressively autofixed| +| 1 | 3.1.2 | FILE_NAME_MATCH_CLASS | Check: warns
Fix: no | no | no | Probably it can be autofixed, but it will be aggressive fix| +| 1 | 1.1.1 | EXCEPTION_SUFFIX | Check: warns if class that extends any Exception class does not have Exception suffix
Fix: Adding suffix "Exception" to a class name | yes | no | Need to add tests for this| +| 2 | 2.1.1 | MISSING_KDOC_TOP_LEVEL | Check: warns on file level internal or public class or function has missing KDoc
Fix: no | no | no | Support extension for setters/gettersSupport extension for method "override"| +| 2 | 2.1.1 | KDOC_EXTRA_PROPERTY | Check: warn if there is property in KDoc which is not present in the class | no | no | - | +| 2 | 2.1.1 | MISSING_KDOC_CLASS_ELEMENTS | Check: warns if accessible internal elements (protected, public, internal) in a class are not documented
Fix: no | no | no | May be need to add exception cases for setters and getters. There is no sense in adding KDoc to them.| +| 2 | 2.1.1 | MISSING_KDOC_ON_FUNCTION | Check: warns if accessible function doesn't have KDoc
Fix: adds KDoc template if it is not empty | yes | no | | +| 2 | 2.1.2 | KDOC_WITHOUT_PARAM_TAG | Check: warns if accessible method has parameters and they are not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place| +| 2 | 2.1.2 | KDOC_WITHOUT_RETURN_TAG | Check: warns if accessible method has explicit return type they it is not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place | +| 2 | 2.1.2 | KDOC_WITHOUT_THROWS_TAG | Check: warns if accessible method has throw keyword and it is not documented in KDoc
Fix: If accessible method has no KDoc, KDoc template is added | yes | no | Should also make separate fix, even if there is already some Kdoc in place | +| 2 | 2.1.3 | KDOC_EMPTY_KDOC | Check: warns if KDoc is empty
Fix: no | no | no | | +| 2 | 2.1.3 | KDOC_WRONG_SPACES_AFTER_TAG | Check: warns if there is more than one space after KDoc tag
Fix: removes redundant spaces | yes | no | | +| 2 | 2.1.3 | KDOC_WRONG_TAGS_ORDER | Check: warns if basic KDoc tags are not oredered properly
Fix: reorders them `@param`, `@return`, `@throws` | yes | no | Ensure basic tags are at the end of KDoc| +| 2 | 2.1.3 | KDOC_NEWLINES_BEFORE_BASIC_TAGS | Check: warns if block of tags @param, @return, @throws is not separated from previous part of KDoc by exactly one empty line
Fix: adds empty line or removes redundant | yes | no | | +| 2 | 2.1.3 | KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS | Check: if there is newline of empty KDoc line (with leading asterisk) between `@param`, `@return`, `@throws` tags
Fix: removes line | yes | no | | +| 2 | 2.1.3 | KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS | Check: warns if special tags `@apiNote`, `@implNote`, `@implSpec` don't have exactly one empty line after
Fix: removes redundant lines or adds one | yes | no | Handle empty lines without leading asterisk| +| 2 | 2.2.1 | KDOC_NO_EMPTY_TAGS | Check: warns if KDoc tags have empty content | no | no | | +| 2 | 2.1.3 | KDOC_NO_DEPRECATED_TAG | Check: warns if `@deprecated` is used in KDoc
Fix: adds `@Deprecated` annotation with message, removes tag | yes | no | Annotation's `replaceWith` field can be filled too| +| 2 | 2.1.1 | KDOC_NO_CONSTRUCTOR_PROPERTY | Check: warns if there is no property tag inside KDoc before constructor | yes | no | +| 2 | 2.1.1 | KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT | Check: warns if there is comment before property in constructor | yes | no | +| 2 | 2.3.1 | KDOC_TRIVIAL_KDOC_ON_FUNCTION | Check: warns if KDoc contains single line with words 'return', 'get' or 'set' | no | no | | +| 2 | 2.2.1 | HEADER_WRONG_FORMAT | Checks: warns if there is no newline after header KDoc
Fix: adds newline | yes | no | Check if header is on the very top of file. It's hard to determine when it's not.| +| 2 | 2.2.1 | HEADER_MISSING_OR_WRONG_COPYRIGHT | Checks: copyright exists on top of file and is properly formatted (as a block comment)
Fix: adds copyright if it is missing and required | yes | mandatoryCopyright | Allow setting copyright patterns via configuration| +| 2 | 2.2.1 | WRONG_COPYRIGHT_YEAR | Checks: copyright have a valid year
Fix: makes a year valid | yes | no | - | +| 2 | 2.2.1 | HEADER_CONTAINS_DATE_OR_AUTHOR | Check: warns if header KDoc contains `@author` tag | no | no | Detect author by other patterns (e.g. 'created by' etc.)Detect creation date (no standard tag even in javadoc)| +| 2 | 2.2.1 | HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE | Check: warns if file with zero or >1 classes doesn't have header KDoc | no | no | | +| 2 | 2.4.2 | COMMENTED_OUT_CODE | Check: warns if commented code is detected (when un-commented, can be parsed) | no | no | Offset is lost when joined EOL comments are split again| +| 2 | 2.4.1 | COMMENT_WHITE_SPACE | Check: warns if there is no space between // and comment, if there is no space between code and comment
Fix: adds a white space | yes | maxSpaces | - | +| 2 | 2.4.1 | WRONG_NEWLINES_AROUND_KDOC | Check: warns if there is no new line above and under comment. Exception first comment
Fix: adds a new line | yes | no | - | +| 2 | 2.4.1 | FIRST_COMMENT_NO_SPACES | Check: warns if there is a new line before first comment
Fix: deletes a new line | yes | no | - | +| 2 | 2.4.1 | IF_ELSE_COMMENTS | Check: warns if there is a comment not in the else block
Fix: adds the comment to the first line in else block | yes | no | - | +| 2 | 2.2.1 | HEADER_NOT_BEFORE_PACKAGE | Check: warns if header KDoc if file is located not before package directive
Fix: moves this KDoc | yes | no | | +| 3 | 3.1.1 | FILE_IS_TOO_LONG | Check: warns if file has too many lines
Fix: no | no | maxSize
ignoreFolders | - | +| 3 | 3.1.2 | FILE_CONTAINS_ONLY_COMMENTS | Check: warns if file contains only comments, imports and package directive. | no | no | - | +| 3 | 3.1.2 | FILE_INCORRECT_BLOCKS_ORDER | Check: warns if general order of code parts is wrong.
Fix: rearranges them. | yes | no | handle other elements that could be present before package directive (other comments) | +| 3 | 3.1.2 | FILE_NO_BLANK_LINE_BETWEEN_BLOCKS | Check: warns if there is not exactly one blank line between code parts.
Fix: leaves single empty line | yes | no | - | +| 3 | 3.1.2 | FILE_UNORDERED_IMPORTS | Check: warns if imports are not sorted alphabetically or contain empty lines among them
Fix: reorders imports. | yes | no | - | +| 3 | 3.1.2 | FILE_WILDCARD_IMPORTS | Check: warns if wildcard imports are used except allows. | no | allowedWildcards | - | +| 3 | 3.2.1 | NO_BRACES_IN_CONDITIONALS_AND_LOOPS | Check: warns if braces are not used in if, else, when, for, do, and while statements. Exception: single line if statement.
Fix: adds missing braces. | yes | no | - | +| 3 | 3.1.4 | WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES | Check: warns if the declaration part of a class-like code structures (class/interface/etc.) is not in the proper order.
Fix: restores order according to code style guide. | yes | no | - | +| 3 | 3.1.4 | BLANK_LINE_BETWEEN_PROPERTIES | Check: warns if properties with comments are not separated by a blank line, properties without comments are
Fix: fixes number of blank lines | yes | no | - | +| 3 | 3.2.2 | BRACES_BLOCK_STRUCTURE_ERROR | Check: warns if non-empty code blocks with braces don't follow the K&R style (1TBS or OTBS style) | yes | openBraceNewline closeBraceNewline | - | +| 3 | 3.4.1 | EMPTY_BLOCK_STRUCTURE_ERROR | Check: warns if empty block exist or if it's style is incorrect | yes | allowEmptyBlocks styleEmptyBlockWithNewline | - | +| 3 | 3.6.1 | MORE_THAN_ONE_STATEMENT_PER_LINE | Check: warns if there is more than one statement per line | yes | no | - | +| 3 | 3.3.1 | WRONG_INDENTATION | Check: warns if indentation is incorrect
Fix: corrects indentation.

Basic cases are covered currently. | yes | extendedIndentOfParameters
alignedParameters
extendedIndentAfterOperators
extendedIndentBeforeDot
indentationSize | - | +| 3 | 3.5.1 | LONG_LINE | Check: warns if length doesn't exceed the specified length | no | lineLength | handle json method in KDoc | +| 3 | 3.6.2 | REDUNDANT_SEMICOLON | Check: warns if semicolons are used at the end of line.
Fix: removes semicolon. | yes | no | - | +| 3 | 3.6.2 | WRONG_NEWLINES | Check: warns if line breaks do not follow code style guid.
Fix: fixes incorrect line breaks. | yes | no | - | +| 3 | 3.15.1 | STRING_CONCATENATION | Check: warns if in a single line concatenation of strings is used | yes | no | - | +| 3 | 3.7.1 | TOO_MANY_BLANK_LINES | Check: warns if blank lines are used placed incorrectly.
Fix: removes redundant blank lines. | yes | no | | +| 3 | 3.8.1 | WRONG_WHITESPACE | Check: warns if usage of horizontal spaces violates code style guide.
Fix: fixes incorrect whitespaces. | yes | no | - | +| 3 | 3.8.1 | TOO_MANY_CONSECUTIVE_SPACES | Check: warns if there are too many consecutive spaces in line. Exception: in enum if configured and single eol comments
Fix: squeezes spaces to 1. | yes | maxSpaces saveInitialFormattingForEnums | - | +| 3 | 3.9.1 | ENUMS_SEPARATED | Check: warns if enum structure is incorrect: enum entries should be separated by comma and line break and last entry should have semicolon in the end. | yes | no | Replace variable to enum if it possible | +| 3 | 3.11.1 | WHEN_WITHOUT_ELSE | Check: warns if when statement don't have else in the end.
Fix: adds else if when doesn't have it. | yes | no | - | If a when statement of type enum or sealed contains all values of a enum - there is no need to have "else" branch. | +| 3 | 3.10.2 | LOCAL_VARIABLE_EARLY_DECLARATION | Check: warns if local variable is declared not immediately before it's usage
Fix (not implemented yet): moves variable declaration | no | no | add auto fix | +| 3 | 3.14.2 | LONG_NUMERICAL_VALUES_SEPARATED | Check: warns if value on integer or float constant is too big | no | maxNumberLength maxBlockLength | - | +| 3 | 3.1.4 | WRONG_DECLARATIONS_ORDER | Check: if order of enum values or constant property inside companion isn't correct | yes | no | - | +| 3 | 3.12.1 | ANNOTATION_NEW_LINE | Check: warns if annotation not on a new single line | yes | no | - | +| 3 | 3.14.1 | WRONG_MULTIPLE_MODIFIERS_ORDER | Check: if multiple modifiers sequence is in the wrong order | yes | no | - | +| 3 | 3.15.2 | STRING_TEMPLATE_CURLY_BRACES | Check: warns if there is redundant curly braces in string template
Fix: deletes curly braces | yes | no | + | +| 3 | 3.15.2 | STRING_TEMPLATE_QUOTES | Check: warns if there are redundant quotes in string template
Fix: deletes quotes and $ symbol | yes | no | + | +| 4 | 4.2.1 | SMART_CAST_NEEDED | Check: warns if casting can be omitted
Fix: Deletes casting | yes | no | - | | +| 4 | 4.3.1 | NULLABLE_PROPERTY_TYPE | Check: warns if immutable property is initialized with null or if immutable property can have non-nullable type instead of nullable
Fix: suggests initial value instead of null or changes immutable property type | yes | no | - | +| 4 | 4.2.2 | TYPE_ALIAS | Check: if type reference of property is longer than expected | yes | typeReferenceLength | -| +| 4 | 4.1.3 | SAY_NO_TO_VAR | Check: raises a warning if `var` modifier is used on local variable (not in class, not on file level). And this var is not used in accumulators | no | no | no | several fixmes related to the search mechanism (VariablesSearch) and fixme for checking reassinment of this var | | 4 | 4.1.1 | FLOAT_IN_ACCURATE_CALCULATIONS | Checks that floating-point values are not used in arithmetic expressions
Fix: no | no | no | Current implementation detects only floating-point constants | -| 4 | 4.2.2 | TYPE_ALIAS | Check: if type reference of property is longer than expected | yes | typeReferenceLength | -| -| 4 | 4.3.2 | GENERIC_VARIABLE_WRONG_DECLARATION | Check: warns if variables of generic types don't have explicit type declaration
Fix: fixes only variables that have generic declaration on both sides | yes | no | + | -| 4 | 4.3.3 | AVOID_NULL_CHECKS | Check: warns if null-check is used explicitly (for example: if (a == null)) | yes | no | no autofix by for now | -| 5 | 5.1.1 | TOO_LONG_FUNCTION | Check: if length of function is too long | no | maxFunctionLength isIncludeHeader | -| 5 | 5.1.2 | NESTED_BLOCK | Check if function has more nested blocks than expected | no | maxNestedBlockQuantit| -| 5 | 5.1.3 | AVOID_NESTED_FUNCTIONS | Check: if there are any nested functions
Fix: declare function in the outer scope | yes | no | + | -| 5 | 5.2.1 | LAMBDA_IS_NOT_LAST_PARAMETER | Checks that lambda inside function parameters isn't in the end | no | no | -| 5 | 5.2.2 | TOO_MANY_PARAMETERS | Check: if function contains more parameters than allowed | no | maxParameterListSize | -| 5 | 5.2.3 | WRONG_OVERLOADING_FUNCTION_ARGUMENTS | Check: function has overloading instead use default arguments | no | no | -| 6 | 6.1.1 | SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY | Check: warns if there is only one secondary constructor in a class
Fix: converts it to a primary constructor | yes | no | Support more complicated logic of constructor conversion | -| 6 | 6.1.2 | USE_DATA_CLASS | Check: if class can be made as data class | no | no | yes | -| 6 | 6.1.3 | EMPTY_PRIMARY_CONSTRUCTOR | Check: if there is empty primary constructor | yes | no | yes | -| 6 | 6.1.4 | MULTIPLE_INIT_BLOCKS | Checks that classes have only one init block | yes | no | - | -| 6 | 6.1.5 | USELESS_SUPERTYPE | Check: if override function can be removed | yes | no | | -| 6 | 6.1.6 | CLASS_SHOULD_NOT_BE_ABSTRACT | Checks: if abstract class has any abstract method. If not, warns that class should not be abstract
Fix: deletes abstract modifier | yes | no | - | -| 6 | 6.1.7 | NO_CORRESPONDING_PROPERTY | Checks: if in case of using "backing property" scheme, the name of real and back property are the same | no | no | - | -| 6 | 6.1.9 | WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR | Check: used the name of a variable in the custom getter or setter | no | no | -| 6 | 6.1.10 | TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED | Check: if there are any trivial getters or setters
Fix: Delete trivial getter or setter | yes | no | - | -| 6 | 6.1.8 | CUSTOM_GETTERS_SETTERS | Check: Inspection that checks that no custom getters and setters are used for properties | no | no | - | -| 6 | 6.1.11 | COMPACT_OBJECT_INITIALIZATION | Checks if class instantiation can be wrapped in `apply` for better readability | | no | | -| 6 | 6.2.2 | EXTENSION_FUNCTION_SAME_SIGNATURE | Checks if extension function has the same signature as another extension function and their classes are related | no | no | + | -| 6 | 6.4.1 | AVOID_USING_UTILITY_CLASS | Checks if there is class/object that can be replace with extension function | no | no | - | -| 6 | 6.4.2 | OBJECT_IS_PREFERRED | Checks: if class is stateless it is preferred to use `object` | yes | no | + | +| 4 | 4.2.2 | TYPE_ALIAS | Check: if type reference of property is longer than expected | yes | typeReferenceLength | -| +| 4 | 4.3.2 | GENERIC_VARIABLE_WRONG_DECLARATION | Check: warns if variables of generic types don't have explicit type declaration
Fix: fixes only variables that have generic declaration on both sides | yes | no | + | +| 4 | 4.3.3 | AVOID_NULL_CHECKS | Check: warns if null-check is used explicitly (for example: if (a == null)) | yes | no | no autofix by for now | +| 5 | 5.1.1 | TOO_LONG_FUNCTION | Check: if length of function is too long | no | maxFunctionLength isIncludeHeader | +| 5 | 5.1.2 | NESTED_BLOCK | Check if function has more nested blocks than expected | no | maxNestedBlockQuantit| +| 5 | 5.1.3 | AVOID_NESTED_FUNCTIONS | Check: if there are any nested functions
Fix: declare function in the outer scope | yes | no | + | +| 5 | 5.2.1 | LAMBDA_IS_NOT_LAST_PARAMETER | Checks that lambda inside function parameters isn't in the end | no | no | +| 5 | 5.2.2 | TOO_MANY_PARAMETERS | Check: if function contains more parameters than allowed | no | maxParameterListSize | +| 5 | 5.2.3 | WRONG_OVERLOADING_FUNCTION_ARGUMENTS | Check: function has overloading instead use default arguments | no | no | +| 6 | 6.1.1 | SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY | Check: warns if there is only one secondary constructor in a class
Fix: converts it to a primary constructor | yes | no | Support more complicated logic of constructor conversion | +| 6 | 6.1.2 | USE_DATA_CLASS | Check: if class can be made as data class | no | no | yes | +| 6 | 6.1.3 | EMPTY_PRIMARY_CONSTRUCTOR | Check: if there is empty primary constructor | yes | no | yes | +| 6 | 6.1.4 | MULTIPLE_INIT_BLOCKS | Checks that classes have only one init block | yes | no | - | +| 6 | 6.1.5 | USELESS_SUPERTYPE | Check: if override function can be removed | yes | no | | +| 6 | 6.1.6 | CLASS_SHOULD_NOT_BE_ABSTRACT | Checks: if abstract class has any abstract method. If not, warns that class should not be abstract
Fix: deletes abstract modifier | yes | no | - | +| 6 | 6.1.7 | NO_CORRESPONDING_PROPERTY | Checks: if in case of using "backing property" scheme, the name of real and back property are the same | no | no | - | +| 6 | 6.1.9 | WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR | Check: used the name of a variable in the custom getter or setter | no | no | +| 6 | 6.1.10 | TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED | Check: if there are any trivial getters or setters
Fix: Delete trivial getter or setter | yes | no | - | +| 6 | 6.1.8 | CUSTOM_GETTERS_SETTERS | Check: Inspection that checks that no custom getters and setters are used for properties | no | no | - | +| 6 | 6.1.11 | COMPACT_OBJECT_INITIALIZATION | Checks if class instantiation can be wrapped in `apply` for better readability | | no | | +| 6 | 6.2.2 | EXTENSION_FUNCTION_SAME_SIGNATURE | Checks if extension function has the same signature as another extension function and their classes are related | no | no | + | +| 6 | 6.4.1 | AVOID_USING_UTILITY_CLASS | Checks if there is class/object that can be replace with extension function | no | no | - | +| 6 | 6.4.2 | OBJECT_IS_PREFERRED | Checks: if class is stateless it is preferred to use `object` | yes | no | + | \ No newline at end of file From 27e5f7d74c94fb6d9893b6c996be5e7f0bc40e60 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Wed, 30 Dec 2020 11:06:41 +0300 Subject: [PATCH 2/3] Support checking .kts files (#667) ### What's done: * Initial support * Examples in smoke test --- .../cqfn/diktat/ruleset/rules/FileNaming.kt | 7 +++- .../diktat/ruleset/rules/PackageNaming.kt | 4 +- .../ruleset/rules/files/BlankLinesRule.kt | 7 +++- .../cqfn/diktat/ruleset/utils/StringUtils.kt | 7 ++++ .../diktat/ruleset/smoke/DiktatSmokeTest.kt | 41 +++++++++++-------- .../org/cqfn/diktat/util/LintTestBase.kt | 1 + .../kotlin/org/cqfn/diktat/util/TestUtils.kt | 5 ++- .../resources/test/smoke/build.gradle_.kts | 36 ++++++++++++++++ pom.xml | 2 +- 9 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 diktat-rules/src/test/resources/test/smoke/build.gradle_.kts diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/FileNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/FileNaming.kt index 8b6135d183..b1a4d5a58a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/FileNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/FileNaming.kt @@ -7,6 +7,7 @@ import org.cqfn.diktat.ruleset.constants.Warnings.FILE_NAME_MATCH_CLASS import org.cqfn.diktat.ruleset.utils.getAllChildrenWithType import org.cqfn.diktat.ruleset.utils.getFilePath import org.cqfn.diktat.ruleset.utils.getFirstChildWithType +import org.cqfn.diktat.ruleset.utils.isKotlinScript import org.cqfn.diktat.ruleset.utils.isPascalCase import com.pinterest.ktlint.core.Rule @@ -39,8 +40,10 @@ class FileNaming(private val configRules: List) : Rule("file-naming if (node.elementType == FILE) { filePath = node.getFilePath() - checkFileNaming(node) - checkClassNameMatchesWithFile(node) + if (!filePath.isKotlinScript()) { + checkFileNaming(node) + checkClassNameMatchesWithFile(node) + } } } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt index 84888608bf..bd2499cc52 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt @@ -60,7 +60,7 @@ class PackageNaming(private val configRules: List) : Rule("package- val realPackageName = calculateRealPackageName(filePath) // if node isLeaf - this means that there is no package name declared - if (node.isLeaf()) { + if (node.isLeaf() && !filePath.isKotlinScript()) { warnAndFixMissingPackageName(node, realPackageName, filePath) return } @@ -129,7 +129,7 @@ class PackageNaming(private val configRules: List) : Rule("package- } // package name should start from a company's domain name - if (!isDomainMatches(wordsInPackageName)) { + if (wordsInPackageName.isNotEmpty() && !isDomainMatches(wordsInPackageName)) { PACKAGE_NAME_INCORRECT_PREFIX.warnAndFix(configRules, emitWarn, isFixMode, domainName, wordsInPackageName[0].startOffset, wordsInPackageName[0]) { val oldPackageName = wordsInPackageName.joinToString(PACKAGE_SEPARATOR) { it.text } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/files/BlankLinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/files/BlankLinesRule.kt index 38e5b92852..3486626c5e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/files/BlankLinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/files/BlankLinesRule.kt @@ -17,6 +17,7 @@ import com.pinterest.ktlint.core.ast.ElementType.FUNCTION_LITERAL import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.LBRACE import com.pinterest.ktlint.core.ast.ElementType.RBRACE +import com.pinterest.ktlint.core.ast.ElementType.SCRIPT import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -46,7 +47,11 @@ class BlankLinesRule(private val configRules: List) : Rule("blank-l } private fun handleBlankLine(node: ASTNode) { - if (node.treeParent.elementType.let { it == BLOCK || it == CLASS_BODY || it == FUNCTION_LITERAL }) { + if (node.treeParent.let { + // kts files are parsed as a SCRIPT node containing BLOCK, therefore WHITE_SPACEs from these BLOCKS shouldn't be checked + it.elementType == BLOCK && it.treeParent?.elementType != SCRIPT || + it.elementType == CLASS_BODY || it.elementType == FUNCTION_LITERAL + }) { if ((node.treeNext.elementType == RBRACE) xor (node.treePrev.elementType == LBRACE)) { // if both are present, this is not beginning or end // if both are null, then this block is empty and is handled in another rule diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt index 06ac3590e1..022d1c7913 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt @@ -111,3 +111,10 @@ fun String.removePrefix(): String { } return this } + +/** + * Checks if [this] String is a name of a kotlin script file by checking whether file extension equals 'kts' + * + * @return true if this is a kotlin script file name, false otherwise + */ +fun String.isKotlinScript() = endsWith(".kts") diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt index 5828452d55..e99af228b7 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt @@ -25,18 +25,14 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -import java.io.File - import kotlinx.serialization.encodeToString -typealias ruleToConfig = Map> +typealias ruleToConfig = Map> /** * Test for [DiktatRuleSetProvider] in autocorrect mode as a whole. All rules are applied to a file. * Note: ktlint uses initial text from a file to calculate line and column from offset. Because of that line/col of unfixed errors * may change after some changes to text or other rules. - * - * fixme: run as a separate maven goal/module? */ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", { DiktatRuleSetProvider(configFilePath) }, @@ -55,9 +51,9 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", rulesConfig.removeIf { it.name == warning.name } rulesConfig.add(RulesConfig(warning.name, enabled = false, configuration = emptyMap())) } - rulesToOverride.forEach { (name, configuration) -> - rulesConfig.removeIf { it.name == name } - rulesConfig.add(RulesConfig(name, enabled = true, configuration = configuration)) + rulesToOverride.forEach { (warning, configuration) -> + rulesConfig.removeIf { it.name == warning.name } + rulesConfig.add(RulesConfig(warning.name, enabled = true, configuration = configuration)) } } createTempFile() @@ -106,7 +102,7 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", fun `smoke test #5`() { overrideRulesConfig(emptyList(), mapOf( - Warnings.HEADER_MISSING_OR_WRONG_COPYRIGHT.name to mapOf( + Warnings.HEADER_MISSING_OR_WRONG_COPYRIGHT to mapOf( "isCopyrightMandatory" to "true", "copyrightText" to """|Copyright 2018-2020 John Doe. | Licensed under the Apache License, Version 2.0 (the "License"); @@ -146,13 +142,8 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", @Test @Tag("DiktatRuleSetProvider") fun `smoke test #2`() { - // fixme: path shouldn't point to `target` directory - // val expectedFileAbsolutePath = Path.of(Path.of("target/test-classes/$resourceFilePath").toAbsolutePath().toString(), "Example2Test.kt_copy") - - val expectedFileAbsolutePath = File("target/test-classes/$resourceFilePath/Example2Test.kt_copy").absolutePath fixAndCompare("Example2Expected.kt", "Example2Test.kt") unfixedLintErrors.assertEquals( - LintError(1, 1, "$DIKTAT_RULE_SET_ID:file-naming", "${FILE_NAME_INCORRECT.warnText()} Example2Test.kt_copy", true), // todo this is a false one LintError(1, 1, "$DIKTAT_RULE_SET_ID:header-comment", "${HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE.warnText()} there are 2 declared classes and/or objects", false), LintError(14, 17, "$DIKTAT_RULE_SET_ID:comments", "${Warnings.COMMENTED_OUT_CODE.warnText()} private class Test : RuntimeException()", false) ) @@ -163,8 +154,7 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", fun `smoke test #1`() { fixAndCompare("Example1Expected.kt", "Example1Test.kt") unfixedLintErrors.assertEquals( - LintError(1, 1, "$DIKTAT_RULE_SET_ID:file-naming", "${FILE_NAME_INCORRECT.warnText()} Example1Test.kt_copy", true), // todo this is a false one - LintError(1, 1, "$DIKTAT_RULE_SET_ID:file-naming", "${FILE_NAME_MATCH_CLASS.warnText()} Example1Test.kt_copy vs Example", true), // todo this is a false one + LintError(1, 1, "$DIKTAT_RULE_SET_ID:file-naming", "${FILE_NAME_MATCH_CLASS.warnText()} Example1Test.kt vs Example", true), LintError(1, 1, "$DIKTAT_RULE_SET_ID:kdoc-formatting", "${KDOC_NO_EMPTY_TAGS.warnText()} @return", false), LintError(3, 6, "$DIKTAT_RULE_SET_ID:kdoc-comments", "${MISSING_KDOC_TOP_LEVEL.warnText()} Example", false), LintError(3, 26, "$DIKTAT_RULE_SET_ID:kdoc-comments", "${MISSING_KDOC_CLASS_ELEMENTS.warnText()} isValid", false), @@ -179,6 +169,25 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", ) } + @Test + @Tag("DiktatRuleSetProvider") + fun `smoke test with kts files`() { + overrideRulesConfig( + listOf( + HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE // because build.gradle.kts doesn't need extra comments, and this rule can be manually disabled if needed + ), + mapOf( + Warnings.WRONG_INDENTATION to mapOf( + "newlineAtEnd" to "false", + "extendedIndentOfParameters" to "false", + ) + ) + ) // so that trailing newline isn't checked + // file name is `gradle_` so that IDE doesn't suggest to import gradle project + fixAndCompare("../../../build.gradle_.kts", "../../../build.gradle_.kts") + Assertions.assertTrue(unfixedLintErrors.isEmpty()) + } + companion object { private const val DEFAULT_CONFIG_PATH = "../diktat-analysis.yml" private val unfixedLintErrors: MutableList = mutableListOf() diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt index 08ab2f3603..bc4098575f 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt @@ -30,6 +30,7 @@ open class LintTestBase(private val ruleSupplier: (rulesConfigList: List?) -> KtLint.Params( text = text, ruleSets = listOf(ruleSetProviderRef.invoke(rulesConfigList).get()), - fileName = fileName, + fileName = fileName.removeSuffix("_copy"), + script = fileName.removeSuffix("_copy").endsWith("kts"), cb = cb, - userData = mapOf("file_path" to fileName) + userData = mapOf("file_path" to fileName.removeSuffix("_copy")) ) ) diff --git a/diktat-rules/src/test/resources/test/smoke/build.gradle_.kts b/diktat-rules/src/test/resources/test/smoke/build.gradle_.kts new file mode 100644 index 0000000000..649b9b7d6a --- /dev/null +++ b/diktat-rules/src/test/resources/test/smoke/build.gradle_.kts @@ -0,0 +1,36 @@ +import org.cqfn.diktat.generation.docs.generateAvailableRules +import org.cqfn.diktat.generation.docs.generateCodeStyle +import org.cqfn.diktat.generation.docs.generateFullDoc +import org.cqfn.diktat.generation.docs.generateRulesMapping + +plugins { + kotlin("jvm") version "1.4.21" + id("org.cqfn.diktat.diktat-gradle-plugin") version "0.1.7" +} + +repositories { + jcenter() + mavenCentral() + maven { url = uri("https://example.com") } +} + +tasks.register("generateAvailableRules") { + dependsOn("generateRulesMapping") + doFirst { + generateAvailableRules(rootDir, file("$rootDir/../wp")) + } +} + +tasks.register("updateDocumentation") { + dependsOn( + "generateRulesMapping", + "generateAvailableRules", + "generateFullDoc", + "generateCodeStyle" + ) +} + +diktat { + debug = true + inputs = files("buildSrc/**/*.kt", "*.kts") +} diff --git a/pom.xml b/pom.xml index f2869f3ef5..c90dfa48ec 100644 --- a/pom.xml +++ b/pom.xml @@ -308,7 +308,7 @@ ${maven.compile.classpath} 1.4 1.8 - **/resources/**/*.kt + **/resources/**/*.kt,**/resources/**/*.kts From 565e2e9101341f002921775261e15eac1e6ac7e9 Mon Sep 17 00:00:00 2001 From: Alexander Tsay <48321920+aktsay6@users.noreply.github.com> Date: Wed, 30 Dec 2020 11:21:28 +0300 Subject: [PATCH 3/3] Feature. All rules should be commented in diktat-analysis.yml (#673) * feature/yml-rule-comments(#470) ### What's done: * Commented rules and parameters in all yml files * Added test --- diktat-analysis.yml | 101 ++++++++++++++- .../ruleset/rules/ConsecutiveSpacesRule.kt | 2 +- .../main/resources/diktat-analysis-huawei.yml | 109 +++++++++++++++- .../src/main/resources/diktat-analysis.yml | 122 +++++++++++++++--- .../chapter3/ConsecutiveSpacesRuleFixTest.kt | 2 +- .../chapter3/ConsecutiveSpacesRuleWarnTest.kt | 2 +- .../ruleset/utils/RulesConfigYamlTest.kt | 25 ++++ 7 files changed, 336 insertions(+), 27 deletions(-) diff --git a/diktat-analysis.yml b/diktat-analysis.yml index 38a03d1f58..5744f1ca3f 100644 --- a/diktat-analysis.yml +++ b/diktat-analysis.yml @@ -1,185 +1,278 @@ +# Common configuration - name: DIKTAT_COMMON enabled: true configuration: + # put your package name here - it will be autofixed and checked domainName: org.cqfn.diktat + # 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 +# 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 +# Checks that package name starts with the company's domain - name: PACKAGE_NAME_INCORRECT_PREFIX enabled: true +# 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: true +# 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: false copyrightText: '' +# 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 +# Checks that there is no wildcard imports. Exception: allowedWildcards - name: FILE_WILDCARD_IMPORTS enabled: true configuration: + # Allowed wildcards for imports (e.g. "import org.cqfn.diktat.*, import org.jetbrains.kotlin.*") allowedWildcards: "kotlinx.serialization.*,org.cqfn.diktat.ruleset.utils.*" +# 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: false + # 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 + # If true: when dot qualified expression starts on a new line, this line will be indented with two indentations instead of one extendedIndentBeforeDot: false + # 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: '180' +# 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 @@ -208,8 +301,10 @@ 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 diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ConsecutiveSpacesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ConsecutiveSpacesRule.kt index 7c2e549cb0..25330bcdb8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ConsecutiveSpacesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ConsecutiveSpacesRule.kt @@ -79,7 +79,7 @@ class ConsecutiveSpacesRule(private val configRules: List) : Rule(" /** * Maximum allowed number of consecutive spaces (not counting indentation) */ - val numberOfSpaces = config["max_spaces"]?.toIntOrNull() ?: MAX_SPACES + val numberOfSpaces = config["maxSpaces"]?.toIntOrNull() ?: MAX_SPACES /** * Whether formatting for enums should be kept without checking diff --git a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml index 3d8614fc42..ab0fd7cc40 100644 --- a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml +++ b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml @@ -1,183 +1,278 @@ +# Common configuration - name: DIKTAT_COMMON enabled: true configuration: + # put your package name here - it will be autofixed and checked domainName: com.huawei + # 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 +# 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 +# Checks that package name starts with the company's domain - name: PACKAGE_NAME_INCORRECT_PREFIX enabled: true +# 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: true +# 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) Huawei Technologies Co., Ltd. 2012-2020. All rights reserved. + copyrightText: ' Copyright (c) Huawei Technologies Co., Ltd. 2012-2020. All rights reserved.' +# 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 +# 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 + # If true: when dot qualified expression starts on a new line, this line will be indented with two indentations instead of one + extendedIndentBeforeDot: false + # 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 @@ -206,8 +301,10 @@ 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 @@ -228,8 +325,8 @@ - name: TOO_LONG_FUNCTION enabled: true configuration: - maxFunctionLength: '30' # max length of function - isIncludeHeader: 'false' # count function's header + maxFunctionLength: 30 # max length of function + isIncludeHeader: false # count function's header # Warns if there are nested functions - name: AVOID_NESTED_FUNCTIONS enabled: true diff --git a/diktat-rules/src/main/resources/diktat-analysis.yml b/diktat-rules/src/main/resources/diktat-analysis.yml index a043d1d4d5..009a44e353 100644 --- a/diktat-rules/src/main/resources/diktat-analysis.yml +++ b/diktat-rules/src/main/resources/diktat-analysis.yml @@ -1,185 +1,283 @@ +# 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 +# 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-2020' +# 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 +293,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 +343,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/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleFixTest.kt index e3f3b2c28c..5c0d458676 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleFixTest.kt @@ -14,7 +14,7 @@ class ConsecutiveSpacesRuleFixTest : FixTestBase("test/paragraph3/spaces", listOf( RulesConfig(Warnings.TOO_MANY_CONSECUTIVE_SPACES.name, true, mapOf( - "max_spaces" to "1", + "maxSpaces" to "1", "saveInitialFormattingForEnums" to "true" ) ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt index 2a1aa47818..3395a28035 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt @@ -15,7 +15,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { private val ruleId = "$DIKTAT_RULE_SET_ID:too-many-spaces" private val rulesConfigListNoSpaces: List = listOf( RulesConfig(TOO_MANY_CONSECUTIVE_SPACES.name, true, - mapOf("max_spaces" to "2")) + mapOf("maxSpaces" to "2")) ) @Test diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt index fd612f6cd3..b7c4776a01 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt @@ -30,6 +30,31 @@ class RulesConfigYamlTest { compareRulesAndConfig(thirdConfig, "parent/diktat-analysis.yml") } + @Test + fun `check comments before rules`() { + checkComments("src/main/resources/diktat-analysis.yml") + checkComments("src/main/resources/diktat-analysis-huawei.yml") + checkComments("../diktat-analysis.yml") + } + + private fun checkComments(configName: String) { + val lines = File(configName) + .readLines() + .filter { + it.startsWith("-") || it.startsWith("#") + } + + lines.forEachIndexed { index, str -> + if (str.startsWith("-")) { + Assertions.assertTrue(lines[if (index > 0) index - 1 else 0].trim().startsWith("#")) { + """ + There is no comment before $str in $configName + """.trimIndent() + } + } + } + } + private fun compareRulesAndConfig(nameConfig: String, nameConfigToText: String? = null) { val filePath = nameConfigToText?.let { pathMap[it] } ?: pathMap[nameConfig] val allRulesFromConfig = readAllRulesFromConfig(nameConfig)