Skip to content

Commit

Permalink
Update: Improve report location for comma-style (refs #12334) (#13111)
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Mar 31, 2020
1 parent 85b7254 commit 438dcbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 3 additions & 8 deletions lib/rules/comma-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ module.exports = {
// lone comma
context.report({
node: reportItem,
loc: {
line: commaToken.loc.end.line,
column: commaToken.loc.start.column
},
loc: commaToken.loc,
messageId: "unexpectedLineBeforeAndAfterComma",
fix: getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken)
});
Expand All @@ -158,6 +155,7 @@ module.exports = {

context.report({
node: reportItem,
loc: commaToken.loc,
messageId: "expectedCommaFirst",
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
});
Expand All @@ -166,10 +164,7 @@ module.exports = {

context.report({
node: reportItem,
loc: {
line: commaToken.loc.end.line,
column: commaToken.loc.end.column
},
loc: commaToken.loc,
messageId: "expectedCommaLast",
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
});
Expand Down
12 changes: 9 additions & 3 deletions tests/lib/rules/comma-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ ruleTester.run("comma-style", rule, {
output: "var foo = 1,\nbar = 2;",
errors: [{
messageId: "expectedCommaLast",
type: "VariableDeclarator"
type: "VariableDeclarator",
column: 1,
endColumn: 2
}]
},
{
Expand Down Expand Up @@ -473,7 +475,9 @@ ruleTester.run("comma-style", rule, {
options: ["first"],
errors: [{
messageId: "expectedCommaFirst",
type: "VariableDeclarator"
type: "VariableDeclarator",
column: 12,
endColumn: 13
}]
},
{
Expand Down Expand Up @@ -590,7 +594,9 @@ ruleTester.run("comma-style", rule, {
output: "var foo = [\n(bar\n),\nbaz\n];",
errors: [{
messageId: "unexpectedLineBeforeAndAfterComma",
type: "Identifier"
type: "Identifier",
column: 1,
endColumn: 2
}]
},
{
Expand Down

0 comments on commit 438dcbb

Please sign in to comment.