Is there an Eclipse "Clean Up" profile that matches the Checkstyle format rules?

StackOverflow https://stackoverflow.com/questions/21211586

  •  29-09-2022
  •  | 
  •  

Domanda

I installed the Checkstyle plugin and selected the Sun Checks configuration as the Default.

After running "Check code with Checkstyle", I have hundreds of Checkstyle violations across dozens of classes. Many of these violations are formatting related: particularly whitespace

Although I haven't used it yet, I think the Eclipse "Clean Up" tool can be run on a project to address some of these issues. The Clean Up tool comes with a profile named "Eclipse [built-in]". The default settings don't look to match the Checkstyle formatting rules.

Other than creating a new Clean Up profile and manually tweaking it to match the Checkstyle rules and because Eclipse allows you to import a Clean Up profile, I'm wondering:

Does there already exist a Clean Up profile xml that matches the Checkstyle rules?

It would be great if I could just import it from somewhere. I tried the Google but had no luck finding one.

Eclipse v4.3 (kepler)
Checkstyle Plug-in v5.6.1.201306282206

È stato utile?

Soluzione

Yeah, I ran into this issue when started using SonarQube

There are two xml rules, one for formatter and one for source clean-up. You can import at Eclipse and IntelliJ IDEA (using a plugin)

It worked for me, as it reduced my issues at this 70k LOC project :

+-----------------+--------+-------+
|                 | Before | After |
+-----------------+--------+-------+
| Issues          | 4.306  | 2.977 |
| Blocker issues  | 0      | 0     |
| Critical issues | 257    | 257   |
| Major issues    | 2.402  | 1.994 |
| Minor issues    | 1.642  | 721   |
| Info issues     | 5      | 5     |
+-----------------+--------+-------+

Here are the formatter.xml and cleanup.xml rules. Credit goes to this github repo and it's authors.

Blog post automating such task on Eclipse here. It states a important caveat

Not everything can be automated

Please note that although a lot of coding standards can be applied retroactively and automatically, some violations cannot be automatically eradicated. Nonetheless, Checkstyle, Eclipse and Sonar can identify the problematic code and guide developers towards coding standard compliance.

Yes, I'm aware you're using only Checkstyle, but I'm sure it applies, since SonarQube uses Checkstyle to raise it's issues.

Altri suggerimenti

I do not know of a way to do that using the Cleanup feature, but eclipse-cs (the Eclipse Checkstyle plugin) offers Eclipse Quick Fixes for many Checkstyle findings. You can have it run all applicable by selecting Apply Checkstyle fixes from the right-click context menu.

Screenshots here. Hope this helps!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top