-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Rule Proposal: matched-token-indentation #9123
Comments
Since ESLint 4.0.0, the |
I think the @EthanRutherford Would #8102 address this, in combination with the |
Here are some examples of what I would consider "correct" code with this rule, if it helps: // example 2 corrected
foo(someArray.map(() => {
// some code here
}));
// example 2 corrected alternative
foo(someArray.map(
() => {
// some code here
})
);
// example 3 corrected
foo([
// some values here
])
// example 3 corrected alternative
foo(
[
// some values here
]
) I'll take a look at #8102 and see if that does what I'm looking for. EDIT: looks like it wouldn't quite solve the problem, and moreover would be imposing a different constraint that is tangent to the above issue. This rule would ensure that the indentation level is always equal on the first line of the expression/block and the last line of the expression/block. It's not interested in whether or not each token gets its own line, just so long as they return to their "home" indentation level at the end. (note the two possible "correct" configurations) |
Another, less immediately obvious way to see this rule is that if the first line has, say, 3 parens in it, then the last line must have all three matching parens. (in fact, that gives me a better idea for the rule name: "delimiter-symmetry") // correct
foo(bar(baz(
// some args
)))
// incorrect
foo(bar(baz(
/* some args */)
)) |
Could you give an example of code that would be considered correct by |
code that is invalid under foo(bar(baz(
1,
2,
3,
))); it is my understanding that this would be invalid, as the "multiline" rule would state that, since the content between the parens is multiline, each paren must have a newline. like so: foo(
bar(
baz(
1,
2,
3,
)
)
); code that is valid under const foo = (
5); this example is pretty simple: because it's not a function paren, I will admit, If my understanding about how |
Sorry, I should have clarified -- I was referring to the |
Oh, I see the |
I would also propose an |
I'll go ahead and close this issue. |
Please describe what the rule should do:
This rule would warn when a closing brace/bracket/paren is on a line with a different indent level than the matching opening token.
What category of rule is this? (place an "X" next to just one item)
[x] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
Matching the indentation level of two matched tokens can improve readability of source code. When opening and closing tokens are at the same indent level, it becomes visually much easier to detect where a section of code (i.e. function parameters, a function body, an array, an object literal, etc.) begins and ends. When the indent level does not match, one has to read through line by line to try and manually match an opening token with its closing token, which can get very difficult quite easily in a language like javascript, where nesting can potentially get very deep.
The text was updated successfully, but these errors were encountered: