Skip to content

Commit

Permalink
feat(indent-binary-ops): disabled to lower indent when starts closing…
Browse files Browse the repository at this point in the history
… bracket (#591)
  • Loading branch information
k35o authored Nov 1, 2024
1 parent 6000f43 commit 25fe554
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,34 @@ it('snapshots', async () => {
|| (g && h)
}"
`)

expect.soft(
fix($`
type Type =
| ({
type: 'a';
} & A)
| ({
type: 'b';
} & B)
| ({
type: 'c';
} & {
c: string;
});
`),
).toMatchInlineSnapshot(`
"type Type =
| ({
type: 'a';
} & A)
| ({
type: 'b';
} & B)
| ({
type: 'c';
} & {
c: string;
});"
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ export default createRule<RuleOptions, MessageIds>({
return openBracketCount < closeBracketCount
}

function hasExclusivelyCloseBracketOfLine(line: number) {
return !sourceCode.tokensAndComments.some(token => token.loc.start.line === line && ![')', '}', ']'].includes(token.value))
}

function handler(node: ASTNode, right: ASTNode) {
if (node.loc.start.line === node.loc.end.line)
return
Expand Down Expand Up @@ -128,7 +124,7 @@ export default createRule<RuleOptions, MessageIds>({
|| (
lastTokenOfLineLeft?.value === ')'
&& isGreaterThanCloseBracketOfLine(tokenLeft.loc.start.line)
&& !hasExclusivelyCloseBracketOfLine(tokenLeft.loc.start.line)
&& ![']', ')', '}'].includes(firstTokenOfLineLeft?.value || '')
)

const indentLeft = getIndentOfLine(tokenLeft.loc.start.line)
Expand Down

0 comments on commit 25fe554

Please # to comment.