Skip to content

Commit

Permalink
Update: add support for JSXFragments in indent rule (fixes #12208) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo authored Sep 20, 2019
1 parent c6af95f commit d4f9a16
Show file tree
Hide file tree
Showing 2 changed files with 426 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const KNOWN_NODES = new Set([
"WhileStatement",
"WithStatement",
"YieldExpression",
"JSXFragment",
"JSXOpeningFragment",
"JSXClosingFragment",
"JSXIdentifier",
"JSXNamespacedName",
"JSXMemberExpression",
Expand Down Expand Up @@ -1453,6 +1456,31 @@ module.exports = {
offsets.setDesiredOffsets(node.name.range, firstToken, 1);
},

JSXFragment(node) {
const firstOpeningToken = sourceCode.getFirstToken(node.openingFragment);
const firstClosingToken = sourceCode.getFirstToken(node.closingFragment);

addElementListIndent(node.children, firstOpeningToken, firstClosingToken, 1);
},

JSXOpeningFragment(node) {
const firstToken = sourceCode.getFirstToken(node);
const closingToken = sourceCode.getLastToken(node);

offsets.setDesiredOffsets(node.range, firstToken, 1);
offsets.matchOffsetOf(firstToken, closingToken);
},

JSXClosingFragment(node) {
const firstToken = sourceCode.getFirstToken(node);
const slashToken = sourceCode.getLastToken(node, { skip: 1 });
const closingToken = sourceCode.getLastToken(node);
const tokenToMatch = astUtils.isTokenOnSameLine(slashToken, closingToken) ? slashToken : closingToken;

offsets.setDesiredOffsets(node.range, firstToken, 1);
offsets.matchOffsetOf(firstToken, tokenToMatch);
},

JSXExpressionContainer(node) {
const openingCurly = sourceCode.getFirstToken(node);
const closingCurly = sourceCode.getLastToken(node);
Expand Down
Loading

0 comments on commit d4f9a16

Please sign in to comment.