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

Suggestion for indent rule #26

Open
Avaq opened this issue Jun 21, 2019 · 5 comments
Open

Suggestion for indent rule #26

Avaq opened this issue Jun 21, 2019 · 5 comments

Comments

@Avaq
Copy link
Member

Avaq commented Jun 21, 2019

We recently started using add (21) (21) style call expressions at work, and I came up with the following indent rule to facilitate it:

{"indent": ["error", 2, {
  "ignoredNodes": ["CallExpression[callee.type='CallExpression']"]
}]}

The magic is in the ignoreNodes rule. It says that any CallExpression calling another CallExpression doesn't need to follow indentation rules.

There are many other directives that can be added to the indent rule options to further customize the rules, but they are not relevant to this example.

@davidchambers
Copy link
Member

Excellent! Could you provide an example of “incorrectly” indented code that this change would permit?

@Avaq
Copy link
Member Author

Avaq commented Jun 21, 2019

add (21)
    (21)

The second call expression has a "callee" which is also a call expression, therefore the indentation rule is ignored there.

@davidchambers
Copy link
Member

Perfect. Would you like to submit a pull request?

@Avaq
Copy link
Member Author

Avaq commented Jun 21, 2019

I don't mind doing it, but I don't have time for it now. I will definitely get to it some day, though. :)

However, seeing as we'll have to reach an agreement on the other directives: https://eslint.org/docs/rules/indent#options, and as you probably already have opinions on those, it might be faster for you to come up with the rules yourself. You can simply add the ignoredNodes thing from my suggestion to suppress the error that made you disable indent rules in the first place.

@davidchambers
Copy link
Member

Sanctuary actually specifies a custom indent rule which contains several exceptions. If you remove an exception from the list then run npm run lint, you will see why the exception is necessary.

Do you still think this is worth undertaking, or is the solution too inelegant and potentially unreliable?

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

2 participants