Skip to content

Wrong file path resolved when using --editorconfig #1551

@NyanSten

Description

@NyanSten

When using --editorconfig option, a wrong path will be resolved.

Without --editorconfig:

12:13:49.290 [pool-1-thread-1] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for app/src/main/kotlin/com/example/Example1.kt file path:
12:13:49.290 [pool-1-thread-2] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for app/src/main/kotlin/com/example/Example2.kt file path:

With --editorconfig=/tmp/editorconfig:

12:15:04.346 [pool-1-thread-2] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for /tmp/editorconfig/Example1.kt file path:                                                                                                                                                                                                                                                   
12:15:04.348 [pool-1-thread-1] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for /tmp/editorconfig/Example2.kt file path:

Notice that the file's director name has been replaced with the editorconfig path. Path-specific rules for e.g. [**/example/*.kt] won't be applied.

Activity

paul-dingemans

paul-dingemans commented on Jul 21, 2022

@paul-dingemans
Collaborator

With --editorconfig=/tmp/editorconfig:

12:15:04.346 [pool-1-thread-2] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for /tmp/editorconfig/Example1.kt file path:                                                                                                                                                                                                                                                   
12:15:04.348 [pool-1-thread-1] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for /tmp/editorconfig/Example2.kt file path:

The logging above is indeed inccorrect.

Path-specific rules for e.g. [**/example/*.kt] won't be applied.

Whenever the --editorconfig option is used, all .editorconfig files on the file path are ignored. I expect that this was a consicious design choice but it has not been documented (or at least I can not find it). Suppose that an .editorconfig file is found on the file path. Is the setting from the specified .editorconfig file more or less import than from the file found on the file path? I expect that this differs per user.

But the least that could be done, is to mention the current behavior in the CLI help.

added this to the 0.47.0 milestone on Jul 21, 2022
NyanSten

NyanSten commented on Jul 21, 2022

@NyanSten
Author

Whenever the --editorconfig option is used, all .editorconfig files on the file path are ignored. I expect that this was a consicious design choice but it has not been documented (or at least I can not find it). Suppose that an .editorconfig file is found on the file path. Is the setting from the specified .editorconfig file more or less import than from the file found on the file path? I expect that this differs per user.

That is fine, I expected that.

The problem is with path-based rules in the provided EditorConfig. If the EditorConfig looks like this:

[*.{kt,kts}]
max_line_length = 140

[app/**/example/*.kt]
disabled_rules = filename

Then when it is found by directory traversal, both max_line_length and disabled_rules rules are applied to app/src/main/kotlin/com/example/Example1.kt, but when it is specified via the --editorconfig option, only the max_line_length rule is applied because the rewritten file name does not match the latter section.

paul-dingemans

paul-dingemans commented on Jul 25, 2022

@paul-dingemans
Collaborator

Tnx for this clarification. That indeed sounds like a bug.

added a commit that references this issue on Aug 13, 2022
54f8194
added a commit that references this issue on Aug 18, 2022
3c6eaca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @NyanSten@paul-dingemans

      Issue actions

        Wrong file path resolved when using --editorconfig · Issue #1551 · pinterest/ktlint