Morozov
Morozov

Reputation: 5250

How to disable filename in ktlint?

How and where i can to disable filename in ktlint?

I don t want to rename this class, but get next error:

interface MainActivityContract should be declared in a file named MainActivityContract.kt (cannot be auto-corrected)

Upvotes: 9

Views: 9027

Answers (5)

Aks4125
Aks4125

Reputation: 5720

If you are using ktlint gradle then you can exclude using filename.

ktlint {
filter {
    exclude("**/generated/**")
    exclude("DateSanitizer.kt") // Replace your file name here
    include("**/kotlin/**")
}}

works with

    id("org.jlleitschuh.gradle.ktlint") version "11.6.0" apply false

Upvotes: 0

Tomasz Dzieniak
Tomasz Dzieniak

Reputation: 2915

Here is an update for those using ktlint version 0.49.0 (or newer).

The ktlint_disabled_rules are no longer supported as it's stated in the changelog:

Note that properties disabled_rules and ktlint_disabled_rules have been removed in this release.

That being said, the correct approach is now to use the filename-associated standard rule.

Add to the .editorconfig:

ktlint_standard_filename = disabled

Upvotes: 2

Zakhar Rodionov
Zakhar Rodionov

Reputation: 1493

Create in main folder file .editorconfig.
Add

ktlint_disabled_rules=filename

Full file for example:

root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

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

[*.{yml,yaml}]
indent_size = 2

Upvotes: 0

Morozov
Morozov

Reputation: 5250

Just added at the top of the file:

// ktlint-disable filename

Note: This works for ktlint version 0.24.0 and above.

Upvotes: 14

Related Questions