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

Allow to disable rules globally #32

Closed
inikolaev opened this issue Feb 20, 2017 · 8 comments
Closed

Allow to disable rules globally #32

inikolaev opened this issue Feb 20, 2017 · 8 comments

Comments

@inikolaev
Copy link

I would like to have a command line parameter which would allow to disable certain rules so that I don't have to add comments to each file in a project.

Right now it looks like the only way to do that is to add a comment to each file where I need to disable a check, which is a bit intrusive I think.

One example is I would like to disable indentation rule, because I need it to behave differently in different contexts and ideally I would need to have different rules for different context which could be enabled/disabled.

@dstarcev
Copy link

I am not sure if it matches the project's ideology, which is against configuration. But if we finally decided to introduce configuration, I would recommend looking at how it is done in ESLint http://eslint.org/docs/user-guide/configuring and introducing .ktlintrc file.

@inikolaev
Copy link
Author

Personally I don't need a configuration right now, but rather a mechanism to disable certain rules globally and a finer-grained set of rules. Command-line parameter would be sufficient and I think it's a pretty good compromise.

A benefit of using a configuration is that it can be easily copied to a different project and you don't lock yourself to a particular library.

@shyiko
Copy link
Collaborator

shyiko commented Feb 20, 2017

@dstarcev is right, any form of configuration (cli parameter included) is against project's ideology. The reasons are the same as for standardjs - http://standardjs.com/#faq ("I disagree with rule X, can you change it?" section).

@inikolaev can you please elaborate which rules are giving you a hard time (and in what way)? What exactly do you mean by "I need it [indentation rule] to behave differently in different contexts"? If rule is misbehaving - it can always be fixed.

@inikolaev
Copy link
Author

Well one of my use cases is method/constructor parameter lists: when there's a long list of parameters we want to be able to write it in the following way:

data class A(val a: Any, 
             val b: Any, 
             val c: Any)

class B(val a: Any, 
        val b: Any, 
        val c: Any) {
}

fun doSomething(val a: Any, 
                val b: Any, 
                val c: Any) {
}

Right now I'm getting error:

Unexpected indentation

So if I understand correctly, this linter doesn't allow any kind of customisation by design?
Because now that would mean that the way I want to write my code is different from how you like to write it and what I consider misbehaviour is actually a feature.

@shyiko
Copy link
Collaborator

shyiko commented Feb 20, 2017

Take a look at #26 (comment) (the whole ticket is basically about the same thing) (related discussion - Kotlin/kotlin-style-guide#15).

Now, considering that this is not the first time this particular case is brought up and the fact that it creates way too much contention we might make an exception here and update IndentationRule.kt to allow vertical alignment of parameters. What do you think?

So if I understand correctly, this linter doesn't allow any kind of customisation by design?

Yes, this is intentional.

@inikolaev
Copy link
Author

Maybe if you stick to some particular way of vertical alignment you should provide a bit more detailed message about how it should be fixed.

Unexpected indentation is a bit too generic, I think it should be customized based on the context to give more hints about what is wrong.

@shyiko
Copy link
Collaborator

shyiko commented Feb 20, 2017

@inikolaev fair enough. I'll see what I can do. Thank you!

@shyiko
Copy link
Collaborator

shyiko commented Feb 21, 2017

@inikolaev I've added a little bit of context to the error messages, relaxed indent rule to accept both

fun f(
  val a: Any,
  val b: Any,
  val c: Any
) {
}

and

fun f(val a: Any,
      val b: Any,
      val c: Any) {
}

as valid and released ktlint@0.5.0 (here are the release notes).

Feel free to reopen the ticket if there is still a need for it.

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

3 participants