Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: improve report location for no-multi-spaces #12329

Merged
merged 1 commit into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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