41

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?

Alex
  • 357
  • 1
  • 3
  • 16
Ken Liu
  • 21,834
  • 17
  • 74
  • 97
  • 1
    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 ;)) – 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 Answers2

75

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!

David X
  • 3,628
  • 3
  • 27
  • 32
Paul
  • 1,582
  • 1
  • 15
  • 24
  • 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
  • 1
    Looks 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
  • 2
    This 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
  • @Noumenon is there an alternative AFAYK? – Marco Bolis Apr 06 '21 at 08:07
  • @MarcoBolis I never found one and just ran it from the command line. – Noumenon Apr 06 '21 at 13:56
0

Here they say, that you can import a checkstyle configuration directly into the eclipse formatter. Didn't verify, but at least, it's a hint.

If the link doesn't work in your browser, please copy'n'paste this url: http://dbestudio.wiki.sourceforge.net/Code+Formatting+with+Checkstyle

Andreas Dolk
  • 111,016
  • 17
  • 174
  • 259