Skip to content

Commit

Permalink
Revert "serialVersionUID should be ignored in CONSTANT_UPPERCASE (#…
Browse files Browse the repository at this point in the history
…1849)"

This reverts commit bffd4ad.
  • Loading branch information
diphtongue authored Dec 12, 2023
1 parent fd85628 commit e13733c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 49 deletions.
2 changes: 0 additions & 2 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# Checks that CONSTANT (treated as const val from companion object or class level) is in non UPPER_SNAKE_CASE
- name: CONSTANT_UPPERCASE
enabled: true
configuration:
exceptionConstNames: "serialVersionUID"
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ class IdentifierNaming(configRules: List<RulesConfig>) : DiktatRule(
)

private fun checkVariableName(node: ASTNode): List<ASTNode> {
val configuration = ConstantUpperCaseConfiguration(
configRules.getRuleConfig(CONSTANT_UPPERCASE)?.configuration
?: emptyMap())

val exceptionNames = configuration.exceptionConstNames

// special case for Destructuring declarations that can be treated as parameters in lambda:
var namesOfVariables = extractVariableIdentifiers(node)

Expand All @@ -184,7 +178,7 @@ class IdentifierNaming(configRules: List<RulesConfig>) : DiktatRule(
// check for constant variables - check for val from companion object or on global file level
// it should be in UPPER_CASE, no need to raise this warning if it is one-letter variable
if (node.isConstant()) {
if (!exceptionNames.contains(variableName.text) && !variableName.text.isUpperSnakeCase() && variableName.text.length > 1) {
if (!variableName.text.isUpperSnakeCase() && variableName.text.length > 1) {
CONSTANT_UPPERCASE.warnOnlyOrWarnAndFix(
configRules = configRules,
emit = emitWarn,
Expand Down Expand Up @@ -499,10 +493,6 @@ class IdentifierNaming(configRules: List<RulesConfig>) : DiktatRule(
} ?: Style.SNAKE_CASE
}

class ConstantUpperCaseConfiguration(config: Map<String, String>) : RuleConfiguration(config) {
val exceptionConstNames = config["exceptionConstNames"]?.split(',') ?: emptyList()
}

class BooleanFunctionsConfiguration(config: Map<String, String>) : RuleConfiguration(config) {
/**
* A list of functions that return boolean and are allowed to use. Input is in a form "foo, bar".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
RulesConfig(FUNCTION_BOOLEAN_PREFIX.name, true,
mapOf("allowedPrefixes" to "equals, equivalent, foo"))
)
private val rulesConfigConstantUpperCase = listOf(
RulesConfig(CONSTANT_UPPERCASE.name, true, mapOf(
"exceptionConstNames" to "serialVersionUID"
))
)

// ======== checks for generics ========
@Test
Expand Down Expand Up @@ -200,37 +195,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
)
}

@Test
@Tag(WarningNames.CONSTANT_UPPERCASE)
fun `serialVersionUID should be ignored`() {
lintMethod(
"""
class TestSerializableClass() : Serializable {
companion object {
private const val serialVersionUID: Long = -1
}
}
""".trimIndent(),
rulesConfigList = rulesConfigConstantUpperCase
)
}

@Test
@Tag(WarningNames.CONSTANT_UPPERCASE)
fun `should trigger when the name is not exception`() {
val code =
"""
class TestSerializableClass() : Serializable {
companion object {
private const val serialVersion: Long = -1
}
}
""".trimIndent()
lintMethod(code,
DiktatError(3, 27, ruleId, "${CONSTANT_UPPERCASE.warnText()} serialVersion", true)
)
}

@Test
@Tags(Tag(WarningNames.IDENTIFIER_LENGTH), Tag(WarningNames.VARIABLE_NAME_INCORRECT))
fun `check variable length (check - negative)`() {
Expand Down

0 comments on commit e13733c

Please sign in to comment.