Skip to content

Commit 438dcbb

Browse files
authoredMar 31, 2020
Update: Improve report location for comma-style (refs #12334) (#13111)
1 parent 85b7254 commit 438dcbb

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed
 

‎lib/rules/comma-style.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ module.exports = {
146146
// lone comma
147147
context.report({
148148
node: reportItem,
149-
loc: {
150-
line: commaToken.loc.end.line,
151-
column: commaToken.loc.start.column
152-
},
149+
loc: commaToken.loc,
153150
messageId: "unexpectedLineBeforeAndAfterComma",
154151
fix: getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken)
155152
});
@@ -158,6 +155,7 @@ module.exports = {
158155

159156
context.report({
160157
node: reportItem,
158+
loc: commaToken.loc,
161159
messageId: "expectedCommaFirst",
162160
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
163161
});
@@ -166,10 +164,7 @@ module.exports = {
166164

167165
context.report({
168166
node: reportItem,
169-
loc: {
170-
line: commaToken.loc.end.line,
171-
column: commaToken.loc.end.column
172-
},
167+
loc: commaToken.loc,
173168
messageId: "expectedCommaLast",
174169
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
175170
});

‎tests/lib/rules/comma-style.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ ruleTester.run("comma-style", rule, {
292292
output: "var foo = 1,\nbar = 2;",
293293
errors: [{
294294
messageId: "expectedCommaLast",
295-
type: "VariableDeclarator"
295+
type: "VariableDeclarator",
296+
column: 1,
297+
endColumn: 2
296298
}]
297299
},
298300
{
@@ -473,7 +475,9 @@ ruleTester.run("comma-style", rule, {
473475
options: ["first"],
474476
errors: [{
475477
messageId: "expectedCommaFirst",
476-
type: "VariableDeclarator"
478+
type: "VariableDeclarator",
479+
column: 12,
480+
endColumn: 13
477481
}]
478482
},
479483
{
@@ -590,7 +594,9 @@ ruleTester.run("comma-style", rule, {
590594
output: "var foo = [\n(bar\n),\nbaz\n];",
591595
errors: [{
592596
messageId: "unexpectedLineBeforeAndAfterComma",
593-
type: "Identifier"
597+
type: "Identifier",
598+
column: 1,
599+
endColumn: 2
594600
}]
595601
},
596602
{

0 commit comments

Comments
 (0)
Please sign in to comment.