Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change variable min & max length to match IntelliJ. #635

Merged
merged 3 commits into from Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions detekt-cli/src/main/resources/default-detekt-config.yml
Expand Up @@ -276,10 +276,10 @@ style:
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
VariableMinLength:
active: false
minimumVariableNameLength: 3
minimumVariableNameLength: 1
VariableMaxLength:
active: false
maximumVariableNameLength: 30
maximumVariableNameLength: 64
TopLevelPropertyNaming:
active: true
constantPattern: '[A-Z][_A-Z0-9]*'
Expand Down
4 changes: 2 additions & 2 deletions detekt-generator/documentation/style.md
Expand Up @@ -383,7 +383,7 @@ TODO: Specify description

#### Configuration options:

* `minimumVariableNameLength` (default: `3`)
* `minimumVariableNameLength` (default: `1`)

maximum name length

Expand All @@ -393,7 +393,7 @@ TODO: Specify description

#### Configuration options:

* `maximumVariableNameLength` (default: `30`)
* `maximumVariableNameLength` (default: `64`)

maximum name length

Expand Down
Expand Up @@ -10,7 +10,7 @@ import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.psi.KtProperty

/**
* @configuration maximumVariableNameLength - maximum name length (default: 30)
* @configuration maximumVariableNameLength - maximum name length (default: 64)
* @author Marvin Ramin
*/
class VariableMaxLength(config: Config = Config.empty) : Rule(config) {
Expand All @@ -33,6 +33,6 @@ class VariableMaxLength(config: Config = Config.empty) : Rule(config) {

companion object {
const val MAXIMUM_VARIABLE_NAME_LENGTH = "maximumVariableNameLength"
private const val DEFAULT_MAXIMUM_VARIABLE_NAME_LENGTH = 30
private const val DEFAULT_MAXIMUM_VARIABLE_NAME_LENGTH = 64
}
}
Expand Up @@ -11,8 +11,8 @@ import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore

/**
* @configuration minimumVariableNameLength - maximum name length (default: 3)
* @author Marvin Ramin
* @configuration minimumVariableNameLength - maximum name length (default: 1)
* @author Marvin Ramin, Niklas Baudy
*/
class VariableMinLength(config: Config = Config.empty) : Rule(config) {

Expand All @@ -38,6 +38,6 @@ class VariableMinLength(config: Config = Config.empty) : Rule(config) {

companion object {
const val MINIMUM_VARIABLE_NAME_LENGTH = "minimumVariableNameLength"
private const val DEFAULT_MINIMUM_VARIABLE_NAME_LENGTH = 3
private const val DEFAULT_MINIMUM_VARIABLE_NAME_LENGTH = 1
}
}
Expand Up @@ -15,14 +15,19 @@ class NamingConventionLengthSpec : SubjectSpek<NamingRules>({
Assertions.assertThat(subject.findings).isEmpty()
}

it("should report a variable name that is too short") {
it("should not report a variable with single letter name") {
val code = "private val a = 3"
subject.lint(code)
Assertions.assertThat(subject.findings).hasSize(1)
Assertions.assertThat(subject.findings).hasSize(0)
}
it("should not report a variable with 64 letters") {
val code = "private val varThatIsExactly64LettersLongWhichYouMightNotWantToBelieveInLolz = 3"
subject.lint(code)
Assertions.assertThat(subject.findings).hasSize(0)
}

it("should report a variable name that is too long") {
val code = "private val thisVariableIsDefinitelyWayTooLongAndShouldBeMuchShorter = 3"
val code = "private val thisVariableIsDefinitelyWayTooLongLongerThanEverythingAndShouldBeMuchShorter = 3"
subject.lint(code)
Assertions.assertThat(subject.findings).hasSize(1)
}
Expand Down