mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Introduced custom rule for detekt to exclude the deprecated imports
This commit is contained in:
parent
af23cf56b7
commit
8e6c74abe8
@ -22,6 +22,8 @@ dependencies {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
}
|
||||
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.20.0")
|
||||
// For defining custom rules in detekt
|
||||
implementation("io.gitlab.arturbosch.detekt:detekt-api:1.20.0")
|
||||
implementation("com.googlecode.json-simple:json-simple:1.1")
|
||||
|
||||
implementation(gradleApi())
|
||||
|
34
buildSrc/src/main/kotlin/plugin/CustomRuleProvider.kt
Normal file
34
buildSrc/src/main/kotlin/plugin/CustomRuleProvider.kt
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2023 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package plugin
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.Config
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSet
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
|
||||
|
||||
class CustomRulesProvider : RuleSetProvider {
|
||||
override val ruleSetId: String = "deprecation-rules"
|
||||
|
||||
override fun instance(config: Config): RuleSet = RuleSet(
|
||||
ruleSetId,
|
||||
listOf(
|
||||
DeprecationExclusionRule()
|
||||
)
|
||||
)
|
||||
}
|
31
buildSrc/src/main/kotlin/plugin/DeprecationExclusionRules.kt
Normal file
31
buildSrc/src/main/kotlin/plugin/DeprecationExclusionRules.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package plugin
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.CodeSmell
|
||||
import io.gitlab.arturbosch.detekt.api.Debt
|
||||
import io.gitlab.arturbosch.detekt.api.Entity
|
||||
import io.gitlab.arturbosch.detekt.api.Issue
|
||||
import io.gitlab.arturbosch.detekt.api.Rule
|
||||
import io.gitlab.arturbosch.detekt.api.Severity
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
|
||||
class DeprecationExclusionRule : Rule() {
|
||||
override val issue = Issue(
|
||||
id = "DeprecationExclusion",
|
||||
severity = Severity.CodeSmell,
|
||||
description = "Deprecated imports should be excluded",
|
||||
debt = Debt.FIVE_MINS
|
||||
)
|
||||
|
||||
override fun visitImportDirective(importDirective: KtImportDirective) {
|
||||
val importText = importDirective.text
|
||||
if (importText.contains("@Deprecated")) {
|
||||
report(
|
||||
CodeSmell(
|
||||
issue,
|
||||
Entity.from(importDirective),
|
||||
"Deprecated import found: $importText"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -31,6 +31,11 @@ console-reports:
|
||||
# - 'FindingsReport'
|
||||
- 'FileBasedFindingsReport'
|
||||
|
||||
deprecation-rules:
|
||||
active: true
|
||||
DeprecationExclusion:
|
||||
active: true
|
||||
|
||||
comments:
|
||||
active: true
|
||||
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
|
||||
@ -295,7 +300,7 @@ performance:
|
||||
potential-bugs:
|
||||
active: true
|
||||
Deprecation:
|
||||
active: false
|
||||
active: true
|
||||
DuplicateCaseInWhenExpression:
|
||||
active: true
|
||||
EqualsAlwaysReturnsTrueOrFalse:
|
||||
|
Loading…
x
Reference in New Issue
Block a user