Skip to content

Commit

Permalink
Don't exclude tests in WildcardImport Rule (#5121)
Browse files Browse the repository at this point in the history
* Use MagicNumber as sample for the tests

* There is not a good reason to allow Wildcard imports inside the tests if you don't want them in your production code

* Remove exceptions in the WildcardImport rule
  • Loading branch information
BraisGabin committed Jul 25, 2022
1 parent c46b9ec commit bcb245e
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/detekt/detekt.yml
Expand Up @@ -274,3 +274,6 @@ style:
VarCouldBeVal:
active: true
ignoreAnnotated: ['Parameter']
WildcardImport:
active: true
excludeImports: []
1 change: 0 additions & 1 deletion detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -716,6 +716,5 @@ style:
ignoreLateinitVar: false
WildcardImport:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
excludeImports:
- 'java.util.*'
Expand Up @@ -60,7 +60,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.impl.source.JavaDummyElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.JavaDummyHolder
import org.jetbrains.kotlin.psi.KtFile
import java.util.*
import java.util.LinkedList

/**
* Runs all KtLint rules.
Expand Down
Expand Up @@ -27,7 +27,6 @@ private object TestExclusions : Exclusions() {
override val ruleSets = emptySet<String>()
override val rules = setOf(
"FunctionNaming",
"WildcardImport",
"LateinitUsage",
"StringLiteralDuplication",
"SpreadOperator",
Expand Down
Expand Up @@ -10,8 +10,8 @@ class DeprecatedPrinterSpec {
fun `prints the correct properties`() {
val markdownString = DeprecatedPrinter.print(listOf(createRuleSetPage()))
val expectedMarkdownString = """
style>WildcardImport>conf2=use conf1 instead
style>WildcardImport>conf4=use conf3 instead
style>MagicNumber>conf2=use conf1 instead
style>MagicNumber>conf4=use conf3 instead
""".trimIndent()
assertThat(markdownString).isEqualTo(expectedMarkdownString)
Expand Down
Expand Up @@ -59,7 +59,7 @@ internal fun createRuleSetPage(): RuleSetPage {

internal fun createRules(): List<Rule> {
val rule1 = Rule(
name = "WildcardImport",
name = "MagicNumber",
description = "a wildcard import",
nonCompliantCodeExample = "import foo.*",
compliantCodeExample = "import foo.bar",
Expand Down
2 changes: 1 addition & 1 deletion detekt-generator/src/test/resources/RuleSet.md
@@ -1,6 +1,6 @@
style rule set

### WildcardImport
### MagicNumber

a wildcard import

Expand Down
4 changes: 2 additions & 2 deletions detekt-generator/src/test/resources/RuleSetConfig.yml
Expand Up @@ -7,9 +7,9 @@ style:
rulesetconfig3:
- 'first'
- 'se*cond'
WildcardImport:
MagicNumber:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts']
conf1: 'foo'
conf3:
- 'a'
Expand Down

0 comments on commit bcb245e

Please sign in to comment.