Skip to content

Commit

Permalink
Review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Jun 24, 2022
1 parent 04316c9 commit d87d5ed
Showing 5 changed files with 152 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -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 a proper format (usually UPPER_SNAKE_CASE)"),
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"),
@@ -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 ternary operator 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"),
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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"),
;
}

Original file line number Diff line number Diff line change
@@ -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)
)
}

@@ -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
)
}
Loading

0 comments on commit d87d5ed

Please sign in to comment.