pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.19k stars 505 forks source link

Ignore suppressions in rule `no-unused-imports` #2725

Closed paul-dingemans closed 3 months ago

paul-dingemans commented 3 months ago

Description

Imports which are only used in code blocks which are suppressed for ktlint should not be reported as unused as removal results in compilation errors.

Refactored the code so that a rule can be marked with interface IgnoreKtlintSuppressions to indicate that all suppression for this rule are to be ignored.

The former SuppressionLocator lambda and object SuppressionLocatorBuilder are now replaced with the class SuppressionLocator. Upon each check whether a ASTNode has to be suppressed, it is also determined whether it is needed to rebuild the suppression hints. This is only needed when the code that is represented by the AST has been changed.

The CodeFormatter no longer has to rebuild the suppression locator after autocorrect. This responsibility is now moved into the RuleExecutionContext and SuppressionLocator itself.

Closes #2696

Checklist

Before submitting the PR, please check following (checks which are not relevant may be ignored):

Documentation is updated. See difference between snapshot and release documentation