Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: add end location to reports in keyword-spacing (refs #12334) (#1…
  • Loading branch information
mdjermanovic committed Jul 7, 2020
1 parent 2ea7ee5 commit 10251bb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/rules/keyword-spacing.js
Expand Up @@ -126,7 +126,7 @@ module.exports = {
!sourceCode.isSpaceBetweenTokens(prevToken, token)
) {
context.report({
loc: token.loc.start,
loc: token.loc,
messageId: "expectedBefore",
data: token,
fix(fixer) {
Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports = {
!sourceCode.isSpaceBetweenTokens(token, nextToken)
) {
context.report({
loc: token.loc.start,
loc: token.loc,
messageId: "expectedAfter",
data: token,
fix(fixer) {
Expand Down
80 changes: 60 additions & 20 deletions tests/lib/rules/keyword-spacing.js
Expand Up @@ -1364,14 +1364,14 @@ ruleTester.run("keyword-spacing", rule, {
code: "import *as a from \"foo\"",
output: "import * as a from \"foo\"",
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedBefore("as")
},
{
code: "import* as a from\"foo\"",
output: "import*as a from\"foo\"",
options: [NEITHER],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: unexpectedBefore("as")
errors: [{
messageId: "expectedBefore",
data: { value: "as" },
line: 1,
column: 9,
endLine: 1,
endColumn: 11
}]
},
{
code: "import* as a from\"foo\"",
Expand All @@ -1380,27 +1380,26 @@ ruleTester.run("keyword-spacing", rule, {
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [{
messageId: "unexpectedBefore",
data: { value: "as" },
line: 1,
column: 8,
endLine: 1,
endColumn: 9
}
]
}]
},
{
code: "import *as a from\"foo\"",
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
}
]
errors: [{
messageId: "unexpectedBefore",
data: { value: "as" },
line: 1,
column: 8,
endLine: 1,
endColumn: 11
}]
},
{
code: "import*as a from\"foo\"",
Expand Down Expand Up @@ -2510,6 +2509,47 @@ ruleTester.run("keyword-spacing", rule, {
// import
//----------------------------------------------------------------------

{
code: "import* as a from \"foo\"",
output: "import * as a from \"foo\"",
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [{
messageId: "expectedAfter",
data: { value: "import" },
line: 1,
column: 1,
endLine: 1,
endColumn: 7
}]
},
{
code: "import *as a from\"foo\"",
output: "import*as a from\"foo\"",
options: [NEITHER],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [{
messageId: "unexpectedAfter",
data: { value: "import" },
line: 1,
column: 7,
endLine: 1,
endColumn: 8
}]
},
{
code: "import *as a from\"foo\"",
output: "import*as a from\"foo\"",
options: [NEITHER],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [{
messageId: "unexpectedAfter",
data: { value: "import" },
line: 1,
column: 7,
endLine: 1,
endColumn: 10
}]
},
{
code: "{}import{a} from \"foo\"",
output: "{} import {a} from \"foo\"",
Expand Down

0 comments on commit 10251bb

Please sign in to comment.