Skip to content

Commit

Permalink
Don't allow the usage of ` in function names (#4439)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Jan 3, 2022
1 parent 8cb63b7 commit ff7824d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
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)
}
}
})

0 comments on commit ff7824d

Please sign in to comment.