nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
158 stars 23 forks source link

The `.editorconfig` file seems to be ignored #565

Closed jdeebee closed 4 days ago

jdeebee commented 2 weeks ago

I'm using ktlint Gradle plugin and have configured some ktlint rules in my project's .editorconfig file. This is a multi-module Android project, and I have installed the latest version of Intellij/IDEA plugin (0.24.1) and configured it to use the manual mode so that it respects my project's rules in the .editorconfig file (which might be another issue by itself - I'd expect the distraction-free mode to also respect my configuration/rules). However, looks like I still get warnings (IDE highlights) for the rules I have disabled.

P.S: I have pinned the version of ktlint used by the Gradle plugin to ensure compatibility between the IDE plugin and the Gradle plugin. Here's the relevant part of my root project's build script:

allprojects {
    apply(plugin = "org.jlleitschuh.gradle.ktlint")

    configure<KtlintExtension> {
        // By default, the ktlint gradle plugin uses an old version of ktlint (currently 1.0.1)
        // Also, the used ktlint version may change between versions of this plugin
        // We pin the version to have predictable builds
        // See https://github.com/JLLeitschuh/ktlint-gradle/?tab=readme-ov-file#configuration
        version.set("1.3.1")

        ktlint {
            debug = true
            ignoreFailures = false
            android = true
            outputToConsole = true

            reporters {
                reporter(ReporterType.CHECKSTYLE)
            }
            filter {
                exclude { file ->
                    val exclude =
                        excludedDirs.any {
                            file.file.toString().contains(it)
                        }
                    if (exclude) {
                        println("EXCLUDING ${file.file}")
                    }
                    exclude
                }
            }
        }
     }

And my project's .editorconfig:

# Top-most EditorConfig file
root = true

# Config for all file types
[*]
max_line_length = 120
trim_trailing_whitespace = true
insert_final_newline = false
indent_style = space
indent_size = 4
ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^

[*.{kt,kts}]
ktlint_standard_annotation = disabled
no-empty-first-line-in-method-block = disabled
ktlint_no-wildcard-imports = enabled
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_naming_ignore_annotation_pattern = Composable
ktlint_standard_package-name = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_string-template-indent = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_no-empty-first-line-in-method-block = disabled
ktlint_standard-trailing-comma-on-call-site = disabled
ktlint_standard-trailing-comma-on-declaration-site = disabled
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 2

[**/test/**.kt]
kotlin_imports_layout = android.*, |, ^org.junit.*, kotlin.io.Closeable, |, *, ^*
kotlin_line_comment_add_space = false
max_line_length = off

[**/androidTest/**.kt]
kotlin_imports_layout = android.*, |, ^org.junit.*, kotlin.io.Closeable, |, *, ^*
kotlin_line_comment_add_space = false
max_line_length = off

[*.yml]
indent_size = 2

I wonder if I'm missing something or is this an actual bug. Thank you very much for looking into this potential issue. Appreciate it.

jdeebee commented 2 weeks ago

I accidentally noticed something. I get the warnings when I have a class with a custom annotation, as soon as I remove the annotation, the warnings are gone and my .editorconfig seems to be respected.

paul-dingemans commented 2 weeks ago

Please provide an example that reproduces the problem. Both the Gradle Plugin and Ktlint Intellij plugin use the same rulesets when you have pinned them. It can however be that they use different versions of the KtlintRuleEngine. Typically this should not result in different results, but it might happen in a very specific situation. If you provide an example, I will check.

paul-dingemans commented 4 days ago

Closed due to lack of response.