New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move suppressions to core
#7101
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import io.github.detekt.test.utils.compileForTest | |
import io.gitlab.arturbosch.detekt.api.CompilerResources | ||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.Rule | ||
import io.gitlab.arturbosch.detekt.api.RuleSet | ||
import io.gitlab.arturbosch.detekt.core.suppressors.isSuppressedBy | ||
import org.intellij.lang.annotations.Language | ||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment | ||
import org.jetbrains.kotlin.config.languageVersionSettings | ||
|
@@ -25,12 +27,12 @@ fun Rule.compileAndLint(@Language("kotlin") content: String): List<Finding> { | |
|
||
fun Rule.lint(@Language("kotlin") content: String): List<Finding> { | ||
val ktFile = compileContentForTest(content) | ||
return visitFile(ktFile) | ||
return visitFile(ktFile).filterSuppressed(this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like to add this here too much but I think that for now it's the simpler solution. Why do we need this? Right now we have some tests on the rules that check that when an annotation is set the finding is not raised. Those tests are testing two things. From one side they are testing that the suppression works, that's tested already somewhere else so it should not be tested. But they are also testing that the The good part is that, if we want, we could refactor those tests and remove this later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step-by.step is the way to go here. As you said, I don't think it's ideal approach, though sufficient for now. |
||
} | ||
|
||
fun Rule.lint(path: Path): List<Finding> { | ||
val ktFile = compileForTest(path) | ||
return visitFile(ktFile) | ||
return visitFile(ktFile).filterSuppressed(this) | ||
} | ||
|
||
fun Rule.lintWithContext( | ||
|
@@ -47,7 +49,7 @@ fun Rule.lintWithContext( | |
|
||
val dataFlowValueFactory = DataFlowValueFactoryImpl(languageVersionSettings) | ||
val compilerResources = CompilerResources(languageVersionSettings, dataFlowValueFactory) | ||
return visitFile(ktFile, bindingContext, compilerResources) | ||
return visitFile(ktFile, bindingContext, compilerResources).filterSuppressed(this) | ||
} | ||
|
||
fun Rule.compileAndLintWithContext( | ||
|
@@ -60,4 +62,10 @@ fun Rule.compileAndLintWithContext( | |
return lintWithContext(environment, content) | ||
} | ||
|
||
fun Rule.lint(ktFile: KtFile): List<Finding> = visitFile(ktFile) | ||
fun Rule.lint(ktFile: KtFile): List<Finding> = visitFile(ktFile).filterSuppressed(this) | ||
|
||
private fun List<Finding>.filterSuppressed(rule: Rule): List<Finding> { | ||
return filterNot { | ||
it.entity.ktElement?.isSuppressedBy(rule.ruleId, rule.aliases, RuleSet.Id("NoARuleSetId")) == true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, detekt does not report, bur rather add it to the findings list.