Reputation: 5250
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
Reputation: 1541
From 0.50.0 and on:
@file:Suppress("ktlint:standard:filename")
package foo
Docs:
https://pinterest.github.io/ktlint/1.1.1/rules/standard/#ktlint-suppression-rule
https://pinterest.github.io/ktlint/1.1.1/faq/#how-do-i-suppress-errors-for-a-lineblockfile
Upvotes: 2
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
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
andktlint_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
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
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