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?
Asked
Active
Viewed 3.0k times
44
-
1Dear 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 ;)) – Jean-Rémy Revy Jan 04 '16 at 14:58
-
1@Jean-RémyRevy done, thanks for the ping! – Ken Liu Jan 05 '16 at 17:16
-
@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) – Vivek Chavda Aug 02 '17 at 13:22
2 Answers
76
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!
-
which file should I import into the Eclipse check-style plug-in for the Google Java style - http://google-styleguide.googlecode.com/svn/trunk/? I tried `styleguide.css`, but that failed. – Kevin Meredith Feb 26 '14 at 14:49
-
1Looks like it depends on the programming language: [C++](http://google-styleguide.googlecode.com/svn/trunk/eclipse-cpp-google-style.xml) [Java](http://google-styleguide.googlecode.com/svn/trunk/eclipse-java-google-style.xml) You need an XML file in any case, not a CSS. – Paul Feb 27 '14 at 20:46
-
2This feature is broken and the Eclipse plugin authors said in March 2019 that they were planning to remove it. https://stackoverflow.com/a/55323793/733092 – Noumenon Dec 10 '19 at 23:20
-
-
1
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:
Install Checkstyle plug-in
Import Checkstyle configuration:
Windows -> Preferences -> Checkstyle -> New
. Choose "external file" as the type.Right-click on your project in the
Package view
and selectCheckstyle -> Create Formatter-Profile
. The following files will be created in you project:
my-project-cs-cleanup.xml
my-project-cs-formatter.xml
- Add the generated
my-project-cs-formatter.xml
as a formatter:Windows -> Preferences -> Java -> Code Style -> Formatter -> Import

Miguel Alorda
- 623
- 5
- 13