-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Fix] jsx-indent
: Does not check indents for JSXText
#2542
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great!
lib/rules/jsx-indent.js
Outdated
* @param {RegExp} regex | ||
* @returns {Array} | ||
*/ | ||
function matchAll(str, regex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no need to hardcode this when https://npmjs.com/string.prototype.matchall exists; please use that instead.
lib/rules/jsx-indent.js
Outdated
const matches = matchAll(value, regExp); | ||
matches.forEach((match) => { | ||
if (match[1]) { | ||
nodeIndentsPerLine.push(match[1].length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole body can then be replaced with:
return match[1] ? match[1].length : 0;
0076cb0
to
0264f6a
Compare
@ljharb but, CI is failed... What do you think about supporting the |
eebc0bd
to
137abcd
Compare
@toshi-toma is there no way to identify text inside JSX in eslint < 5? It seems pretty likely that there is something, it's just got a different node type. |
In older eslint (and current babel-eslint), the node type of text inside JSX is |
@ljharb |
f13e0df
to
8b89f61
Compare
8b89f61
to
ffdf69a
Compare
Fixes #2467, Fixes #2484, Fixes #1136
This PR fixes the problem of does not check
jsx-indent
forJSXText
.JSXText
Node is different from other formats.e.g. The following code.
JSXText
's node.value returns\n text\n text\n
.changes
add handler for JSXText Node
https://github.com/yannickcr/eslint-plugin-react/blob/0076cb09abfed7a3777102359efb5f39dee2e01e/lib/rules/jsx-indent.js#L406-L412
check JSXText Indent
https://github.com/yannickcr/eslint-plugin-react/blob/0076cb09abfed7a3777102359efb5f39dee2e01e/lib/rules/jsx-indent.js#L304-L341
add the fix for JSXText
https://github.com/yannickcr/eslint-plugin-react/blob/0076cb09abfed7a3777102359efb5f39dee2e01e/lib/rules/jsx-indent.js#L100-L104
add test cases
tests/lib/rules/jsx-indent.js