-
Notifications
You must be signed in to change notification settings - Fork 39
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
Diktat produces wrong line:column
numbers in the "fix" mode if multiple rules are applied
#1538
Comments
2 tasks
@akuleshov7, @nulls, WDYT? |
@0x6675636b796f75676974687562, agree. We need to split fix and warn parts: we need to fix everything that possible in first run and then warn about left errors. But suggestion to make this change with old version of |
0x6675636b796f75676974687562
added a commit
that referenced
this issue
Oct 28, 2022
### What's done: * ktlint 0.47: migrate to the new Baseline API. * ktlint 0.47: make sure rule ids are always fully-qualified (pre-0.47 behaviour broken). * ktlint 0.47: suppress deprecation warnings (`RuleSet` and `RuleSetProvider` are now deprecated, scheduled for removal in 0.48). * ktlint 0.47: ignore the corrected errors when in "fix" mode (pre-0.47 behaviour broken). * ktlint 0.47, test code: allow lint errors to appear in any order (because of the new AST traversal order, see #1538). * Configure Surefire and Failsafe plugins for better reporting. * GutHub Actions: print out stack traces (`-X`) when running the snapshot version of the Maven plug-in. * Smoke tests: enable extra diagnostics when running `diktat` from `save-cli`. * Smoke tests: enable extra `save-cli` verbosity (`--log all`) when running it on Windows, too. * Smoke tests: when running `save-cli`, override the temporary directory on Windows (`TMP` and `TEMP`), because of pinterest/ktlint#1608. Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Andrey Shcheglov <[email protected]>
This was referenced Nov 3, 2023
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Diktat 1.2.3, Ktlint 0.46.1.
Consider this code fragment:
Diktat (e.g. when run from the command line) reports the following errors, all on the same line:
Now, when run in the "fix" mode, Diktat will correct all of the above errors except for the
MISSING_KDOC_ON_FUNCTION
:As you can see, the
line:column
numbers will no longer be9:54
but9:21
, because some of the rules have been already applied and some of the errors fixed. Yet,9:21
is absolutely misleading, because the resulting (formatted) file will look like this:If we run Diktat again (now against the reformatted file), there will be
10:5
instead of9:21
:The problem becomes even more evident after the upgrade to Ktlint 0.47.x (API Changes & RuleSet providers), because it has changed the way AST elements are traversed.
Consider there're multiple rules, ordered in a specific way:
Assuming there're multiple AST syntax nodes enclosed in each other:
Ktlint 0.46 used to recursively apply the above rules in the following order:
As of Ktlint 0.47, the traversal order is different:
In practice, when Diktat is run in the "fix" mode, this change in Ktlint behaviour results in the same error (e.g.:
MISSING_KDOC_ON_FUNCTION
) reported multiple times against different (incorrect) locations within a file.Probably, we should change our strategy to first running
KtLint.format()
ignoring any errors followed byKtLint.lint()
, and only report errors produced by the lastlint()
call.In particular, this blocks saveourtool/benedikt#3.
The text was updated successfully, but these errors were encountered: