checkstyle-idea icon indicating copy to clipboard operation
checkstyle-idea copied to clipboard

Module specific suppression file not working

Open Avinm opened this issue 2 years ago • 1 comments

I have a checkstyle rule file with the following config for suppressions:

    <module name="SuppressionFilter">
        <property name="file" value="${checkstyle.suppression.filter}" default="checkstyle-suppressions.xml" />
    </module>

I have imported this rule to checkstyle-idea and provided the value checkstyle-suppressions.xml for the variable checkstyle.suppression.filter when importing.

The documentation says that the plugin will look for the file checkstyle-suppressions.xml in module root directory. However, in a project with multiple modules say M1, M2, M3, the plugin always uses M1/checkstyle-suppressions.xml for running inspections on all 3 modules.

Would it be possible to improve this behavior so that inspection in M2 use M2/checkstyle-suppressions.xml and those in M3 use M3/checkstyle-suppressions.xml and so on?

Avinm avatar Oct 06 '21 21:10 Avinm

It's a perfectly reasonable request, and indeed it is how the feature is intended to work. So there's two options: a) it's a bug, or b) it's realted to the horror that is ProjectUtil.guessModuleDir. To quote the IDEA docs:

Returns some directory which is located near module files.

There is no such thing as "base directory" for a module in IntelliJ project model.
A module may have multiple content roots, or not have content roots at all. The
module configuration file (.iml) may be located far away from the module files or
doesn't exist at all. So this method tries to suggest some directory which is related
to the module but due to its heuristics nature its result shouldn't be used for real
actions as is, user should be able to review and change it. For example it can be
used as a default selection in a file chooser.

Back when the feature was added, modules did have a base dir, but Jetbrains have decided to move away from that, bless them.

I've had a look and the logic does look sensible - we get the module for the current file, and then try the content roots, and then to guess the module dir. So my suspicion does tend towards (b), which would be a right pain. In any case I'll try to take a second look later when I'm fresh, and see if I'm missing something.

jshiell avatar Oct 27 '21 13:10 jshiell