Skip to content

Commit 7f2740e

Browse files
authored
fix(indent-binary-ops): handle { for left token check (#693)
1 parent b239b71 commit 7f2740e

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎packages/eslint-plugin/rules/indent-binary-ops/indent-binary-ops._plus_.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ run({
111111
|| c
112112
|| d;
113113
`,
114+
$`
115+
{ aaaaa &&
116+
bbbbb &&
117+
ccccc }
118+
`,
119+
$`
120+
{
121+
aaaaa &&
122+
bbbbb &&
123+
ccccc
124+
}
125+
`,
126+
$`
127+
if (condition1 &&
128+
condition2 &&
129+
condition3
130+
) {
131+
a &&
132+
b() &&
133+
c()
134+
}
135+
`,
114136
],
115137
invalid: [],
116138
})
@@ -580,4 +602,17 @@ it('snapshots', async () => {
580602
|| 2
581603
|| 3;"
582604
`)
605+
606+
expect.soft(
607+
fix($`
608+
{ aaaaa &&
609+
bbbbb &&
610+
ccccc }
611+
`),
612+
).toMatchInlineSnapshot(`
613+
"{ aaaaa &&
614+
bbbbb &&
615+
ccccc }"
616+
`,
617+
)
583618
})

‎packages/eslint-plugin/rules/indent-binary-ops/indent-binary-ops._plus_.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ export default createRule<RuleOptions, MessageIds>({
135135
// End of line is a opening bracket (`[`, `(`),
136136
// or the expression is an assignment
137137
|| [':', '[', '(', '<'].concat(ASSIGNMENT_OPERATOR).includes(lastTokenOfLineLeft?.value || '')
138-
// Before the left token is a opening bracket (`[`, `(`),
138+
// Before the left token is a opening bracket (`[`, `(`, `{`),
139139
// or the expression is an assignment
140-
|| (['[', '(', '=>', ':'].concat(ASSIGNMENT_OPERATOR).includes(tokenBeforeAll?.value || '') && firstTokenOfLineLeft?.loc.start.line === tokenBeforeAll?.loc.start.line)
140+
|| (['[', '(', '{', '=>', ':'].concat(ASSIGNMENT_OPERATOR).includes(tokenBeforeAll?.value || '') && firstTokenOfLineLeft?.loc.start.line === tokenBeforeAll?.loc.start.line)
141141

142142
const needSubtractionIndent = false
143143
// End of line is a closing bracket

0 commit comments

Comments
 (0)