nebula-plugins / gradle-lint-plugin

A pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts.
Apache License 2.0
761 stars 88 forks source link

Is there any way to create a custom rules for 'gradle-lint-plugin' and add them to the classpath? #371

Open dgroup opened 2 years ago

dgroup commented 2 years ago

Hi, In this article https://github.com/nebula-plugins/gradle-lint-plugin/wiki/Writing-A-Rule there is an instruction on how to create a rule. In case if I want to implement several rules for my own team, how can I use them within gradle-lint-plugin?

For example, Gradle PMD plugin supports dependency section (with dependency scope=pmd) that allows connecting other rules implemented outside the PMD team https://docs.gradle.org/current/userguide/pmd_plugin.html#sec:pmd_dependency_management

apply plugin: 'pmd'

dependencies {
   ...
   pmd "io.github.dgroup:arch4u-pmd:${version}"    // use latest arch4u-pmd rules version
   ...
}

pmd {
   consoleOutput = true
   ruleSetFiles = files("io/github/dgroup/arch4u/pmd/arch4u-ruleset.xml")
   ...
}
exaucae commented 10 months ago

Did you land somewhere with this, @dgroup? I asked a similar question in #395 before seeing yours.

dgroup commented 10 months ago

@exaucae, I made a fork with several rules and applied them to my projects directly.

exaucae commented 10 months ago

Thank you!

exaucae commented 10 months ago

this line could be the one to change if we want to feed custom rules to the plugin: https://github.com/nebula-plugins/gradle-lint-plugin/blob/280804cbbdcce703284921b34fe8719a0a84f661/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy#L33

The classloader is used by the LintRuleRegistry to get rulesets: https://github.com/nebula-plugins/gradle-lint-plugin/blob/main/src/main/groovy/com/netflix/nebula/lint/plugin/LintRuleRegistry.groovy#L27-L31