-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto-arranging code to satisfy CheckStyle DeclarationOrder #4908
Comments
According to the Checkstyle Documentation for the
The Google Java Style Guide for instance states the following:
@keturn From what I've seen (please correct me if you've seen this differently), I don't think we have a lot of possibilities to configure this differently on checkstyle side. We could try to configure the code style on intellij-level via the |
Thanks for finding the reference for the ordering! I have nothing more to add at this time; this particular aspect of configuration is not one I've worked with. |
Okay, then as long as we can agree on that it makes more sense to adjust the intellij side rather than the checkstyle side, I'll try to figure out how we can do exactly that 🙂 |
Actually I just noted that IntelliJ tricked a Your example: private final Set<String> dependencies = Sets.newHashSet("engine");
private String worldGeneratorUri = "moduletestingenvironment:dummy";
private boolean doneLoading;
PathManager pathManager;
PathManagerProvider.Cleaner pathManagerCleaner; First execution of "Reformat Code": private final Set<String> dependencies = Sets.newHashSet("engine");
PathManager pathManager;
PathManagerProvider.Cleaner pathManagerCleaner;
private String worldGeneratorUri = "moduletestingenvironment:dummy";
private boolean doneLoading; which is still correct but immediately followed by IntelliJ adding the final keyword for worldGeneratorUri: private final Set<String> dependencies = Sets.newHashSet("engine");
PathManager pathManager;
PathManagerProvider.Cleaner pathManagerCleaner;
private final String worldGeneratorUri = "moduletestingenvironment:dummy";
private boolean doneLoading; Which is why the second execution of "Reformat Code" has something new to reformat into: private final Set<String> dependencies = Sets.newHashSet("engine");
private final String worldGeneratorUri = "moduletestingenvironment:dummy";
PathManager pathManager;
PathManagerProvider.Cleaner pathManagerCleaner;
private boolean doneLoading; Which should be correct for both IntelliJ Code Style configuration and CheckStyle 🤔 |
class C {
private final Set<String> a;
public Set<String> b;
} is well-ordered according to IJ, because CheckStyle complains because that is a |
When CheckStyle complains “Variable access definition in wrong order
[DeclarationOrder]
,” it's not clear how to satisfy it, and IntelliJ's Reformat Code action is not always sufficient.Update either the IntelliJ code style definition or the CheckStyle rules so the two match.
For IntelliJ IDEA, see https://www.jetbrains.com/help/idea/2021.2/code-style-java.html#arrangement_tab
See also: discussion thread
How to reproduce
This is a sample of a class with a bunch of field types, extracted from ModuleTestingEnvironment:
CheckStyle complains about where
pathManager
is placed here, as a package-private non-static field. Reformat Code does move those lines, but CheckStyle is still not content with the result.The text was updated successfully, but these errors were encountered: