Skip to content

Commit 472c368

Browse files
authored
feat: fix handling of blockless with statements in indent rule (#16068)
1 parent fc81848 commit 472c368

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/rules/indent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ module.exports = {
12111211
}
12121212
},
12131213

1214-
"DoWhileStatement, WhileStatement, ForInStatement, ForOfStatement": node => addBlocklessNodeIndent(node.body),
1214+
"DoWhileStatement, WhileStatement, ForInStatement, ForOfStatement, WithStatement": node => addBlocklessNodeIndent(node.body),
12151215

12161216
ExportNamedDeclaration(node) {
12171217
if (node.declaration === null) {
@@ -1268,7 +1268,7 @@ module.exports = {
12681268
*
12691269
* Traversal into the node sets indentation of the semicolon, so we need to override it on exit.
12701270
*/
1271-
":matches(DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, IfStatement, WhileStatement):exit"(node) {
1271+
":matches(DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, IfStatement, WhileStatement, WithStatement):exit"(node) {
12721272
let nodesToCheck;
12731273

12741274
if (node.type === "IfStatement") {

tests/lib/rules/indent.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,21 @@ ruleTester.run("indent", rule, {
776776
`,
777777
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
778778
},
779+
{
780+
code: unIndent`
781+
with (a)
782+
b();
783+
`,
784+
options: [4]
785+
},
786+
{
787+
code: unIndent`
788+
with (a)
789+
b();
790+
c();
791+
`,
792+
options: [4]
793+
},
779794
{
780795
code: unIndent`
781796
if(true)
@@ -6322,6 +6337,14 @@ ruleTester.run("indent", rule, {
63226337
`,
63236338
options: [4]
63246339
},
6340+
{
6341+
code: unIndent`
6342+
with (a)
6343+
console.log(b)
6344+
;[1, 2, 3].forEach(x=>console.log(x))
6345+
`,
6346+
options: [4]
6347+
},
63256348
{
63266349
code: unIndent`
63276350
label: for (a of b)
@@ -6955,6 +6978,20 @@ ruleTester.run("indent", rule, {
69556978
[2, 4, 0, "Identifier"]
69566979
])
69576980
},
6981+
{
6982+
code: unIndent`
6983+
with(a)
6984+
b();
6985+
`,
6986+
output: unIndent`
6987+
with(a)
6988+
b();
6989+
`,
6990+
options: [4],
6991+
errors: expectedErrors([
6992+
[2, 4, 0, "Identifier"]
6993+
])
6994+
},
69586995
{
69596996
code: unIndent`
69606997
if(true)
@@ -13301,6 +13338,20 @@ ruleTester.run("indent", rule, {
1330113338
options: [4],
1330213339
errors: expectedErrors([3, 0, 4, "Punctuator"])
1330313340
},
13341+
{
13342+
code: unIndent`
13343+
with (a)
13344+
console.log(b)
13345+
;[1, 2, 3].forEach(x=>console.log(x))
13346+
`,
13347+
output: unIndent`
13348+
with (a)
13349+
console.log(b)
13350+
;[1, 2, 3].forEach(x=>console.log(x))
13351+
`,
13352+
options: [4],
13353+
errors: expectedErrors([3, 0, 4, "Punctuator"])
13354+
},
1330413355
{
1330513356
code: unIndent`
1330613357
label: for (a of b)

0 commit comments

Comments
 (0)