diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 56eccdeb6e7..b974a6ab150 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -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) { @@ -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") { diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 4d7d6104663..0785083d0ac 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -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) @@ -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) @@ -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) @@ -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)