Skip to content

Commit

Permalink
Update MagicNumber rule to exclude .kts files (#4877)
Browse files Browse the repository at this point in the history
* Update MagicNumber rule to exclude .kts files

The MagicNumber rule should not be enforced in script files,
because you cannot have constants in these files.

Closes #4863

* Adapt Exclusion.kt for MagicNumber rule
  • Loading branch information
schalkms committed May 31, 2022
1 parent b2ef7a6 commit f66a321
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -543,7 +543,7 @@ style:
maxJumpCount: 1
MagicNumber:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts']
ignoreNumbers:
- '-1'
- '0'
Expand Down
Expand Up @@ -5,7 +5,7 @@ import io.gitlab.arturbosch.detekt.generator.collection.Rule
/**
* Holds a list of extra exclusions for rules and rule sets.
*/
val exclusions = arrayOf(TestExclusions, KotlinScriptExclusions, LibraryExclusions)
val exclusions = arrayOf(TestExclusions, KotlinScriptExclusions, KotlinScriptAndTestExclusions, LibraryExclusions)

/**
* Tracks rules and rule sets which needs an extra `excludes: $pattern` property
Expand All @@ -28,7 +28,6 @@ private object TestExclusions : Exclusions() {
override val rules = setOf(
"FunctionNaming",
"WildcardImport",
"MagicNumber",
"LateinitUsage",
"StringLiteralDuplication",
"SpreadOperator",
Expand All @@ -51,6 +50,14 @@ private object KotlinScriptExclusions : Exclusions() {
override val rules = setOf("MissingPackageDeclaration")
}

private object KotlinScriptAndTestExclusions : Exclusions() {

override val pattern =
"['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', " +
"'**/*.kts']"
override val rules = setOf("MagicNumber")
}

private object LibraryExclusions : Exclusions() {

override val pattern = "['**']"
Expand Down

0 comments on commit f66a321

Please sign in to comment.