Ken Liu
Ken Liu

Reputation: 22914

How to generate an Eclipse formatter configuration from a checkstyle configuration?

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?

Upvotes: 47

Views: 32545

Answers (2)

Miguel Alorda
Miguel Alorda

Reputation: 692

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

Upvotes: 5

Paul
Paul

Reputation: 2338

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!

Upvotes: 80

Related Questions