Remove dependencies on discouraged-comment-location rule #2371
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
Rule
discouraged-comment-location
intended to make implementation of rules easier. By disallowing those locations, the rules did not need to take them into accound.Disabling the
discouraged-comment-location
rule however also forced users to disable other rules as well (for example see #2338). With the number of rules that depended ondiscouraged-comment-location
and the number of locations which were forbidden, this became more and more a useability problem for certain users. Disabling thediscouraged-comment-location
rule for one specific type of comment location was not possible. So only choiche was to disable the entire rule and all rules that depend on it.The
discouraged-comment-location
rule still exists to avoid a breaking change. But it no longer provides any functionality anymore. The logic of this rule has been moved to normal rule classes in case a discouraged comment location was added for one specific rule only. Comment locations that are more generic (e.g. used by at least two different rules) are moved to separate rules as this provides more clarity about rule dependencies.Rules below no longer depend on any other rule to handle disallowed comment location. If needed, the rules provide custom checks:
chain-method-continuation
if-else-wrapping
New rules below are added to check for disallowed comment locations in constructs that are used by multiple rules:
type-argument/type-argument-list
type-projection/type-parameter-list
value-argument/value-argument-list
value-parameter/value-parameter-list
Rules that previously relied explicitly or implicitly on the
discouraged-comment-location
rule now explicitly depend on rules above. If rules above are disabled, it is now more clear why a rule has a dependency on that rule as it is more specific.To provide above, following functionality was added as well:
afterCodeSibling
,beforeCodeSibling
andbetweenCodeSiblings
to ASTNodeExtensionsktlint_official
have been removed as this code style is by default.Closes #2367
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)CHANGELOG.md
is updatedDocumentation is updated. See difference between snapshot and release documentation