-
Notifications
You must be signed in to change notification settings - Fork 507
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
java.lang.IllegalStateException: Skipping rule(s) which are depending on a rule which is not loaded #2338
Comments
The idea is no repeat logic in multiple rules as those can get out of sync which can lead to conflicts between rules. Also, sharing of logic between rules by using additional classes goes against the ktlint architecture. Restrictions like your example are only created when a rule (A) can only be executed if it is guarranteed that another rule (B) has been formatting a node beforehand. In this way rule B can ignore harmful situations which are already resolved by rule (A). If rule B could not assume this, it has to repeat logic from rule A to be able to format the code in a reasonable way. Ktlint allows to define two different kind of relations between rules. The most strict relation is that a specific rule A must run before rule B (and as of that needs to be loaded and must be enabled) like in your example. The other relation states that rule A must run before rule B whenever rule A is enabled. By throwing the exception, you user is forced to configure ktlint in a consistent way. Silently ignoring rule
|
Well, practically speaking I found it impossible to configure ktlint in a way that would be workable for my organization. I'm not sure we'll ever be able to upgrade to ktlint 1.0, which will be a bit of an odd life experience for me given that separately I also maintain a gradle plugin for ktlint. Here's the problem, and the example you show there is a great example, a rule like |
Have you set The The
The |
I ran into this same issue, and I also came across another similar rule dependency like this which makes even less sense to me.
Why should comment locations have anything to do with actual code blocks. 😕 I only want to disable the |
I totally get this. Comments (and especially end of line comments) are always a lot of work to get right. Every now and then I see that even IntelliJ IDEA gets confused in refactoring of code with comments. I do not always have time and energy to take comments into account in every rule. Comments can almost literally be between any two tokens in the code. On a lot of places this totally makes no sense and probably no one will place comments at certain locations. But to make a rule resilient against comments you have to take this into account. For example:
Does the comment in sample above apply to the block preceding or following it. |
I appreciate it's a very difficult problem and compromises will need to be made somewhere. Thanks for the explanation. |
I can only 100% agree what Peter wrote. This really feels like a step backwards and not like something I'd consider 1.x |
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 on `discouraged-comment-location` and the number of locations which were forbidden, this became more and more a useability problem for certain users. Disabling the `discouraged-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: * Add utility methods `afterCodeSibling`, `beforeCodeSibling` and `betweenCodeSiblings` to ASTNodeExtensions * KtlintAssertThat now provides a more consistent interface for building rule assertion function which are depending on another rule. For some rules, the editorconfig properties regarding setting code style to `ktlint_official` have been removed as this code style is by default. Closes #2367
|
In general, I agree with the points raised here, I had to disable (at least at first) quite a few rules to be able to migrate to 1.x without many changes. Thanks for the adjustments around
is much better than
As general feedback, |
@jeremymailen wrote:
On this I replied with:
The dependency on the @jeremymailen Now the question is whether you meant that wrapping of the opening |
That sounds great. I only meant that adopting a different rule that affected all or many lines of code might become a sticking point. From a user point of view my opinion is that string template indent would ideally be independent of all other rules except the indent size. I totally admit this comes with a lot of implementation challenges and a rule needing some context input as to what formatting it's taking part in so that it's cooperative. |
As far as I know, no further action is required at this moment. It the issue is not yet completely resolved, please add new information. |
Observed Behavior
If you disable a rule such as:
It will cause execution to fail due to dependent rules requiring it to be loaded.
Expected Behavior
Disabling a rule should only prevent it from being evaluated, it shouldn't impact the executability of other rules which may share some behavior or logic.
Your Environment
The text was updated successfully, but these errors were encountered: