Skip to content

checkstyle line numbers are offset #1386

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

Closed
aep opened this issue Mar 16, 2017 · 6 comments · Fixed by #3694
Closed

checkstyle line numbers are offset #1386

aep opened this issue Mar 16, 2017 · 6 comments · Fixed by #3694
Labels
bug Panic, non-idempotency, invalid code, etc. p-low

Comments

@aep
Copy link

aep commented Mar 16, 2017

in src/rustfmt_diff.rs line 41 line number is offset by context_queue to start the line at the start of the patch

  mismatch = Mismatch::new(line_number - context_queue.len() as u32);

but will make the output of checkstyle incorrect.
this affects PR1384

would adding be another member to Mismatch with the real line number be ok?

@nrc nrc added the bug Panic, non-idempotency, invalid code, etc. label Mar 16, 2017
@nrc
Copy link
Member

nrc commented Mar 16, 2017

would adding be another member to Mismatch with the real line number be ok?

sgtm

aep added a commit to aep/codeclimate-rustfmt that referenced this issue Mar 16, 2017
@aep
Copy link
Author

aep commented Mar 16, 2017

ideally we'd have a begin and end of the mismatch for #1384

@TimDiekmann
Copy link
Member

Is it possible to raise the priority or give me mentoring on how to correct this bug?

@calebcartwright
Copy link
Member

What exactly is the ask, to have the error nodes include both of the Mismatch members (the line number and the original line number)?

If so, I can submit a PR with a fix

@TimDiekmann
Copy link
Member

I think this would be a good solution, thanks!

@calebcartwright
Copy link
Member

calebcartwright commented Jul 19, 2019

Well this is turning out to be more complicated than I'd anticipated 😄 The biggest question I have is around what the expected or "correct" checkstyle xml content should be in this context as it's not clear to me what folks are using the checkstyle output for.

For a contrived example, take this source file:

 1|fn add(x: i32,
 2|y: i32) -> i32 {
 3|            x + y
 4|}
 5|
 6|
 7|fn multiply(a: i32,
 8|b: i32) -> i32 {
 9|         a * b
10| }

With standard config options, this would be formatted to:

 1|fn add(x: i32, y: i32) -> i32 {
 2|   x + y
 3|}
 4|
 5|fn multiply(a: i32, b: i32) -> i32 {
 6|    a * b
 7|}

If the checkstyle line numbers correspond to the formatted file, then we could reflect the mismatched lines with something like this:

<error line="1" severity="warning" message="Should be `fn add(x: i32, y: i32) -&gt; i32 {`" />
<error line="2" severity="warning" message="Should be `    x + y`" />
<error line="5" severity="warning" message="Should be `fn multiply(a: i32, b: i32) -&gt; i32 {`" />
<error line="6" severity="warning" message="Should be `    a * b`" />
<error line="7" severity="warning" message="Should be `}`" />

Things get a little tricky though when lines are removed as part of formatting. Take that closing } for the add function for example. It was on line 4 but is now on line 3, line 4 is now blank, and lines 8, 9, and 10 are now gone.

Would folks expect any/all of those other lines (3, 4, and/or 8-10) to be included in the checkstyle xml as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. p-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants