Hi, I'm looking for a way to check function names ...
# detekt
c
Hi, I'm looking for a way to check function names that use backticks. Specifically, I want to ensure they do not start with an uppercase letter. It seems the FunctionParameterNaming rule doesn't apply to these functions. For example:
Copy code
@Test
fun `Invalid function name`() {
    
}

@Test
fun `valid function name`() {
    
}
Any guidance on this would be appreciated!
я
You can extend this rule
FunctionNaming
just change functionPattern to ``?([a-z][a-zA-Z0-9 ]*)`?` You need to do this in
detkt.yml
file, documentation
Copy code
FunctionNaming:
    active: true
    excludes: ['**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**']
    functionPattern: '`?([a-z][a-zA-Z0-9 ]*)`?'
    excludeClassPattern: '$^'
I did this for this test class
Copy code
class TestClass {

    fun test() {
        println()
    }

    fun Test() {
        println()
    }

    fun `Test function with capital`() {
        println()
    }

    fun `test function with lowercase letter`() {
        println()
    }
}
Rule found two issue
Copy code
/Users/yauheni/Projects/Home/CustomeDetectRule/app/src/test/java/com/github/kiolk/customedetectrule/TestClass.kt:9:9: Function names should match the pattern: `?([a-z][a-zA-Z0-9 ]*)`? [FunctionNaming]
/Users/yauheni/Projects/Home/CustomeDetectRule/app/src/test/java/com/github/kiolk/customedetectrule/TestClass.kt:13:9: Function names should match the pattern: `?([a-z][a-zA-Z0-9 ]*)`? [FunctionNaming]
👍 2
c
@Яўген Сліж thanks, it works as expected 😉