Skip to content
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

checkstyle inconsistent with prettier #631

Closed
xenoterracide opened this issue Jan 5, 2024 · 2 comments · Fixed by #633
Closed

checkstyle inconsistent with prettier #631

xenoterracide opened this issue Jan 5, 2024 · 2 comments · Fixed by #633

Comments

@xenoterracide
Copy link

xenoterracide commented Jan 5, 2024

[ant:checkstyle] [ERROR] Merge.java:40:80: Only one statement per line allowed. [OneStatementPerLine]
npx prettier --version
3.1.1
2.5.0
plugins:
  - prettier-plugin-java
  - prettier-plugin-properties
  - prettier-plugin-sh
  - prettier-plugin-toml
  - "@prettier/plugin-xml"

checkstyle, I copied pasta-ed from deda6ca#diff-6c435908fe54a62733ee357cc3ef828f242045ba31fa59d6d3f763b5352d694e which is just a link to the version in master at the time of this writing

Input:

        if (first == null) return second;
        else if (second == null) return first;

Output:

        if (first == null) return second; else if (second == null) return first;

Expected behavior:

no error, results should be consistent, however I'm not certain if prettier is creating the wrong output or if checkstyle is configured wrong. I'm kind of wondering if prettier can/should be adding the braces here in the first place.

@jtkiesel
Copy link
Contributor

jtkiesel commented Jan 6, 2024

Prettier JavaScript seems to leave the input as it is in this case (i.e. it wants a newline separating the if and else if, and doesn't automatically add braces.) We do have #459 that considers forcing braces around conditional bodies. That change would probably require more discussion than simply adding/keeping the newline, so I would suggest that the action item for this ticket is to add/keep the newline between the if and else if to mimic Prettier JavaScript's behavior (and to avoid violating the Checkstyle config we provide.)

@xenoterracide
Copy link
Author

xenoterracide commented Jan 6, 2024

I would be fine with leaving the input as is. I'm not sure how I feel about this particular style of code in general but reducing it to one line seems like the wrong answer. I temporarily fixed this code by adding braces around the first one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants