You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We decide whether a warning should be issued (or whether the parent AST node doesn't have any @Suppress() annotation) from Warnings.warn() and Warnings.fix().
Approach A
In order to decide whether a particular @Suppress("XYZ") annotation (for the XYZ rule) on an AST node (or any of its parent nodes) is used or not, we must process all AST nodes in the given file and collect the following statistics:
whether any of the nodes has triggered a warning from the XYZ check
whether any of the node hierarchies are annotated with @Suppress("XYZ").
The simplest case (no warnings at all, at least one matching @Suppress annotation) is indeed easy to implement.
Yet, this needs to be done either at KtLint level or higher (DiktatMain level), as currently we're only in control of our rules (DiktatRule), and rules just don't have enough information.
Yet, there're more complex cases like empty intersection
(in the above case only the smallest-scope annotation should be preserved).
Approach B
If there're NDiktat checks suppressed in a given file, we could run Diktat at minimum 2 times (all suppressions on, all suppressions off), and at most O(N2) times, excluding suppressions one by one and checking whether there's any change in the number of warnings reported.
It might be a good idea to implement feature of detecting rule suppresses that could be removed e.g. this code:
would show warning as far as @Suppress("TYPE_ALIAS")` is unnecessary.
Moreover, fix feature might be also good.
The text was updated successfully, but these errors were encountered: