Updated on 2026-08-14
This commit is contained in:
parent
1a0eaa779a
commit
654b2ff948
17 changed files with 103 additions and 36 deletions
|
|
@ -22,13 +22,19 @@ private fun DetektExtension.configure(project: Project) {
|
|||
ignoreFailures = false
|
||||
autoCorrect = true
|
||||
buildUponDefaultConfig = true
|
||||
config.setFrom(project.rootProject.files("tangem-android-tools/detekt-config.yml"))
|
||||
config.setFrom(
|
||||
project.rootProject.files(
|
||||
"tangem-android-tools/detekt-config.yml",
|
||||
"plugins/detekt-rules/app-detekt-config.yml"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun Project.configureDetektPlugins() {
|
||||
listOf(
|
||||
listOfNotNull(
|
||||
findLibrary(alias = "detekt-formatting"),
|
||||
findLibrary(alias = "detekt-compose"),
|
||||
findProject(":plugins:detekt-rules"),
|
||||
).forEach {
|
||||
dependencies.add(CONFIGURATION_DETEKT_PLUGINS, it)
|
||||
}
|
||||
|
|
|
|||
1
plugins/detekt-rules/.gitignore
vendored
Normal file
1
plugins/detekt-rules/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
3
plugins/detekt-rules/app-detekt-config.yml
Normal file
3
plugins/detekt-rules/app-detekt-config.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
tangem-rules:
|
||||
UnsafeStringResourceUsage:
|
||||
active: true
|
||||
7
plugins/detekt-rules/build.gradle.kts
Normal file
7
plugins/detekt-rules/build.gradle.kts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(deps.detekt.api)
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.detekt
|
||||
|
||||
import com.tangem.detekt.rules.UnsafeStringResourceUsage
|
||||
import io.gitlab.arturbosch.detekt.api.Config
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSet
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
|
||||
|
||||
class TangemRuleSetProvider : RuleSetProvider {
|
||||
|
||||
override val ruleSetId: String = "tangem-rules"
|
||||
|
||||
override fun instance(config: Config): RuleSet {
|
||||
return RuleSet(
|
||||
id = ruleSetId,
|
||||
rules = listOf(
|
||||
UnsafeStringResourceUsage(config),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.tangem.detekt.rules
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
class UnsafeStringResourceUsage(config: Config) : Rule(config) {
|
||||
|
||||
override val issue: Issue = Issue(
|
||||
id = "UnsafeStringResourceUsage",
|
||||
severity = Severity.Security,
|
||||
description = "Avoid using stringResource directly in the code.",
|
||||
debt = Debt.FIVE_MINS,
|
||||
)
|
||||
|
||||
val unsafeFunctionNames = listOf("stringResource", "pluralStringResource")
|
||||
|
||||
override fun visitCallExpression(expression: KtCallExpression) {
|
||||
super.visitCallExpression(expression)
|
||||
|
||||
val functionName = expression.calleeExpression?.text
|
||||
if (functionName in unsafeFunctionNames) {
|
||||
report(
|
||||
CodeSmell(
|
||||
issue = issue,
|
||||
entity = Entity.from(expression),
|
||||
message = "Usage of `$functionName` is unsafe. Use the version of the function with the `Safe` " +
|
||||
"suffix. For example, `${functionName}Safe`."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
com.tangem.detekt.TangemRuleSetProvider
|
||||
Loading…
Add table
Add a link
Reference in a new issue