How to generate an Eclipse formatter configuration from a checkstyle configuration?
Asked Answered
N

2

47

I have a checkstyle configuration XML file and want to automatically generate an Eclipse formatter configuration from this. Is there any tool that can do this?

Neukam answered 12/6, 2009 at 2:50 Comment(3)
Dear Ken, some of us think you really should accept the above answer as the best (not sure that Paul is running after the Unsung hero's badge ;))Nervous
@Jean-RémyRevy done, thanks for the ping!Neukam
@Jean-RémyRevy It's good that the answer was accepted, but unsung hero would be for users that have accepted answers with 0 votes, rather than lots of votes without being accepted. (Just trying to save others from having to search what unsung hero badge means)Mccabe
U
80

In Eclipse (3.6):

  • Install Checkstyle plug-in
  • Import stylesheet using Windows --> Preferences, General --> Checkstyle --> New. Since you have an external file, choose "external file" as the type.

Right-click on your project in the Package view and select Checkstyle --> Create Formatter-Profile.

Then enable the formatter for your workspace: Windows --> Preferences --> Java --> Code Style --> Formatter. Select formatter: "eclipse-cs [project name]".

Click OK!

Upholsterer answered 12/3, 2012 at 11:3 Comment(5)
which file should I import into the Eclipse check-style plug-in for the Google Java style - google-styleguide.googlecode.com/svn/trunk? I tried styleguide.css, but that failed.Bolt
Looks like it depends on the programming language: C++ Java You need an XML file in any case, not a CSS.Upholsterer
This feature is broken and the Eclipse plugin authors said in March 2019 that they were planning to remove it. https://mcmap.net/q/331924/-problem-with-checkstyle-creating-formatter-profileSmoothbore
@Smoothbore is there an alternative AFAYK?Islam
@MarcoBolis I never found one and just ran it from the command line.Smoothbore
N
5

The answer currently marked as accepted does not work as is with Eclipse 2022-06 and Checkstyle Plug-in 10.0.0. These are the steps that worked for me:

  1. Install Checkstyle plug-in

  2. Import Checkstyle configuration: Windows -> Preferences -> Checkstyle -> New. Choose "external file" as the type.

  3. Right-click on your project in the Package view and select Checkstyle -> Create Formatter-Profile. The following files will be created in you project:

  • my-project-cs-cleanup.xml
  • my-project-cs-formatter.xml
  1. Add the generated my-project-cs-formatter.xml as a formatter: Windows -> Preferences -> Java -> Code Style -> Formatter -> Import
Naomanaomi answered 2/9, 2022 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.