Skip to content

Commit

Permalink
feat: fix handling of blockless with statements in indent rule (#16068
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mdjermanovic authored Jul 2, 2022
1 parent fc81848 commit 472c368
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ module.exports = {
}
},

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

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

if (node.type === "IfStatement") {
Expand Down
51 changes: 51 additions & 0 deletions tests/lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,21 @@ ruleTester.run("indent", rule, {
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
with (a)
b();
`,
options: [4]
},
{
code: unIndent`
with (a)
b();
c();
`,
options: [4]
},
{
code: unIndent`
if(true)
Expand Down Expand Up @@ -6322,6 +6337,14 @@ ruleTester.run("indent", rule, {
`,
options: [4]
},
{
code: unIndent`
with (a)
console.log(b)
;[1, 2, 3].forEach(x=>console.log(x))
`,
options: [4]
},
{
code: unIndent`
label: for (a of b)
Expand Down Expand Up @@ -6955,6 +6978,20 @@ ruleTester.run("indent", rule, {
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
with(a)
b();
`,
output: unIndent`
with(a)
b();
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
if(true)
Expand Down Expand Up @@ -13301,6 +13338,20 @@ ruleTester.run("indent", rule, {
options: [4],
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
with (a)
console.log(b)
;[1, 2, 3].forEach(x=>console.log(x))
`,
output: unIndent`
with (a)
console.log(b)
;[1, 2, 3].forEach(x=>console.log(x))
`,
options: [4],
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
label: for (a of b)
Expand Down

0 comments on commit 472c368

Please sign in to comment.