-
Notifications
You must be signed in to change notification settings - Fork 519
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
Select code repository
Activity
paul-dingemans commentedon Jul 21, 2022
The logging above is indeed inccorrect.
Whenever the
--editorconfigoption is used, all.editorconfigfiles 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.editorconfigfile is found on the file path. Is the setting from the specified.editorconfigfile 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.
NyanSten commentedon Jul 21, 2022
That is fine, I expected that.
The problem is with path-based rules in the provided EditorConfig. If the EditorConfig looks like this:
Then when it is found by directory traversal, both
max_line_lengthanddisabled_rulesrules are applied toapp/src/main/kotlin/com/example/Example1.kt, but when it is specified via the--editorconfigoption, only themax_line_lengthrule is applied because the rewritten file name does not match the latter section.paul-dingemans commentedon Jul 25, 2022
Tnx for this clarification. That indeed sounds like a bug.
Improve support of default editorconfig properties
Improve support of default editorconfig properties (#1580)