Skip to content
Permalink
Browse files

Update: add support for JSXFragments in indent rule (fixes #12208) (#…

  • Loading branch information
kaicataldo committed Sep 20, 2019
1 parent c6af95f commit d4f9a16af7e00021e2ed63823d9c2f149bc985d6
Showing with 426 additions and 0 deletions.
  1. +28 −0 lib/rules/indent.js
  2. +398 −0 tests/lib/rules/indent.js
@@ -81,6 +81,9 @@ const KNOWN_NODES = new Set([
"WhileStatement",
"WithStatement",
"YieldExpression",
"JSXFragment",
"JSXOpeningFragment",
"JSXClosingFragment",
"JSXIdentifier",
"JSXNamespacedName",
"JSXMemberExpression",
@@ -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);

0 comments on commit d4f9a16

Please sign in to comment.
You can’t perform that action at this time.