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 cd17d1a
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 144 deletions.
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 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"),
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 @@ -12,9 +12,9 @@ private val log = LoggerFactory.getLogger("StringCaseUtils")
/**
* Available cases to name enum members
*/
enum class Style {
PASCAL_CASE,
SNAKE_CASE,
enum class Style(val str: String) {
PASCAL_CASE("PascalCase"),
SNAKE_CASE("UPPER_SNAKE_CASE"),
;
}

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
Loading

0 comments on commit cd17d1a

Please sign in to comment.