revelc/formatter-maven-plugin

Report problematic line number in error message

Closed this issue · 3 comments

dmak commented

Currently plugin reports that there is a problem with a given file, without providing the line number in which a formatting violation had occurred.

Would be great to output that line number to console next to file name.

The plugin can only verify whether the formatter plugin would have changed a file if it had been used to perform the formatting. It doesn't know which lines are the problem. It just signals you need to run the formatting task. If you use the plugin to format the file that caused the error, then you can easily perform a diff on the two files to see where the problem was. Reporting the specific line numbers and comparing formatted and unformatted files to do so is outside the scope of this plugin.

dmak commented

I think you find a right direction: when making a comparison, generate a unified diff, which will include an indication where the diff starts and thus makes further analysis faster. Is it difficult to add this functionality?

Generate formatted diff output in Java

@dmak It's not necessarily difficult. It's just a lot of extra code, and a lot to consider when trying to provide options to display the output. If we do this, then some people will want to suppress it, so we'll have to have options for doing that, and some people might want the files written but save the old files as backup, etc. Doing this just adds bloat, and possibly degrade performance.

Ultimately, none of it is necessary, since you can just run the formatter:format goal and see the diff yourself. If you're doing it in a GitHub Action, you can run formatter:validate as a goal, then conditionally on failure, run formatter:format and git diff. So, it's trivial to see the differences already without any changes in the plugin.