Skip to content

Commit

Permalink
Update: improve report location for no-multi-spaces (#12329)
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and platinumazure committed Oct 17, 2019
1 parent 561093f commit d61c8a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-multi-spaces.js
Expand Up @@ -121,7 +121,7 @@ module.exports = {

context.report({
node: rightToken,
loc: rightToken.loc.start,
loc: { start: leftToken.loc.end, end: rightToken.loc.start },
message: "Multiple spaces found before '{{displayValue}}'.",
data: { displayValue },
fix: fixer => fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ")
Expand Down
48 changes: 36 additions & 12 deletions tests/lib/rules/no-multi-spaces.js
Expand Up @@ -112,7 +112,9 @@ ruleTester.run("no-multi-spaces", rule, {
output: "function foo(a, b) {}",
errors: [{
message: "Multiple spaces found before 'b'.",
type: "Identifier"
type: "Identifier",
column: 16,
endColumn: 18
}]
},
{
Expand All @@ -121,15 +123,19 @@ ruleTester.run("no-multi-spaces", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [{
message: "Multiple spaces found before 'b'.",
type: "Identifier"
type: "Identifier",
column: 14,
endColumn: 16
}]
},
{
code: "var a = 1",
output: "var a = 1",
errors: [{
message: "Multiple spaces found before '1'.",
type: "Numeric"
type: "Numeric",
column: 8,
endColumn: 10
}]
},
{
Expand All @@ -153,7 +159,9 @@ ruleTester.run("no-multi-spaces", rule, {
output: "var arr = {'a': 1, 'b': 2};",
errors: [{
message: "Multiple spaces found before ''b''.",
type: "String"
type: "String",
column: 19,
endColumn: 21
}]
},
{
Expand Down Expand Up @@ -213,16 +221,24 @@ ruleTester.run("no-multi-spaces", rule, {
output: "[ , 1, , 3, , ]",
errors: [{
message: "Multiple spaces found before ','.",
type: "Punctuator"
type: "Punctuator",
column: 2,
endColumn: 4
}, {
message: "Multiple spaces found before ','.",
type: "Punctuator"
type: "Punctuator",
column: 8,
endColumn: 10
}, {
message: "Multiple spaces found before ','.",
type: "Punctuator"
type: "Punctuator",
column: 14,
endColumn: 16
}, {
message: "Multiple spaces found before ']'.",
type: "Punctuator"
type: "Punctuator",
column: 17,
endColumn: 19
}]
},
{
Expand Down Expand Up @@ -273,7 +289,9 @@ ruleTester.run("no-multi-spaces", rule, {
output: "function foo () {}",
errors: [{
message: "Multiple spaces found before '('.",
type: "Punctuator"
type: "Punctuator",
column: 13,
endColumn: 19
}]
},
{
Expand Down Expand Up @@ -389,7 +407,9 @@ ruleTester.run("no-multi-spaces", rule, {
output: "var x = 5;",
errors: [{
message: "Multiple spaces found before '5'.",
type: "Numeric"
type: "Numeric",
column: 8,
endColumn: 11
}]
},

Expand All @@ -415,7 +435,9 @@ ruleTester.run("no-multi-spaces", rule, {
output: "var x = 5; // comment",
errors: [{
message: "Multiple spaces found before '// comment'.",
type: "Line"
type: "Line",
column: 11,
endColumn: 13
}]
},
{
Expand Down Expand Up @@ -582,7 +604,9 @@ ruleTester.run("no-multi-spaces", rule, {
options: [{ ignoreEOLComments: false }],
errors: [{
message: "Multiple spaces found before '/*comment...*/'.",
type: "Block"
type: "Block",
column: 11,
endColumn: 13
}]
},
{
Expand Down

0 comments on commit d61c8a5

Please sign in to comment.