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

Remove rule from NamingRules multi rule #5212

Merged
merged 17 commits into from Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -42,6 +42,9 @@ class ConstructorParameterNaming(config: Config = Config.empty) : Rule(config) {
private val ignoreOverridden: Boolean by config(true)

override fun visitParameter(parameter: KtParameter) {
if (parameter.nameAsSafeName.isSpecial || parameter.nameIdentifier?.parent?.javaClass == null) {
return
}
if (parameter.isContainingExcludedClassOrObject(excludeClassPattern) || isIgnoreOverridden(parameter)) {
return
}
Expand Down
Expand Up @@ -46,6 +46,9 @@ class FunctionParameterNaming(config: Config = Config.empty) : Rule(config) {
private val ignoreOverridden: Boolean by configWithFallback(::ignoreOverriddenFunctions, true)

override fun visitParameter(parameter: KtParameter) {
if (parameter.nameAsSafeName.isSpecial || parameter.nameIdentifier?.parent?.javaClass == null) {
return
}
if (parameter.isContainingExcludedClass(excludeClassPattern)) {
return
}
Expand Down
Expand Up @@ -32,6 +32,10 @@ class NamingProvider : DefaultRuleSetProvider {
FunctionNaming(config),
EnumNaming(config),
ObjectPropertyNaming(config),
FunctionMinLength(config),
FunctionMaxLength(config),
VariableMaxLength(config),
VariableMaxLength(config),
cortinico marked this conversation as resolved.
Show resolved Hide resolved
)
)
}

This file was deleted.

@@ -0,0 +1,34 @@
package io.gitlab.arturbosch.detekt.rules.naming

import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test

class FunctionMaxLengthSpec {

@Test
fun `should report a function name that is too long base on config`() {
val subject = FunctionMaxLength(TestConfig(mapOf("maximumFunctionNameLength" to 10)))
val code = "fun thisFunctionLongName() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).hasSize(1)
}

@Test
fun `should report a function name that is too long`() {
val subject = FunctionMaxLength()
val code = "fun thisFunctionIsDefinitelyWayTooLongAndShouldBeMuchShorter() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).hasSize(1)
}

@Test
fun `should not report a function name that is okay`() {
val subject = FunctionMaxLength()
val code = "fun three() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).isEmpty()
}

}
@@ -0,0 +1,34 @@
package io.gitlab.arturbosch.detekt.rules.naming

import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions
Fixed Show fixed Hide fixed
import org.junit.jupiter.api.Test

class FunctionMinLengthSpec {

@Test
fun `should report a function name that is too short`() {
val subject = FunctionMinLength()
val code = "fun a() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).hasSize(1)
}

@Test
fun `should report a function name that is too short base on config`() {
val subject = FunctionMinLength(TestConfig(mapOf("minimumFunctionNameLength" to 5)))
val code = "fun four() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).hasSize(1)
}

@Test
fun `should not report a function name that is okay`() {
val subject = FunctionMinLength()
val code = "fun three() = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).isEmpty()
}

}

This file was deleted.

This file was deleted.

Expand Up @@ -9,7 +9,7 @@ class PackageNamingSpec {

@Test
fun `should use custom name for package`() {
val rule = NamingRules(TestConfig(PackageNaming.PACKAGE_PATTERN to "^(package_1)$"))
val rule = PackageNaming(TestConfig(PackageNaming.PACKAGE_PATTERN to "^(package_1)$"))
assertThat(rule.compileAndLint("package package_1")).isEmpty()
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ class TopLevelPropertyNamingSpec {
@Test
fun `should use custom name top level propeties`() {
assertThat(
NamingRules(TestConfig(mapOf(TopLevelPropertyNaming.CONSTANT_PATTERN to "^lowerCaseConst$"))).compileAndLint(
TopLevelPropertyNaming(TestConfig(mapOf(TopLevelPropertyNaming.CONSTANT_PATTERN to "^lowerCaseConst$"))).compileAndLint(
"""
class Foo{
companion object {
Expand Down
@@ -0,0 +1,32 @@
package io.gitlab.arturbosch.detekt.rules.naming

import io.gitlab.arturbosch.detekt.test.assertThat
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.junit.jupiter.api.Test

class VariableMaxLengthSpec {

@Test
fun `should not report underscore variable names`() {
val code = """
fun getResult(): Pair<String, String> = TODO()
fun function() {
val (_, status) = getResult()
}
"""
assertThat(VariableMaxLength().compileAndLint(code)).isEmpty()
}

@Test
fun `should not report a variable with 64 letters`() {
val code = "private val varThatIsExactly64LettersLongWhichYouMightNotWantToBelieveInLolz = 3"
assertThat(VariableMaxLength().compileAndLint(code)).isEmpty()
}

@Test
fun `should report a variable name that is too long`() {
val code = "private val thisVariableIsDefinitelyWayTooLongLongerThanEverythingAndShouldBeMuchShorter = 3"
assertThat(VariableMaxLength().compileAndLint(code)).hasSize(1)
}

}
@@ -0,0 +1,62 @@
package io.gitlab.arturbosch.detekt.rules.naming

import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions
Fixed Show fixed Hide fixed
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

class VariableMinLengthSpec {

@Nested
inner class `VariableMinLength rule with a custom minimum length` {

val variableMinLength =
VariableMinLength(TestConfig(mapOf(VariableMinLength.MINIMUM_VARIABLE_NAME_LENGTH to "2")))

@Test
fun `reports a very short variable name`() {
val code = "private val a = 3"
Assertions.assertThat(variableMinLength.compileAndLint(code)).hasSize(1)
}

@Test
fun `does not report a variable with only a single underscore`() {
val code = """
class C {
val prop: (Int) -> Unit = { _ -> Unit }
}
"""
Assertions.assertThat(variableMinLength.compileAndLint(code)).isEmpty()
}
}

@Test
fun `should not report a variable name that is okay`() {
val subject = VariableMinLength()
val code = "private val thisOneIsCool = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).isEmpty()
}

@Test
fun `should not report a variable with single letter name`() {
val subject = VariableMinLength()
val code = "private val a = 3"
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).isEmpty()
}

@Test
fun `should not report underscore variable names`() {
val subject = VariableMinLength()
val code = """
fun getResult(): Pair<String, String> = TODO()
fun function() {
val (_, status) = getResult()
}
"""
subject.compileAndLint(code)
Assertions.assertThat(subject.findings).isEmpty()
}
}