How can I easily fix Checkstyle errors?

前端 未结 6 2311
失恋的感觉
失恋的感觉 2020-12-14 16:40

Is there a way to have an IDE fix Checkstyle errors automatically without having to fix each manually?

6条回答
  •  情话喂你
    2020-12-14 17:35

    There is a way to do this every time you save your file but not all warnings in Checkstyle can be fixed automatically.

    You can have Checkstyle generate a formatter for you by right clicking on your package in the Package/Project explorer and selecting Checkstyle->Create Formatter-Profile. This will create a new formatter called eclipse-cs [your-package-name] based off of your Checkstyle configuration. You'll find it in the "Active profile" drop-down in the formatter preferences of Eclipse.

    You can then set the formatter to run each save by going to Preferences->[Language of Choice]->Editor->Save Actions. Check the "Perform the selected actions on save" and "Format source code" boxes.

提交回复
热议问题