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

Unable to disable "filename" rule #237

Closed
ssoloff opened this issue Jun 21, 2018 · 11 comments
Closed

Unable to disable "filename" rule #237

ssoloff opened this issue Jun 21, 2018 · 11 comments

Comments

@ssoloff
Copy link

ssoloff commented Jun 21, 2018

I have a couple of files on which I'd like to temporarily disable the recently-added filename rule. An example of such a rule violation in my project follows:

<snip>/GameSpecificationSpec.kt:1:1: object GameSpecificationBehavesAsDataClassSpec should be declared in a file named GameSpecificationBehavesAsDataClassSpec.kt (filename)

However, I can't seem to get ktlint to honor my ktlint-disable directive for this rule. Since ktlint reports the violation at row 1, column 1, I tried placing both of the following directives on the first line of the file in question:

// ktlint-disable filename

and

// ktlint-disable

Unfortunately, neither had any effect with respect to the filename rule, and the violation was still reported. Am I missing something obvious about how to disable this rule?

I'm wondering if, because FilenameRule applies to the root node of the AST, it's simply running before any suppression directives are encountered in the remainder of the AST? In which case, is there some other syntax one can use to disable such a "root" rule?

@ssoloff ssoloff changed the title Unable to disable "filename" rule Unable to suppress "filename" rule Jun 21, 2018
@ssoloff ssoloff changed the title Unable to suppress "filename" rule Unable to disable "filename" rule Jun 21, 2018
@shyiko
Copy link
Collaborator

shyiko commented Jun 21, 2018

Confirmed and thank you for the ticket. I'll have a fix ready within 24h.

@shyiko
Copy link
Collaborator

shyiko commented Jun 23, 2018

0.24.0 released 🎈.
// ktlint-disable filename at the top of the file should work now.

@ssoloff
Copy link
Author

ssoloff commented Jun 23, 2018

Confirmed. Thanks, @shyiko!

@mnewlive
Copy link

mnewlive commented Aug 7, 2019

0.24.0 released .
// ktlint-disable filename at the top of the file should work now.

Are there any other options? Since I have in each class there is an annotation that should be at the top, but if I write below it but above the package name, the command doesn't work.

@Tapchicoma
Copy link
Collaborator

@mnewlive You can add .editorconfig with following content:

[*.{kt,kts}]
disabled_rules=filename

@mnewlive
Copy link

mnewlive commented Aug 9, 2019

@mnewlive You can add .editorconfig with following content:

[*.{kt,kts}]
disabled_rules=filename

using this method I can disable the rule for all classes,
but how can I disable the rule for only one class for example?

@Tapchicoma
Copy link
Collaborator

// ktlint-disable filename at the top of the file should work now.

@mnewlive just to confirm - you want to disable this rule for a specific folder?

@mnewlive
Copy link

mnewlive commented Aug 9, 2019

// ktlint-disable filename at the top of the file should work now.

@mnewlive just to confirm - you want to disable this rule for a specific folder?

for a specific class/classes

@Tapchicoma
Copy link
Collaborator

then you could modify .editorconfig to following content:

[src/main/kotlin/**/*Interface.kt]
disabled-rules=filename

For more info how to use .editorconfig you could check https://editorconfig.org/

@mnewlive
Copy link

then you could modify .editorconfig to following content:

[src/main/kotlin/**/*Interface.kt]
disabled-rules=filename

For more info how to use .editorconfig you could check https://editorconfig.org/

I tried to write smth like this:

# http://editorconfig.org
root = true

[src/main/java/com/mandarine/targetList/interfaces/OnBackPressListenerEEE.kt]
disabled-rules = filename

But also get error for my class:

/home/vadimm/AndroidStudioProjects/target-list/app/src/main/java/com/mandarine/targetList/interfaces/OnBackPressListenerEEE.kt:1:1: interface OnBackPressListener should be declared in a file named OnBackPressListener.kt (cannot be auto-corrected)

@Tapchicoma
Copy link
Collaborator

@mnewlive you should remove spaces in assignments, see #555

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

4 participants