Skip to content

Commit

Permalink
fix(jsx-indent): conflict between indent and jsx-indent (#368)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <github@antfu.me>
  • Loading branch information
Daydreamer-riri and antfu committed Apr 29, 2024
1 parent c329a86 commit 7313184
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/eslint-plugin-jsx/rules/jsx-indent/jsx-indent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,36 @@ const Component = () => (
`,
options: [2],
},
{
options: [2, { checkAttributes: true, indentLogicalExpressions: true }],
code: `
<>
<div
foo={
condition
? [
'bar'
]
: [
'baz',
'qux'
]
}
/>
<div
style={
true
? {
color: 'red',
}
: {
height: 1,
}
}
/>
</>
`,
},
),

invalid: invalids(
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin-jsx/rules/jsx-indent/jsx-indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ export default createRule<MessageIds, RuleOptions>({
const nameIndent = getNodeIndent(node.name)
const lastToken = context.sourceCode.getLastToken(node.value)!
const firstInLine = getFirstNodeInLine(context, lastToken)
// leave this for `indent` rule to handle
if (firstInLine.loc.start.line !== lastToken.loc.start.line)
return
const indent = node.name.loc.start.line === firstInLine.loc.start.line ? 0 : nameIndent
checkNodesIndent(firstInLine as unknown as ASTNode, indent)
}
Expand Down

0 comments on commit 7313184

Please sign in to comment.