ktlint
ktlint copied to clipboard
The maximum line length of 120 has been exceeded. The rule cannot be modified or disabled.
ktlint { version.set("0.45.2") android.set(true) additionalEditorconfigFile.set(file("/my-android/.editorconfig")) disabledRules.set(Set.of("max_line_length", "import-ordering", "no-wildcard-imports", "final-newline", "missing-newline-after", "no-unused-imports", "indent")) } }
![image](https://user-images.githubusercontent.com/28982210/174074597-79d08592-f8d6-4116-86d8-a3a7ab551119.png)
![image](https://user-images.githubusercontent.com/28982210/174074542-0e573770-4b9e-41f7-bfa5-8745ca4836e7.png)
Result: Exceeded max line length (100) (cannot be auto-corrected)
With these settings, I keep getting an error about exceeding 100 characters. What could I set up wrong, why is everything so not obvious (
Also tell me, is it possible to disable the rule that prohibits putting a comma at the end of the enumeration, for example, in the class constructor after the very last argument? I would like to be able to put a comma, ide allows me to do this, but ktlint does not
![image](https://user-images.githubusercontent.com/28982210/174075521-5eb58e8d-b107-4348-b795-18420c119d46.png)
![image](https://user-images.githubusercontent.com/28982210/174075704-4b17e08e-c333-47f6-a015-852326e9c7dd.png)
Please update to latest version of ktlint (0.45.2) first and report back if the problem still occurs.
@paul-dingemans Updated the version and edited the question. The problem persists. I seem to be doing something wrong
I tried to specify the full path to the .editorConfig file, but it did not help
Based on your last screendump, I get the feeling that you only epxerience the problem with ktolin script (*.kts) files. That is caused by the space before *.kts
in the .editorconfig
file. Change it to:
[{*.kt,*.kts}]
.
Also tell me, is it possible to disable the rule that prohibits putting a comma at the end of the enumeration, for example, in the class constructor after the very last argument? I would like to be able to put a comma, ide allows me to do this, but ktlint does not
Please read documentation. https://github.com/pinterest/ktlint#trailing-comma
@paul-dingemans
I was already happy, but deleting this space didn’t help either. (I even deleted everything else and left it as on the screen, but that doesn’t help either. I cleared the cache in android studio, all to no avail.
In screenshot above you have set max_line_length=off
so that might be the cause. Also, you need to explcitily save
the .editorconfig
file as changes otherwise are not picked up by IntelliJ IDEA.
If error still occurs then please paste the source code instead of only providing a screenshot.
@paul-dingemans
[*.{kt,kts}]
max_line_length=105
indent_size=4
insert_final_newline=false
disabled_rules=max_line_length
ktlint {
version.set("0.45.2")
android.set(true)
additionalEditorconfigFile.set(file("/my_project/.editorconfig"))
//disabledRules.set(Set.of("max_line_length", "import-ordering", "final-newline", "missing-newline-after", "no-unused-imports", "indent"))
}
Here are my settings. In the logs, I get a message about exceeding 100 characters, although I set 105 for the experiment. It is noteworthy that I commented out the android.set(true) line and I picked up the setting about 105 characters, but I returned this setting again, and then turned it off again and that's it .. I can no longer come to this state and did not understand what affected it. I also did not understand what you said about the fact that ide does not save changes. I tried turning "enable editorConfig support" off and on thinking I could get it to save the settings, but alas.
it is also not clear where it is better to write disabled_rules in gradle or in .editorConfig and which entry has a higher priority
The ktlint gradle plugin is maintained in another project, so I can not be 100% sure what is happening. From the perspective of Ktlint, I can say that:
- The max line length is not checked for lines that only contain an EOL comment like your //disabledRules.set(...)
- In your example, an additional
.editorconfig
files seems to be provided viaadditionalEditorconfigFile.set(file("/my_project/.editorconfig"))
. Assuming that the gradle plugin passes this file toktlint
then all other.editorconfig
files are ignored. - If the API consumer of ktlint, e.g. the gradle plugin, is calling ktlint correctly then it can override properties which are specified in the .editorconfig file. This override the setting provided via
.editorconfig
files (including the additional file mentioned in previous step).
I can confirm that the check cannot be disabled.
I think there's something wrong with editorconfig inheritance, for example, if I put max_line_length=off
in [*]
everything works.
But if I put max_line_length=off
in [**/test/**.kt]
-- it doesn't work. Same goes for [*.kt]
as well.
Looks like ktlint respects only root-level declaration.
@sanyarnd I am happy to look into this, if you can document the full reproduction path including sources to be used, commands being executed and output (using option --verbose
).
sample project ktlint-max-length-bug.zip
.editorconfig
:
root = true
[*]
max_line_length = 120
[{*.kt, *.kts}]
max_line_length = 80
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
[**/test/**.kt]
max_line_length = off
ktlint_ignore_back_ticked_identifier = true
mvn package
output:
[ERROR] src\main\kotlin\LongLineClass.kt:2:1: Exceeded max line length (80)
[ERROR] src\test\kotlin\LongLineTest.kt:2:1: Exceeded max line length (80)
I can not reproduce the problem with your sample project. What OS are you running on? Based on the backslashed in the path, it looks like Windows.
When I run command: ktlint --trace --relative
11:31:46.237 [pool-1-thread-2] TRACE com.pinterest.ktlint.KtlintCommandLine - Checking src/main/kotlin/LongLineClass.kt
11:31:46.237 [pool-1-thread-1] TRACE com.pinterest.ktlint.KtlintCommandLine - Checking src/test/kotlin/LongLineTest.kt
11:31:46.753 [pool-1-thread-1] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for ./src/test/kotlin/LongLineTest.kt file path:
max_line_length: off, ij_kotlin_code_style_defaults: KOTLIN_OFFICIAL, ktlint_ignore_back_ticked_identifier: true
11:31:46.753 [pool-1-thread-2] TRACE com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for ./src/main/kotlin/LongLineClass.kt file path:
max_line_length: 80, ij_kotlin_code_style_defaults: KOTLIN_OFFICIAL
Please send your complete output of command ktlint --trace --relative
for further analysis.
Please also note that the "space" in [{*.kt, *.kts}]
does not result in what you might expect (the settings would only be on kts-files for which the filename actually starts with a space).
Tested 0.47.0 and error is gone now
Tested 0.47.0 and error is gone now
Ok, tnx for confirming.
@Turalllb This is a little late but it seems like "max_line_length"
should be "max-line-length"
instead?
@Turalllb This is a little late but it seems like
"max_line_length"
should be"max-line-length"
instead?
Funny, just a couple of day there was another issue in which the same problem occurred. As I suggested in https://github.com/pinterest/ktlint/issues/1974, ktlint should give a more clear warning.
funny enough max_line_length
is actually max-line-length
funny enough
max_line_length
is actuallymax-line-length
I am not sure what you mean. Do you care to explain?