Skip to content
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

Custom gradle tasks with custom ruleset results in warning #1269

Closed
ibevilinc opened this issue Nov 3, 2021 · 2 comments · Fixed by #1279
Closed

Custom gradle tasks with custom ruleset results in warning #1269

ibevilinc opened this issue Nov 3, 2021 · 2 comments · Fixed by #1279
Labels

Comments

@ibevilinc
Copy link

Running ktlint in gradle with a custom task (ie no plugin) AND a custom rule set results in the following warning:
[WARNING] Number of custom rule sets loaded does not match the expected number of rule sets to be loaded.
Expected to load 0 custom rule set(s) for rules:
Actually loaded 1 custom rule set(s) with names: XXXX
One or more of the specified jars does not provide the custom rule set correctly. Check following:
- Does the jar contain an implementation of the RuleSetProvider interface?
- Does the jar contain a resource file with name "com.pinterest.ktlint.core.RuleSetProvider"?
- Is the resource file located in directory "src/main/resources/META-INF/services"?
- Does the resource file contain the fully qualified class name of the class implementing the RuleSetProvider interface?

Expected Behavior

Loading custom rule sets should NOT result in a warning unless the custom rules failed to meet the other rules.

Observed Behavior

Custom rules are loaded and executed, just an invalid warning is being displayed.

Steps to Reproduce

Load custom rule set using:

val ktlint by configurations.creating

dependencies {
    ktlint("com.pinterest:ktlint:0.43.0") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
        }
    }
    ktlint(project(":custom-ktlint-ruleset"))
}

Your Environment

  • Version of ktlint used: 0.43.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): custom gradle tasks
  • Version of Gradle used (if applicable): 7.2
  • Operating System and version: OSX 12.0.1
  • Link to your project (if it's a public repository): n/a

Additional Notes

This did not occur in 0.42.1 or earlier versions. Looking through the new RuleSetLoader, it appears the bug is being caused because the expected number of custom rulesets is being counted from the number of --ruleset parameters but the custom gradle tasks provides them via the classpath so the actual vs expected count doesn't get calculated correctly.

@paul-dingemans
Copy link
Collaborator

This did not occur in 0.42.1 or earlier versions. Looking through the new RuleSetLoader, it appears the bug is being caused because the expected number of custom rulesets is being counted from the number of --ruleset parameters but the custom gradle tasks provides them via the classpath so the actual vs expected count doesn't get calculated correctly.

This is indeed new functionality. Tnx for your analysis. It sounds like a plausible cause.

Custom rules are loaded and executed, just an invalid warning is being displayed.

As you already noted yourself: the warning does not affect the execution of the rule.

@shashachu shashachu added the bug label Nov 4, 2021
paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue Nov 6, 2021
Check JAR files one by one whether a custom rule set has been provided and print warning when it is missing.

Closes pinterest#1269
paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue Nov 6, 2021
@akuleshov7
Copy link
Contributor

Oh, we also faced it. But looks like it does not affect anything, just a warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants