Skip to content

Commit

Permalink
Minor documentation fixes (#1332)
Browse files Browse the repository at this point in the history
### What's done:
- doc fixes
  • Loading branch information
orchestr7 authored Jun 24, 2022
1 parent dbb88ee commit 0351f52
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 175 deletions.
10 changes: 5 additions & 5 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
testDirs: test
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -180,7 +180,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum class Warnings(
CONSTANT_UPPERCASE(true, "1.5.1", "<val> properties from companion object or on file level mostly in all cases are constants - please use upper snake case for them"),
VARIABLE_HAS_PREFIX(true, "1.1.1", "variable has prefix (like mVariable or M_VARIABLE), generally it is a bad code style (Android - is the only exception)"),
IDENTIFIER_LENGTH(false, "1.1.1", "identifier's length is incorrect, it should be in range of [2, 64] symbols"),
ENUM_VALUE(true, "1.3.1", "enum values should be in selected UPPER_CASE snake/PascalCase format"),
ENUM_VALUE(true, "1.3.1", "enum values should be in a proper format/case"),
GENERIC_NAME(true, "1.1.1", "generic name should contain only one single capital letter, it can be followed by a number"),
BACKTICKS_PROHIBITED(false, "1.1.1", "backticks should not be used in identifier's naming. The only exception test methods marked with @Test annotation"),
FUNCTION_NAME_INCORRECT_CASE(true, "1.4.1", "function/method name should be in lowerCamelCase"),
Expand Down Expand Up @@ -103,7 +103,7 @@ enum class Warnings(
FILE_UNORDERED_IMPORTS(true, "3.1.2", "imports should be ordered alphabetically and shouldn't be separated by newlines"),
FILE_WILDCARD_IMPORTS(false, "3.1.2", "wildcard imports should not be used"),
UNUSED_IMPORT(true, "3.1.2", "unused imports should be removed"),
NO_BRACES_IN_CONDITIONALS_AND_LOOPS(true, "3.2.1", "in if, else, when, for, do, and while statements braces should be used. Exception: single line if statement."),
NO_BRACES_IN_CONDITIONALS_AND_LOOPS(true, "3.2.1", "in if, else, when, for, do, and while statements braces should be used. Exception: single line ternary operator statement"),
WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES(true, "3.1.4", "the declaration part of a class-like code structures (class/interface/etc.) should be in the proper order"),
BLANK_LINE_BETWEEN_PROPERTIES(true, "3.1.4", "there should be no blank lines between properties without comments; comment, KDoc or annotation on property should have blank" +
" line before"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,13 @@ class IdentifierNaming(configRules: List<RulesConfig>) : DiktatRule(
Style.SNAKE_CASE -> String::toUpperSnakeCase
}
if (!validator(value.text)) {
ENUM_VALUE.warnAndFix(configRules, emitWarn, isFixMode, value.text, value.startOffset, value) {
ENUM_VALUE.warnAndFix(
configRules,
emitWarn,
isFixMode,
"${value.text} (should be in ${configuration.enumStyle.str})",
value.startOffset, value
) {
// FixMe: add tests for this
(value as LeafPsiElement).rawReplaceWithText(autofix(value.text))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ private val log = LoggerFactory.getLogger("StringCaseUtils")

/**
* Available cases to name enum members
* @property str
*/
enum class Style {
PASCAL_CASE,
SNAKE_CASE,
enum class Style(val str: String) {
PASCAL_CASE("PascalCase"),
SNAKE_CASE("UPPER_SNAKE_CASE"),
;
}

Expand Down
10 changes: 5 additions & 5 deletions diktat-rules/src/main/resources/diktat-analysis-huawei.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
testDirs: test
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
enabled: true
# all code blocks with MyAnnotation will be ignored and not checked
ignoreAnnotated: [ MyAnnotation ]
# 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -182,7 +182,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
10 changes: 5 additions & 5 deletions diktat-rules/src/main/resources/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
disabledChapters: ""
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
enabled: true
# all code blocks with MyAnnotation will be ignored and not checked
ignoreAnnotated: [ MyAnnotation ]
# 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -182,7 +182,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
""".trimIndent()
lintMethod(code,
LintError(1, 12, ruleId, "${CLASS_NAME_INCORRECT.warnText()} TEST_ONE", true),
LintError(2, 5, ruleId, "${ENUM_VALUE.warnText()} first_value", true),
LintError(2, 18, ruleId, "${ENUM_VALUE.warnText()} secondValue", true),
LintError(2, 31, ruleId, "${ENUM_VALUE.warnText()} thirdVALUE", true),
LintError(2, 43, ruleId, "${ENUM_VALUE.warnText()} FourthValue", true)
LintError(2, 5, ruleId, "${ENUM_VALUE.warnText()} first_value (should be in UPPER_SNAKE_CASE)", true),
LintError(2, 18, ruleId, "${ENUM_VALUE.warnText()} secondValue (should be in UPPER_SNAKE_CASE)", true),
LintError(2, 31, ruleId, "${ENUM_VALUE.warnText()} thirdVALUE (should be in UPPER_SNAKE_CASE)", true),
LintError(2, 43, ruleId, "${ENUM_VALUE.warnText()} FourthValue (should be in UPPER_SNAKE_CASE)", true)
)
}

Expand All @@ -253,10 +253,10 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
""".trimIndent()
lintMethod(code,
LintError(1, 12, ruleId, "${CLASS_NAME_INCORRECT.warnText()} TEST_ONE", true),
LintError(2, 5, ruleId, "${ENUM_VALUE.warnText()} first_value", true),
LintError(2, 18, ruleId, "${ENUM_VALUE.warnText()} secondValue", true),
LintError(2, 31, ruleId, "${ENUM_VALUE.warnText()} thirdVALUE", true),
LintError(2, 43, ruleId, "${ENUM_VALUE.warnText()} FOURTH_VALUE", true),
LintError(2, 5, ruleId, "${ENUM_VALUE.warnText()} first_value (should be in PascalCase)", true),
LintError(2, 18, ruleId, "${ENUM_VALUE.warnText()} secondValue (should be in PascalCase)", true),
LintError(2, 31, ruleId, "${ENUM_VALUE.warnText()} thirdVALUE (should be in PascalCase)", true),
LintError(2, 43, ruleId, "${ENUM_VALUE.warnText()} FOURTH_VALUE (should be in PascalCase)", true),
rulesConfigList = rulesConfigPascalCaseEnum
)
}
Expand Down
10 changes: 5 additions & 5 deletions examples/gradle-groovy-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
disabledChapters: ""
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
enabled: true
# all code blocks with MyAnnotation will be ignored and not checked
ignoreAnnotated: [ MyAnnotation ]
# 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -182,7 +182,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
10 changes: 5 additions & 5 deletions examples/gradle-kotlin-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
disabledChapters: ""
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
enabled: true
# all code blocks with MyAnnotation will be ignored and not checked
ignoreAnnotated: [ MyAnnotation ]
# 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -182,7 +182,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
10 changes: 5 additions & 5 deletions examples/maven/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
disabledChapters: ""
kotlinVersion: 1.7
srcDirectories: "main"
# Checks that the Class/Enum/Interface name does not match Pascal case
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
enabled: true
# all code blocks with MyAnnotation will be ignored and not checked
ignoreAnnotated: [ MyAnnotation ]
# 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
# Checks that enum value is in upper SNAKE_CASE or in PascalCase depending on the config. UPPER_SNAKE_CASE is the default, but can be changed by 'enumStyle' config
- name: ENUM_VALUE
enabled: true
configuration:
# Two options: snakeCase(default), PascalCase
enumStyle: snakeCase
# Two options: SNAKE_CASE (default), PascalCase
enumStyle: SNAKE_CASE
# Checks that class which extends any Exception class has Exception suffix
- name: EXCEPTION_SUFFIX
enabled: true
Expand Down Expand Up @@ -182,7 +182,7 @@
enabled: true
configuration:
deleteUnusedImport: true
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line if statement
# Checks that braces are used in if, else, when, for, do, and while statements. Exception: single line ternary operator 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
Expand Down
Loading

0 comments on commit 0351f52

Please sign in to comment.