You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Class and function naming rules for main and test share the same configuration but it is very common to have different conventions, particularly with the use of ticks in test names. I would like to add an option to define a separate pattern for test classes/functions. Even a separate inner class pattern for tests would be good, as Detekt's test code reports violations of the ClassNaming rule (at least when I opened it up; maybe my IDE is not configured correctly?).
Expected Behavior of the rule
New configuration option for ClassNaming and FunctionNaming to allow different patterns for test identifiers.
Conventions for main and test code often different and should be able to be configured separately.
Examples from Detekt's tests (code not related to this report removed for clarity)
classAvoidReferentialEqualitySpec {
@Nested
innerclass `ReferentialEquality with defaults` {
@Test
fun`reports usage of === for strings`() {
}
@Test
fun`reports usage of !== for strings`() {
}
classDebtSpec {
fun`should print 20min, 10min and 5min`() {
}
}
classIgnoredReturnValueSpec {
@Test
fun`reports when the containing class of a function has _@CheckReturnValue_`() {
}
}
Caveat; Related Requirement
As far as I know, Detekt does not currently have a global way to differentiate main code from test code. There are a number of options to do this by default with optional overriding behavior:
Allow configuration to define a global pattern for main and test code. This is currently repeated often so it can simplify a lot of configuration. While the most usable solution, I would consider it as a separate enhancement.
Add a new configuration property to each of these rules to define what "test" means. Would require duplication unless the user utilizes YAML alias nodes.
Consider any file that imports a *.Test annotation to be a test file. Likely other common ones should be supported to. Not very clean.
At least initially, always use the same pattern for test packages, \w*([Tt]est|[Ss]pec. Make this globally configurable in a future enhancement.
Related issues and PRs
#5212 - Remove rule from NamingRules multi rule (Merged) #4144 / #4438 - Don't exclude tests for naming rules (Merged) #2656 / #3977 - Don't treat ` as part of class name (Merged)
The text was updated successfully, but these errors were encountered:
As far as I know, Detekt does not currently have a global way to differentiate main code from test code. There are a number of options to do this by default with optional overriding behavior:
Theoretically, you have a detektMain and a detektTest task (if you use type resolution). You could provide different config file for the two configurations.
I agree that is not easy to do and we have no documentation about it
We should have the ability to configure the same rule multiple times with different configurations. This kind of request is not new and it have a lot of sense.
Class and function naming rules for
main
andtest
share the same configuration but it is very common to have different conventions, particularly with the use of ticks in test names. I would like to add an option to define a separate pattern for test classes/functions. Even a separate inner class pattern for tests would be good, as Detekt's test code reports violations of theClassNaming
rule (at least when I opened it up; maybe my IDE is not configured correctly?).Expected Behavior of the rule
New configuration option for
ClassNaming
andFunctionNaming
to allow different patterns for test identifiers.Confirmed valid symbols in back-tick names: https://pl.kotl.in/zC3_rHFfG
Context
Conventions for
main
andtest
code often different and should be able to be configured separately.Examples from Detekt's tests (code not related to this report removed for clarity)
Caveat; Related Requirement
As far as I know, Detekt does not currently have a global way to differentiate main code from test code. There are a number of options to do this by default with optional overriding behavior:
*.Test
annotation to be a test file. Likely other common ones should be supported to. Not very clean.\w*([Tt]est|[Ss]pec
. Make this globally configurable in a future enhancement.Related issues and PRs
#5212 - Remove rule from NamingRules multi rule (Merged)
#4144 / #4438 - Don't exclude tests for naming rules (Merged)
#2656 / #3977 - Don't treat ` as part of class name (Merged)
The text was updated successfully, but these errors were encountered: