diktat icon indicating copy to clipboard operation
diktat copied to clipboard

Variable names ending with a capital letter are considered errors

Open aiovlev opened this issue 4 years ago • 1 comments

Describe the bug

Variable names ending with a capital letter are considered errors.

Expected behavior

no warnings/errors

Observed behavior

[VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: topK

Steps to Reproduce

Create a variable ending with a capital letter (for example topK) and run mvn diktat:check

Environment information

  • diktat version: 1.0.0-rc3
  • build tool (maven/gradle): maven
  • how is diktat run (CLI, plugin, etc.): plugin
  • kotlin version: 1.5.10
  • operating system: WSL

aiovlev avatar Oct 18 '21 15:10 aiovlev

We use the following pattern to detect lower camel case: [a-z]([a-z0-9])*([A-Z][a-z0-9]+)*

fun String.isLowerCamelCase(): Boolean = this.matches("[a-z]([a-z0-9])*([A-Z][a-z0-9]+)*".toRegex())

Probably, the regex can be updated to [a-z]([a-z0-9])*([A-Z][a-z0-9]+)*[A-Z]?. But need to test StringCaseUtils

nulls avatar Dec 19 '23 12:12 nulls