Ktlint: FilenameRule does not find lint errors if missing editorconfig (new in 0.40.0)

Created on 7 Dec 2020  路  3Comments  路  Source: pinterest/ktlint

Expected Behavior

The filename rule should produce a lint error when the kotlin source file name does not match the symbol declared whether or not an editorconfig is present or if it is missing path section which includes the offending file.

Observed Behavior

Starting in 0.40.0 it does not find this error.
However 0.39.0 does under the same circumstances.

Steps to Reproduce

Create file src/main/kotlin/Wrong.kt

class Right

(no editorconfig)
ktlint src/main/kotlin/Wrong.kt and it does not find any errors

with editorconfig

[*.{kt,kts}]
indent_size = 4

a lint error will be found

src/main/kotlin/Wrong.kt:1:1: class Right should be declared in a file named Right.kt (cannot be auto-corrected)

If you again change the editorconfig file to the below, the lint error will disappear again

[src/test/**/*.{kt,kts}]
indent_size = 4

Your Environment

  • MacOS
  • ktlint 0.40.0
  • Java 11
bug

Most helpful comment

Found the issue, will fix for the next release.

All 3 comments

We also faced this, @romtsn @Tapchicoma, but it looks to be an expected behavior.
May be we will add default values for editor config to workaround it?

Interestingly "filename" rule does not use .editorconfig, but I can reproduce this issue. Will check what is the cause.

Found the issue, will fix for the next release.

Was this page helpful?
0 / 5 - 0 ratings