revelc/formatter-maven-plugin

Tab treated as one space for the purpose of line length

Closed this issue · 3 comments

Describe the bug
Formats to a different line length than Eclipse when tabs are used. Eclipse computes line length based on tabulation.size, but formatter-maven-plugin considers a tab to be equivalent to a single space.

Versions

  • Affected version(s) of this project: 2.16.0
  • OS: Windows
  • Eclipse version 2023-06 (4.28.0)

To Reproduce

  1. Set the tab size to 8 (<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="8"/>).
  2. Set the line length to 80 (<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>).
  3. Create a Java file with JavaDoc on a method, indented with a single tab.
  4. Format the Java file.

Expected behavior
Should allow 72 characters for JavaDoc. That is what Eclipse does.

Actual behavior
Allows 79 characters for JavaDoc.

image

@DanTheDancer Are you using the exact same configuration as Eclipse? This plugin simply uses Eclipse to do that. I seem to recall there is one thing it does poorly and we had to account for but haven't seen any issues with javadocs myself.

Try importing your config into Eclipse, and re-exporting it. Most of the problems people have with this plugin doing things different from Eclipse is a version mismatch between their older config file and the plugin, which is based on newer Eclipse JDT libraries.

(EDIT: Also, stop using tabs, or at least stop using them while expecting the character count to match the visual... that is going to be notoriously dependent upon the editor, and is a very unfriendly thing to do to others working on a project with different local settings.)

@ctubbsii you are correct: our formatting profile was version 12 (ten years old). Using version 23 appears to solve the problem.

I think this bug is resolved. Will re-open if further testing reveals otherwise.