From f3843a05b654ceeb7b8c73e163951a24ff20338e Mon Sep 17 00:00:00 2001 From: Anix Date: Sun, 17 May 2020 12:25:32 +0000 Subject: [PATCH 1/5] Update: changed loc for extra (refs #12334) --- lib/rules/block-spacing.js | 21 +- tests/lib/rules/block-spacing.js | 374 ++++++++++++++++++++++++++++--- 2 files changed, 356 insertions(+), 39 deletions(-) diff --git a/lib/rules/block-spacing.js b/lib/rules/block-spacing.js index c6ed44a2798..96012eda324 100644 --- a/lib/rules/block-spacing.js +++ b/lib/rules/block-spacing.js @@ -102,9 +102,18 @@ module.exports = { // Check. if (!isValid(openBrace, firstToken)) { + let loc = openBrace.loc.start; + + if (messageId === "extra") { + loc = { + start: openBrace.loc.end, + end: firstToken.loc.start + }; + } + context.report({ node, - loc: openBrace.loc.start, + loc, messageId, data: { location: "after", @@ -120,9 +129,17 @@ module.exports = { }); } if (!isValid(lastToken, closeBrace)) { + let loc = closeBrace.loc.start; + + if (messageId === "extra") { + loc = { + start: lastToken.loc.end, + end: closeBrace.loc.start + }; + } context.report({ node, - loc: closeBrace.loc.start, + loc, messageId, data: { location: "before", diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 95d9d8cc089..e0861c1f532 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -240,8 +240,24 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 2, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 3 + }, + { + type: "BlockStatement", + line: 1, + column: 9, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 10 + } ] }, { @@ -249,7 +265,18 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } } + { + type: "BlockStatement", + line: 1, + column: 2, + messageId: "extra", + data: { + location: "after", + token: "{" + }, + endLine: 1, + endColumn: 3 + } ] }, { @@ -257,7 +284,18 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 9, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 8, + messageId: "extra", + data: { + location: "before", + token: "}" + }, + endLine: 1, + endColumn: 9 + } ] }, { @@ -265,7 +303,18 @@ ruleTester.run("block-spacing", rule, { output: "{\nfoo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 2, column: 8, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 2, + column: 7, + messageId: "extra", + data: { + location: "before", + token: "}" + }, + endLine: 2, + endColumn: 8 + } ] }, { @@ -273,7 +322,18 @@ ruleTester.run("block-spacing", rule, { output: "{foo();\n}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } } + { + type: "BlockStatement", + line: 1, + column: 2, + messageId: "extra", + data: { + location: "after", + token: "{" + }, + endLine: 1, + endColumn: 3 + } ] }, { @@ -281,8 +341,24 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 9, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 10 + }, + { + type: "BlockStatement", + line: 1, + column: 16, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 17 + } ] }, { @@ -290,8 +366,24 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {} else {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 17, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 18 + }, + { + type: "BlockStatement", + line: 1, + column: 24, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 25 + } ] }, { @@ -299,8 +391,24 @@ ruleTester.run("block-spacing", rule, { output: "switch (a) {case 0: foo();}", options: ["never"], errors: [ - { type: "SwitchStatement", line: 1, column: 12, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "SwitchStatement", line: 1, column: 29, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "SwitchStatement", + line: 1, + column: 13, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 14 + }, + { + type: "SwitchStatement", + line: 1, + column: 28, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 29 + } ] }, { @@ -308,8 +416,24 @@ ruleTester.run("block-spacing", rule, { output: "while (a) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 11, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 20, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 12, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 13 + }, + { + type: "BlockStatement", + line: 1, + column: 19, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 20 + } ] }, { @@ -317,8 +441,24 @@ ruleTester.run("block-spacing", rule, { output: "do {foo();} while (a);", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 4, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 5, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 6 + }, + { + type: "BlockStatement", + line: 1, + column: 12, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 13 + } ] }, { @@ -326,8 +466,24 @@ ruleTester.run("block-spacing", rule, { output: "for (;;) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 19, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 11, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 12 + }, + { + type: "BlockStatement", + line: 1, + column: 18, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 19 + } ] }, { @@ -335,8 +491,24 @@ ruleTester.run("block-spacing", rule, { output: "for (var a in b) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 19, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 20 + }, + { + type: "BlockStatement", + line: 1, + column: 26, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 27 + } ] }, { @@ -345,8 +517,24 @@ ruleTester.run("block-spacing", rule, { options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 19, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 20 + }, + { + type: "BlockStatement", + line: 1, + column: 26, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 27 + } ] }, { @@ -354,12 +542,60 @@ ruleTester.run("block-spacing", rule, { output: "try {foo();} catch (e) {foo();} finally {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 5, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 14, messageId: "extra", data: { location: "before", token: "}" } }, - { type: "BlockStatement", line: 1, column: 26, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 35, messageId: "extra", data: { location: "before", token: "}" } }, - { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 54, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 6, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 7 + }, + { + type: "BlockStatement", + line: 1, + column: 13, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 14 + }, + { + type: "BlockStatement", + line: 1, + column: 27, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 28 + }, + { + type: "BlockStatement", + line: 1, + column: 34, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 35 + }, + { + type: "BlockStatement", + line: 1, + column: 46, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 47 + }, + { + type: "BlockStatement", + line: 1, + column: 53, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 54 + } ] }, { @@ -367,8 +603,24 @@ ruleTester.run("block-spacing", rule, { output: "function foo() {bar();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 17, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 18 + }, + { + type: "BlockStatement", + line: 1, + column: 24, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 25 + } ] }, { @@ -376,8 +628,24 @@ ruleTester.run("block-spacing", rule, { output: "(function() {bar();});", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 22, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 14, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 15 + }, + { + type: "BlockStatement", + line: 1, + column: 21, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 22 + } ] }, { @@ -386,8 +654,24 @@ ruleTester.run("block-spacing", rule, { options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 9, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 10 + }, + { + type: "BlockStatement", + line: 1, + column: 16, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 17 + } ] }, { @@ -395,9 +679,25 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + line: 1, + column: 9, + messageId: "extra", + data: { location: "after", token: "{" }, + endLine: 1, + endColumn: 10 + }, + { + type: "BlockStatement", + line: 1, + column: 44, + messageId: "extra", + data: { location: "before", token: "}" }, + endLine: 1, + endColumn: 45 + } ] - } + }, ] }); From bf49a7727df975bd5a6aeb05ba44a4330599893f Mon Sep 17 00:00:00 2001 From: Anix Date: Sun, 17 May 2020 12:48:11 +0000 Subject: [PATCH 2/5] Chore: linting fixes --- tests/lib/rules/block-spacing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index e0861c1f532..ec582c33294 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -698,6 +698,6 @@ ruleTester.run("block-spacing", rule, { endColumn: 45 } ] - }, + } ] }); From 056cfcfa3a4768563989d1e861ef88e6d2fefd81 Mon Sep 17 00:00:00 2001 From: Anix Date: Mon, 18 May 2020 12:15:18 +0000 Subject: [PATCH 3/5] Update: loc reporting for missing case --- lib/rules/block-spacing.js | 4 +- tests/lib/rules/block-spacing.js | 355 +++++++++++++++++++++---------- 2 files changed, 239 insertions(+), 120 deletions(-) diff --git a/lib/rules/block-spacing.js b/lib/rules/block-spacing.js index 96012eda324..c4b30b0b70b 100644 --- a/lib/rules/block-spacing.js +++ b/lib/rules/block-spacing.js @@ -102,7 +102,7 @@ module.exports = { // Check. if (!isValid(openBrace, firstToken)) { - let loc = openBrace.loc.start; + let loc = openBrace.loc; if (messageId === "extra") { loc = { @@ -129,7 +129,7 @@ module.exports = { }); } if (!isValid(lastToken, closeBrace)) { - let loc = closeBrace.loc.start; + let loc = closeBrace.loc; if (messageId === "extra") { loc = { diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index ec582c33294..9690b3d3f84 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -21,48 +21,48 @@ const ruleTester = new RuleTester(); ruleTester.run("block-spacing", rule, { valid: [ - // default/always - { code: "{ foo(); }", options: ["always"] }, - "{ foo(); }", - "{ foo();\n}", - "{\nfoo(); }", - "{\r\nfoo();\r\n}", - "if (a) { foo(); }", - "if (a) {} else { foo(); }", - "switch (a) {}", - "switch (a) { case 0: foo(); }", - "while (a) { foo(); }", - "do { foo(); } while (a);", - "for (;;) { foo(); }", - "for (var a in b) { foo(); }", - { code: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 } }, - "try { foo(); } catch (e) { foo(); }", - "function foo() { bar(); }", - "(function() { bar(); });", - { code: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 } }, - "if (a) { /* comment */ foo(); /* comment */ }", - "if (a) { //comment\n foo(); }", + // // default/always + // { code: "{ foo(); }", options: ["always"] }, + // "{ foo(); }", + // "{ foo();\n}", + // "{\nfoo(); }", + // "{\r\nfoo();\r\n}", + // "if (a) { foo(); }", + // "if (a) {} else { foo(); }", + // "switch (a) {}", + // "switch (a) { case 0: foo(); }", + // "while (a) { foo(); }", + // "do { foo(); } while (a);", + // "for (;;) { foo(); }", + // "for (var a in b) { foo(); }", + // { code: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 } }, + // "try { foo(); } catch (e) { foo(); }", + // "function foo() { bar(); }", + // "(function() { bar(); });", + // { code: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 } }, + // "if (a) { /* comment */ foo(); /* comment */ }", + // "if (a) { //comment\n foo(); }", - // never - { code: "{foo();}", options: ["never"] }, - { code: "{foo();\n}", options: ["never"] }, - { code: "{\nfoo();}", options: ["never"] }, - { code: "{\r\nfoo();\r\n}", options: ["never"] }, - { code: "if (a) {foo();}", options: ["never"] }, - { code: "if (a) {} else {foo();}", options: ["never"] }, - { code: "switch (a) {}", options: ["never"] }, - { code: "switch (a) {case 0: foo();}", options: ["never"] }, - { code: "while (a) {foo();}", options: ["never"] }, - { code: "do {foo();} while (a);", options: ["never"] }, - { code: "for (;;) {foo();}", options: ["never"] }, - { code: "for (var a in b) {foo();}", options: ["never"] }, - { code: "for (var a of b) {foo();}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "try {foo();} catch (e) {foo();}", options: ["never"] }, - { code: "function foo() {bar();}", options: ["never"] }, - { code: "(function() {bar();});", options: ["never"] }, - { code: "(() => {bar();});", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"] }, - { code: "if (a) { //comment\n foo();}", options: ["never"] } + // // never + // { code: "{foo();}", options: ["never"] }, + // { code: "{foo();\n}", options: ["never"] }, + // { code: "{\nfoo();}", options: ["never"] }, + // { code: "{\r\nfoo();\r\n}", options: ["never"] }, + // { code: "if (a) {foo();}", options: ["never"] }, + // { code: "if (a) {} else {foo();}", options: ["never"] }, + // { code: "switch (a) {}", options: ["never"] }, + // { code: "switch (a) {case 0: foo();}", options: ["never"] }, + // { code: "while (a) {foo();}", options: ["never"] }, + // { code: "do {foo();} while (a);", options: ["never"] }, + // { code: "for (;;) {foo();}", options: ["never"] }, + // { code: "for (var a in b) {foo();}", options: ["never"] }, + // { code: "for (var a of b) {foo();}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + // { code: "try {foo();} catch (e) {foo();}", options: ["never"] }, + // { code: "function foo() {bar();}", options: ["never"] }, + // { code: "(function() {bar();});", options: ["never"] }, + // { code: "(() => {bar();});", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + // { code: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"] }, + // { code: "if (a) { //comment\n foo();}", options: ["never"] } ], invalid: [ @@ -182,12 +182,60 @@ ruleTester.run("block-spacing", rule, { code: "try {foo();} catch (e) {foo();} finally {foo();}", output: "try { foo(); } catch (e) { foo(); } finally { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 5, messageId: "missing", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 12, messageId: "missing", data: { location: "before", token: "}" } }, - { type: "BlockStatement", line: 1, column: 24, messageId: "missing", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 31, messageId: "missing", data: { location: "before", token: "}" } }, - { type: "BlockStatement", line: 1, column: 41, messageId: "missing", data: { location: "after", token: "{" } }, - { type: "BlockStatement", line: 1, column: 48, messageId: "missing", data: { location: "before", token: "}" } } + { + type: "BlockStatement", + messageId: "missing", + data: { location: "after", token: "{" }, + line: 1, + column: 5, + endLine: 1, + endColumn: 6 + }, + { + type: "BlockStatement", + messageId: "missing", + data: { location: "before", token: "}" }, + line: 1, + column: 12, + endLine: 1, + endColumn: 13 + }, + { + type: "BlockStatement", + messageId: "missing", + data: { location: "after", token: "{" }, + line: 1, + column: 24, + endLine: 1, + endColumn: 25 + }, + { + type: "BlockStatement", + messageId: "missing", + data: { location: "before", token: "}" }, + line: 1, + column: 31, + endLine: 1, + endColumn: 32 + }, + { + type: "BlockStatement", + messageId: "missing", + data: { location: "after", token: "{" }, + line: 1, + column: 41, + endLine: 1, + endColumn: 42 + }, + { + type: "BlockStatement", + messageId: "missing", + data: { location: "before", token: "}" }, + line: 1, + column: 48, + endLine: 1, + endColumn: 49 + } ] }, { @@ -229,7 +277,18 @@ ruleTester.run("block-spacing", rule, { output: "if (a) { //comment\n foo(); }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } } + { + type: "BlockStatement", + messageId: "missing", + data: { + location: "after", + token: "{" + }, + line: 1, + column: 8, + endLine: 1, + endColumn: 9 + } ] }, @@ -242,21 +301,21 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 2, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 2, endLine: 1, endColumn: 3 }, { type: "BlockStatement", - line: 1, - column: 9, messageId: "extra", data: { location: "before", token: "}" }, endLine: 1, - endColumn: 10 + endColumn: 10, + line: 1, + column: 9 } ] }, @@ -267,13 +326,13 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 2, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 2, endLine: 1, endColumn: 3 } @@ -286,13 +345,13 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 8, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 8, endLine: 1, endColumn: 9 } @@ -305,13 +364,13 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 2, - column: 7, messageId: "extra", data: { location: "before", token: "}" }, + line: 2, + column: 7, endLine: 2, endColumn: 8 } @@ -324,13 +383,13 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 2, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 2, endLine: 1, endColumn: 3 } @@ -343,19 +402,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 9, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 9, endLine: 1, endColumn: 10 }, { type: "BlockStatement", - line: 1, - column: 16, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 16, endLine: 1, endColumn: 17 } @@ -368,19 +427,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 17, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 17, endLine: 1, endColumn: 18 }, { type: "BlockStatement", - line: 1, - column: 24, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 24, endLine: 1, endColumn: 25 } @@ -393,19 +452,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "SwitchStatement", - line: 1, - column: 13, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 13, endLine: 1, endColumn: 14 }, { type: "SwitchStatement", - line: 1, - column: 28, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 28, endLine: 1, endColumn: 29 } @@ -418,19 +477,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 12, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 12, endLine: 1, endColumn: 13 }, { type: "BlockStatement", - line: 1, - column: 19, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 19, endLine: 1, endColumn: 20 } @@ -443,19 +502,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 5, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 5, endLine: 1, endColumn: 6 }, { type: "BlockStatement", - line: 1, - column: 12, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 12, endLine: 1, endColumn: 13 } @@ -468,19 +527,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 11, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 11, endLine: 1, endColumn: 12 }, { type: "BlockStatement", - line: 1, - column: 18, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 18, endLine: 1, endColumn: 19 } @@ -493,19 +552,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 19, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 19, endLine: 1, endColumn: 20 }, { type: "BlockStatement", - line: 1, - column: 26, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 26, endLine: 1, endColumn: 27 } @@ -519,19 +578,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 19, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 19, endLine: 1, endColumn: 20 }, { type: "BlockStatement", - line: 1, - column: 26, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 26, endLine: 1, endColumn: 27 } @@ -544,28 +603,28 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 6, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 6, endLine: 1, endColumn: 7 }, { type: "BlockStatement", - line: 1, - column: 13, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 13, endLine: 1, endColumn: 14 }, { type: "BlockStatement", - line: 1, - column: 27, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 27, endLine: 1, endColumn: 28 }, @@ -580,19 +639,19 @@ ruleTester.run("block-spacing", rule, { }, { type: "BlockStatement", - line: 1, - column: 46, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 46, endLine: 1, endColumn: 47 }, { type: "BlockStatement", - line: 1, - column: 53, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 53, endLine: 1, endColumn: 54 } @@ -605,19 +664,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 17, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 17, endLine: 1, endColumn: 18 }, { type: "BlockStatement", - line: 1, - column: 24, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 24, endLine: 1, endColumn: 25 } @@ -630,19 +689,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 14, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 14, endLine: 1, endColumn: 15 }, { type: "BlockStatement", - line: 1, - column: 21, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 21, endLine: 1, endColumn: 22 } @@ -656,19 +715,19 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 9, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 9, endLine: 1, endColumn: 10 }, { type: "BlockStatement", - line: 1, - column: 16, messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 16, endLine: 1, endColumn: 17 } @@ -681,21 +740,81 @@ ruleTester.run("block-spacing", rule, { errors: [ { type: "BlockStatement", - line: 1, - column: 9, messageId: "extra", data: { location: "after", token: "{" }, + line: 1, + column: 9, endLine: 1, endColumn: 10 }, { type: "BlockStatement", + messageId: "extra", + data: { location: "before", token: "}" }, line: 1, column: 44, + endLine: 1, + endColumn: 45 + } + ] + }, + { + code: "(() => { bar();});", + output: "(() => {bar();});", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [ + { + type: "BlockStatement", + messageId: "extra", + data: { location: "after", token: "{" }, + line: 1, + column: 9, + endLine: 1, + endColumn: 12 + } + ] + }, + { + code: "(() => {bar(); });", + output: "(() => {bar();});", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [ + { + type: "BlockStatement", messageId: "extra", data: { location: "before", token: "}" }, + line: 1, + column: 15, endLine: 1, - endColumn: 45 + endColumn: 18 + } + ] + }, + { + code: "(() => { bar(); });", + output: "(() => {bar();});", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [ + { + type: "BlockStatement", + messageId: "extra", + data: { location: "after", token: "{" }, + line: 1, + column: 9, + endLine: 1, + endColumn: 12 + }, + { + type: "BlockStatement", + messageId: "extra", + data: { location: "before", token: "}" }, + line: 1, + column: 18, + endLine: 1, + endColumn: 21 } ] } From ee3cacf94349dbfd125955c12796508ad0186788 Mon Sep 17 00:00:00 2001 From: Anix Date: Mon, 18 May 2020 16:19:39 +0000 Subject: [PATCH 4/5] Chore: un-comment valid case --- tests/lib/rules/block-spacing.js | 82 ++++++++++++++++---------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 9690b3d3f84..0818742af5a 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -21,48 +21,48 @@ const ruleTester = new RuleTester(); ruleTester.run("block-spacing", rule, { valid: [ - // // default/always - // { code: "{ foo(); }", options: ["always"] }, - // "{ foo(); }", - // "{ foo();\n}", - // "{\nfoo(); }", - // "{\r\nfoo();\r\n}", - // "if (a) { foo(); }", - // "if (a) {} else { foo(); }", - // "switch (a) {}", - // "switch (a) { case 0: foo(); }", - // "while (a) { foo(); }", - // "do { foo(); } while (a);", - // "for (;;) { foo(); }", - // "for (var a in b) { foo(); }", - // { code: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 } }, - // "try { foo(); } catch (e) { foo(); }", - // "function foo() { bar(); }", - // "(function() { bar(); });", - // { code: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 } }, - // "if (a) { /* comment */ foo(); /* comment */ }", - // "if (a) { //comment\n foo(); }", + // default/always + { code: "{ foo(); }", options: ["always"] }, + "{ foo(); }", + "{ foo();\n}", + "{\nfoo(); }", + "{\r\nfoo();\r\n}", + "if (a) { foo(); }", + "if (a) {} else { foo(); }", + "switch (a) {}", + "switch (a) { case 0: foo(); }", + "while (a) { foo(); }", + "do { foo(); } while (a);", + "for (;;) { foo(); }", + "for (var a in b) { foo(); }", + { code: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 } }, + "try { foo(); } catch (e) { foo(); }", + "function foo() { bar(); }", + "(function() { bar(); });", + { code: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 } }, + "if (a) { /* comment */ foo(); /* comment */ }", + "if (a) { //comment\n foo(); }", - // // never - // { code: "{foo();}", options: ["never"] }, - // { code: "{foo();\n}", options: ["never"] }, - // { code: "{\nfoo();}", options: ["never"] }, - // { code: "{\r\nfoo();\r\n}", options: ["never"] }, - // { code: "if (a) {foo();}", options: ["never"] }, - // { code: "if (a) {} else {foo();}", options: ["never"] }, - // { code: "switch (a) {}", options: ["never"] }, - // { code: "switch (a) {case 0: foo();}", options: ["never"] }, - // { code: "while (a) {foo();}", options: ["never"] }, - // { code: "do {foo();} while (a);", options: ["never"] }, - // { code: "for (;;) {foo();}", options: ["never"] }, - // { code: "for (var a in b) {foo();}", options: ["never"] }, - // { code: "for (var a of b) {foo();}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - // { code: "try {foo();} catch (e) {foo();}", options: ["never"] }, - // { code: "function foo() {bar();}", options: ["never"] }, - // { code: "(function() {bar();});", options: ["never"] }, - // { code: "(() => {bar();});", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - // { code: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"] }, - // { code: "if (a) { //comment\n foo();}", options: ["never"] } + // never + { code: "{foo();}", options: ["never"] }, + { code: "{foo();\n}", options: ["never"] }, + { code: "{\nfoo();}", options: ["never"] }, + { code: "{\r\nfoo();\r\n}", options: ["never"] }, + { code: "if (a) {foo();}", options: ["never"] }, + { code: "if (a) {} else {foo();}", options: ["never"] }, + { code: "switch (a) {}", options: ["never"] }, + { code: "switch (a) {case 0: foo();}", options: ["never"] }, + { code: "while (a) {foo();}", options: ["never"] }, + { code: "do {foo();} while (a);", options: ["never"] }, + { code: "for (;;) {foo();}", options: ["never"] }, + { code: "for (var a in b) {foo();}", options: ["never"] }, + { code: "for (var a of b) {foo();}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "try {foo();} catch (e) {foo();}", options: ["never"] }, + { code: "function foo() {bar();}", options: ["never"] }, + { code: "(function() {bar();});", options: ["never"] }, + { code: "(() => {bar();});", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"] }, + { code: "if (a) { //comment\n foo();}", options: ["never"] } ], invalid: [ From 85c88b036230fbc8614db25a14c1a5b2b1b463a5 Mon Sep 17 00:00:00 2001 From: Anix Date: Tue, 19 May 2020 11:18:19 +0000 Subject: [PATCH 5/5] Chore: consistent ordering of datas in errors object --- tests/lib/rules/block-spacing.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 0818742af5a..a80d07cc7d4 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -312,10 +312,10 @@ ruleTester.run("block-spacing", rule, { type: "BlockStatement", messageId: "extra", data: { location: "before", token: "}" }, - endLine: 1, - endColumn: 10, line: 1, - column: 9 + column: 9, + endLine: 1, + endColumn: 10 } ] },