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

[FunctionNaming] Don't allow the usage of ` in function names #4439

Merged
merged 1 commit into from Jan 3, 2022
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
2 changes: 1 addition & 1 deletion detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -446,7 +446,7 @@ naming:
FunctionNaming:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)'
functionPattern: '[a-z][a-zA-Z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true
FunctionParameterNaming:
Expand Down
Expand Up @@ -32,7 +32,7 @@ class FunctionNaming(config: Config = Config.empty) : Rule(config) {
)

@Configuration("naming pattern")
private val functionPattern: Regex by config("([a-z][a-zA-Z0-9]*)|(`.*`)", String::toRegex)
private val functionPattern: Regex by config("[a-z][a-zA-Z0-9]*", String::toRegex)

@Configuration("ignores functions in classes which match this regex")
private val excludeClassPattern: Regex by config("$^", String::toRegex)
Expand Down
Expand Up @@ -97,11 +97,11 @@ class FunctionNamingSpec : Spek({
)
}

it("allow functions with backtick") {
it("doesn't allow functions with backtick") {
val code = """
fun `7his is a function name _`() = Unit
"""
assertThat(FunctionNaming().compileAndLint(code)).isEmpty()
assertThat(FunctionNaming().compileAndLint(code)).hasSourceLocations(SourceLocation(1, 5))
}
}
})
Expand Up @@ -85,10 +85,10 @@ class NamingConventionLengthSpec : Spek({
assertThat(subject.findings).isEmpty()
}

it("should not report a function name that begins with a backtick, capitals, and spaces") {
it("should report a function name that begins with a backtick, capitals, and spaces") {
val code = "fun `Hi bye`() = 3"
subject.compileAndLint(code)
assertThat(subject.findings).isEmpty()
assertThat(subject.findings).hasSize(1)
}
}
})