-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
indent rule's ignoredNodes not respected when multiline #9882
indent rule's ignoredNodes not respected when multiline #9882
Comments
I dug into the source code a little on this one already. It seems, to my untrained eye, that the crux of the matter is this line: Line 954 in 9cbb487
This line checks the token corresponding to the node about to be ignored, finds the token upon which its indentation is based, and ensures it's outside the current node before ignoring it. In this scenario, I want to ignore indentation around |
I think this is happening because JSX indentation currently works in two phases:
|
Hm, interesting. That implied to my mind that I could add
Which is the wrong direction, but better matches the original scenario of using Airbnb's recommended set of ignoredNodes: https://github.com/airbnb/javascript/blob/53b2d7d245ba4abefc0429bfda4a46f099b9ace5/packages/eslint-config-airbnb-base/rules/style.js#L141 If I copy paste theirs (with changing 2 spaces to 4) in a new config: Configurationmodule.exports = {
parser: 'babel-eslint',
rules: {
// this option sets a specific tab width for your code
// https://eslint.org/docs/rules/indent
indent: ['error', 4, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1
},
FunctionExpression: {
parameters: 1,
body: 1
},
CallExpression: {
arguments: 1
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: ['JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'],
ignoreComments: false
}],
},
}; It results in:
(exactly the same error as originally) So it's a less simple scenario than my original bug report, but this is actually what I care about fixing given the project I'm working in is based on Airbnb's config. I'm not sure how this impacts your analysis, given that we can assume |
@airbnb is having this same problem; when |
I know this is ancillary to the issue, but is this something that should be changed? Should we only ignore the first token of the node after |
I think the current behavior is that it ignores the first token after Removing the "ignores logical operators" behavior is tracked in #8978. |
Reading this issue; I'm still not sure what code change would be needed to fix it :-/ certainly the Perhaps the |
If my explanation in #9882 (comment) was correct, then I think the solution would be to update the |
This seems to resolve the originally-posted issue, provided that diff --git a/lib/rules/indent.js b/lib/rules/indent.js
index 79a0f25c..acc52463 100644
--- a/lib/rules/indent.js
+++ b/lib/rules/indent.js
@@ -1043,7 +1043,6 @@ module.exports = {
offsets.ignoreToken(operator);
offsets.ignoreToken(tokenAfterOperator);
offsets.setDesiredOffset(tokenAfterOperator, operator, 0);
- offsets.setDesiredOffsets([tokenAfterOperator.range[1], node.range[1]], tokenAfterOperator, 1);
},
"BlockStatement, ClassBody"(node) {
@ljharb You mentioned that you're also having this same problem. Have you encountered it in any situations which don't involve a (If you have a codebase with a lot of errors from this issue, one fast way to check could be to temporarily apply that diff and see if any errors remain.) |
That’s the only scenario I’ve seen it in, but i can’t really survey 10k+ files :-) I’ll try it locally as well. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
No error.
What actually happened? Please include the actual, raw output from ESLint.
The text was updated successfully, but these errors were encountered: