saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
537 stars 39 forks source link

Variable names ending with a capital letter are considered errors #1079

Open aiovlev opened 3 years ago

aiovlev commented 3 years ago

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

nulls commented 10 months ago

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