From a7fd343991cde99d8a219e3b25616db5792fe9a9 Mon Sep 17 00:00:00 2001 From: Anix Date: Sat, 6 Jun 2020 04:35:43 +0530 Subject: [PATCH] Update: keyword-spacing unexpected space loc improve (refs #12334) (#13377) --- lib/rules/keyword-spacing.js | 5 +++-- tests/lib/rules/keyword-spacing.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/rules/keyword-spacing.js b/lib/rules/keyword-spacing.js index 1829aed37ad..99979a32a5b 100644 --- a/lib/rules/keyword-spacing.js +++ b/lib/rules/keyword-spacing.js @@ -152,7 +152,7 @@ module.exports = { sourceCode.isSpaceBetweenTokens(prevToken, token) ) { context.report({ - loc: token.loc.start, + loc: { start: prevToken.loc.end, end: token.loc.start }, messageId: "unexpectedBefore", data: token, fix(fixer) { @@ -203,8 +203,9 @@ module.exports = { astUtils.isTokenOnSameLine(token, nextToken) && sourceCode.isSpaceBetweenTokens(token, nextToken) ) { + context.report({ - loc: token.loc.start, + loc: { start: token.loc.end, end: nextToken.loc.start }, messageId: "unexpectedAfter", data: token, fix(fixer) { diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 08e93394307..b67ee52384b 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -1373,6 +1373,35 @@ ruleTester.run("keyword-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBefore("as") }, + { + code: "import* as a from\"foo\"", + output: "import*as a from\"foo\"", + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ + messageId: "unexpectedBefore", + line: 1, + column: 8, + endLine: 1, + endColumn: 9 + } + ] + }, + { + code: "import *as a from\"foo\"", + output: "import*as a from\"foo\"", + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [ + { + messageId: "unexpectedAfter", + line: 1, + column: 7, + endLine: 1, + endColumn: 8 + } + ] + }, { code: "import*as a from\"foo\"", output: "import* as a from\"foo\"", @@ -3165,4 +3194,5 @@ ruleTester.run("keyword-spacing", rule, { errors: expectedAfter("async") } ] + });