Skip to content

[Java] Replace checkstyle with google-java-format or another formatter? #213

Closed

Description

@lidavidm

Describe the enhancement requested

checkstyle is unfortunately only a linter and cannot auto-format. google-java-format (or possibly some other plugin like clang-format) can be run to check and reformat files. google-java-format additionally integrates with IntelliJ. This makes development smoother.

However, we would have to reformat the entire codebase. Possibly, we can do this module-by-module.

Component(s)

Developer Tools, Java

Activity

  1. added
    Type: enhancement
    on Feb 27, 2023
  2. aiguofer commented on Feb 27, 2023

    @aiguofer
    Contributor

    +1! Coming from the python world, where black is almost a standard now, I haven't had to think about formatting in a long time. I simply set my editor/IDE to auto-format on save and it always passes linting.

    I think I spent at least 15 minutes the other day manually fixing little things to make checkstyle happy; I would love to only have to think about the code and not formatting.

    Another interesting option is https://github.com/jhipster/prettier-java.

    I see that pre-commit is already part of the project and dev process. One potential way forward could be to enable pre-commit to do the java auto-formating only on changed files. The downside of this approach would be that PRs would be harder to look through until all files are re-formatted.

  3. lidavidm commented on Feb 27, 2023

    @lidavidm
    MemberAuthor

    Unfortunately, CI relies on archery (which will recheck every file), not pre-commit, so that's not quite an option

    prettier may be nice if we already use prettier elsewhere (I don't think we do), also not sure if it has integration with typical Java IDEs

    In any case any of {google-java-format, clang-format, prettier} would probably be better than checkstyle

  4. lidavidm commented on Feb 27, 2023

    @lidavidm
    MemberAuthor

    From a quick glance, I would probably feel most comfortable with google-java-format (all Java, maintained). prettier-java looks to have its own Java parser and I'm not sure how much clang-format's Java support is used (or if it'll keep up with Java syntax changes, not that we can use them for a while yet...)

  5. rtadepalli commented on Feb 28, 2023

    @rtadepalli
    Contributor

    Thoughts on using filter branch to apply formatting without losing git blame? There are a fair amount of commits, and it'd take a while to get through all of them...

  6. lidavidm commented on Feb 28, 2023

    @lidavidm
    MemberAuthor

    We can't rewrite history.

  7. lidavidm commented on Feb 28, 2023

    @lidavidm
    MemberAuthor

    We can use that feature for ignoring commits for blame.

  8. rtadepalli commented on Feb 28, 2023

    @rtadepalli
    Contributor

    Ah, completely forgot that filter branch rewrites history 🤦‍♂️

  9. transferred this issue fromapache/arrowon Nov 26, 2024
  10. lidavidm commented on Nov 28, 2024

    @lidavidm
    MemberAuthor

    We already integrated Spotless.

  11. added this to the 18.2.0 milestone on Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions