Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The maximum line length of 120 has been exceeded. The rule cannot be modified or disabled. #1496

Closed
Turalllb opened this issue Jun 15, 2022 · 24 comments

Comments

@Turalllb
Copy link

Turalllb commented Jun 15, 2022

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

image

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

image

version 10.3.0
@paul-dingemans
Copy link
Collaborator

Please update to latest version of ktlint (0.45.2) first and report back if the problem still occurs.

@Turalllb
Copy link
Author

@paul-dingemans Updated the version and edited the question. The problem persists. I seem to be doing something wrong

@Turalllb
Copy link
Author

I tried to specify the full path to the .editorConfig file, but it did not help

@paul-dingemans
Copy link
Collaborator

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}].

@paul-dingemans
Copy link
Collaborator

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

@Turalllb
Copy link
Author

@paul-dingemans
image

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.

@paul-dingemans
Copy link
Collaborator

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.

@Turalllb
Copy link
Author

Turalllb commented Jun 16, 2022

@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.

@Turalllb
Copy link
Author

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

@paul-dingemans
Copy link
Collaborator

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:

  1. The max line length is not checked for lines that only contain an EOL comment like your //disabledRules.set(...)
  2. In your example, an additional .editorconfig files seems to be provided via additionalEditorconfigFile.set(file("/my_project/.editorconfig")). Assuming that the gradle plugin passes this file to ktlint then all other .editorconfig files are ignored.
  3. 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).

@sanyarnd
Copy link

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.

@paul-dingemans
Copy link
Collaborator

@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).

@sanyarnd
Copy link

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)

@paul-dingemans
Copy link
Collaborator

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).

@sanyarnd
Copy link

Tested 0.47.0 and error is gone now

@paul-dingemans
Copy link
Collaborator

Tested 0.47.0 and error is gone now

Ok, tnx for confirming.

@logi-nilsson
Copy link

@Turalllb This is a little late but it seems like "max_line_length" should be "max-line-length" instead?

@paul-dingemans
Copy link
Collaborator

@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 #1974, ktlint should give a more clear warning.

@Kashif-E
Copy link

Kashif-E commented May 5, 2023

funny enough max_line_length is actually max-line-length

@paul-dingemans
Copy link
Collaborator

funny enough max_line_length is actually max-line-length

I am not sure what you mean. Do you care to explain?

@mchelombitkopax8
Copy link

@Kashif-E kashif mamba jumba, do you damn care to explain?

@Kashif-E
Copy link

@mchelombitkopax8 the keyword is not max_line_length_ but max-line-length

@logi-nilsson
Copy link

logi-nilsson commented Aug 1, 2024

@mchelombitkopax8 You can try suppressing both rules @Suppress("max_line_length", "max-line-length").

@paul-dingemans
Copy link
Collaborator

The proper way to suppress this rule is:

@Suppress("ktlint:standard:max-line-length")

But of course this only works for violations created by this rule specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants