Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: keyword-spacing unexpected space loc improve (refs #12334) (#…
  • Loading branch information
anikethsaha committed Jun 5, 2020
1 parent e49732e commit a7fd343
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rules/keyword-spacing.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/rules/keyword-spacing.js
Expand Up @@ -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\"",
Expand Down Expand Up @@ -3165,4 +3194,5 @@ ruleTester.run("keyword-spacing", rule, {
errors: expectedAfter("async")
}
]

});

0 comments on commit a7fd343

Please sign in to comment.