I am trying to setup my .editorconfig and it seems it silently ignores some internal errors and it makes the .editorconfig hard to debug.
# http://editorconfig.org
droot = true
[*]
indent_style = space
indent_size = 4
end_of_line = lff
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{kt,kts}]
disabled_rules = disabled_rules = no-wildcard-imports,import-ordering,no-consecutive-blank-lines,colon-spacing,curly-spacing,range-spacing,no-var,dump,chain-wrapping,comment-spacing,filename,final-newline,indent,max-line-length,modifier-order,no-blank-line-before-rbrace,no-line-break-after-else,no-line-break-before-assignment,no-semi,no-trailing-spaces,parameter-list-wrapping,colon-spacing,comma-spacing,curly-spacing,op-spacing
For instance, see the invalid end_of_line parameter - IntelliJ will highlight the incorrectness, but ktlint just skips it. Also for some reason, the disabled_rules is also ignored with no error as I keep getting:
/src/main/kotlin/net/goout/geoipinfo/GeoIpInfo.kt:10:1: Wildcard import (cannot be auto-corrected)
Also changing the root = true to invalid droot = true has no effect and yields not even a warning.
On the other hand, changing indent_size to 5 correctly yields (meaning the file is correctly loaded):
src/main/kotlin/net/goout/geoipinfo/Geoipinfo.kt:52:1: Unexpected indentation (4) (it should be 5) (cannot be auto-corrected)
Using --debug doesn't help much, it just says:
[DEBUG] Discovered .editorconfig (/Users/knyttlwork/Workspace/GoOut/GeoIpInfo) {charset=utf-8, end_of_line=lff, indent_size=4, indent_style=space, insert_final_newline=true, tab_width=4, trim_trailing_whitespace=true}
[DEBUG] Discovered .editorconfig (/Users/knyttlwork/Workspace/GoOut/GeoIpInfo) {charset=utf-8, end_of_line=lff, indent_size=4, indent_style=space, insert_final_newline=true, tab_width=4, trim_trailing_whitespace=true}
(why does the message appear twice?)
But it doesn't complain about anything invalid.
Version:
$ ktlint --version
0.36.0
Note that in case of the
disabled_rules = no-wildcard-imports,import-ordering,no-consecutive-blank-lines,colon-spacing,curly-spacing,range-spacing,no-var,dump,chain-wrapping,comment-spacing,filename,final-newline,indent,max-line-length,modifier-order,no-blank-line-before-rbrace,no-line-break-after-else,no-line-break-before-assignment,no-semi,no-trailing-spaces,parameter-list-wrapping,colon-spacing,comma-spacing,curly-spacing,op-spacing
The problem is that it exceed the limit of .editorconfig format of 255 characters for the property value. When the limit is exceeded the key-value pair is silently ignored. This behaviour is baked into the ec4j library which ktlint uses for parsing .editorconfig files.
I filed an issue in the editorcofig githug. Anyway this probably won't get fixed anytime soon.
Sounds like maybe the limit will get increased.
But it not flagging the invalid end_of_line parameter is certainly a bug. I'd expect it to, at minimum, spit a warning.
it does not report any warning, not only end_of_line
But it not flagging the invalid end_of_line parameter is certainly a bug. I'd expect it to, at minimum, spit a warning.
Per the official spec this is not a bug but a feature:
EditorConfig plugins shall ignore unrecognized keys and invalid/unsupported values for those keys.
I also filled an issue for that in the editorconfig repo.
As a temporarily workaround I would propose to throw an error when some value in .editorconfig has over 255 characters.
ec4j 3.0 was just released. It removes the limit on value length. Updating to that version should fix this issue.
Here's a PR for upgrading ec4j: https://github.com/pinterest/ktlint/pull/1042