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

Unable to disable ktlint rule #476

Closed
szpak opened this issue Oct 18, 2019 · 9 comments
Closed

Unable to disable ktlint rule #476

szpak opened this issue Oct 18, 2019 · 9 comments
Labels

Comments

@szpak
Copy link

szpak commented Oct 18, 2019

I'm new to spotless and I might miss something. However, I'm not able to disable a specific ktlint rule.

//    id("com.diffplug.gradle.spotless") version "3.24.2"

spotless {
    kotlin {
        ktlint().userData(mapOf("disabled_rules" to "comment-spacing"))
    }
}

regarding to this and that, "comment-spacing" should be disabled globally. However, I still as the following error:

$ gw spotlessCheck
> Task :spotlessKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spotlessKotlin'.
> The following files had format violations:
      src/compatTest/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPluginTests.kt
          @@ -48,7 +48,7 @@
           import·java.nio.file.Files
           import·java.nio.file.Path
           
          -@Suppress("FunctionName")·//TODO:·How·to·suppress·"kotlin:S100"·from·SonarLint?
          +@Suppress("FunctionName")·//·TODO:·How·to·suppress·"kotlin:S100"·from·SonarLint?
           @ExtendWith(WiremockResolver::class)
           class·NexusPublishPluginTests·{
           
  Run 'gradlew spotlessApply' to fix these violations.

which suggests that rule is still taken into account.

What have I missed? How to effectively disable ktlint rule for the whole project?

@saschpe
Copy link

saschpe commented Oct 25, 2019

I don't think such a disable rule exist. The mechanism in Spotless works in general though:

spotless {
    kotlin {
        target("*/src/**/*.kt")
        ktlint("0.35.0").userData(mapOf("disabled_rules" to "no-wildcard-imports"))
    }
}

@szpak
Copy link
Author

szpak commented Nov 5, 2019

Thanks for your reply. It caused that I tried to use never spotless plugin and with 3.25.0 my construction works out of the box. It seems that "something" has been fixed/implemented in the meantime.

@szpak szpak closed this as completed Nov 5, 2019
szpak added a commit to gradle-nexus/publish-plugin that referenced this issue Nov 5, 2019
See: diffplug/spotless#476
As a side effect import-ordering has been disabled to do not break the build.
It changed to fail after upgrade. I don't want to mix that PR with global
import reordering.
@sp00ne
Copy link

sp00ne commented May 27, 2020

Spotless still ignores disabled rules

[*.{kt,kts,xml}]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,kts}]
max_line_length = 165
disabled_rules = import-ordering

This configuration still causes it to nitpick on import ordering

@nedtwigg
Copy link
Member

@sp00ne it's the difference between .editorconfig versus passing explicitly through Spotless using ktlint("0.35.0").userData(

@sp00ne
Copy link

sp00ne commented May 28, 2020

I see, but shouldn't it honor the .editorconfig anyhow? 🤔 This feels highly cumbersome. Especially with sending a version name, feels like it is in a high risk zone of getting outdated upon a version bump. Or am I missing something?

@nedtwigg
Copy link
Member

The version is optional, if you leave it off you get the latest, I was just copying example above. We don’t support editorconfig, the issue which outlines how to add support for it is #162. If you pass the contents of editorconfig as userData, that will work, but it is errorprone. Would def be great if we supported editorconfig, would love to merge a PR for it!

@jbduncan
Copy link
Member

We don’t support editorconfig, the issue which outlines how to add support for it is #162.

@nedtwigg Did you mean to refer to #142, by any chance? :)

@alixwar
Copy link

alixwar commented Jun 29, 2023

This works for me:

        kotlin {
            ktlint()
                .editorConfigOverride(
                    mapOf(
                        "ktlint_standard_no-wildcard-imports" to "disabled",
                    ),
                )
        }

@mhmd-android
Copy link

thank you @alixwar, "editorConfigOverride" that's worked for me

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

No branches or pull requests

7 participants