Ignore suppressions in rule no-unused-imports
#2725
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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):
Closes #<xxx>
orFixes #<xxx>
(replace<xxx>
with issue number)Documentation is updated. See difference between snapshot and release documentation