Skip to content

Commit 40c8c32

Browse files
mdjermanovickaicataldo
authored andcommitted
Fix: improve report location for object-curly-spacing (#12563)
1 parent 1110045 commit 40c8c32

File tree

2 files changed

+338
-81
lines changed

2 files changed

+338
-81
lines changed

lib/rules/object-curly-spacing.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ module.exports = {
7474
* @returns {void}
7575
*/
7676
function reportNoBeginningSpace(node, token) {
77+
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });
78+
7779
context.report({
7880
node,
79-
loc: token.loc.start,
81+
loc: { start: token.loc.end, end: nextToken.loc.start },
8082
message: "There should be no space after '{{token}}'.",
8183
data: {
8284
token: token.value
8385
},
8486
fix(fixer) {
85-
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });
86-
8787
return fixer.removeRange([token.range[1], nextToken.range[0]]);
8888
}
8989
});
@@ -96,16 +96,16 @@ module.exports = {
9696
* @returns {void}
9797
*/
9898
function reportNoEndingSpace(node, token) {
99+
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });
100+
99101
context.report({
100102
node,
101-
loc: token.loc.start,
103+
loc: { start: previousToken.loc.end, end: token.loc.start },
102104
message: "There should be no space before '{{token}}'.",
103105
data: {
104106
token: token.value
105107
},
106108
fix(fixer) {
107-
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });
108-
109109
return fixer.removeRange([previousToken.range[1], token.range[0]]);
110110
}
111111
});
@@ -120,7 +120,7 @@ module.exports = {
120120
function reportRequiredBeginningSpace(node, token) {
121121
context.report({
122122
node,
123-
loc: token.loc.start,
123+
loc: token.loc,
124124
message: "A space is required after '{{token}}'.",
125125
data: {
126126
token: token.value
@@ -140,7 +140,7 @@ module.exports = {
140140
function reportRequiredEndingSpace(node, token) {
141141
context.report({
142142
node,
143-
loc: token.loc.start,
143+
loc: token.loc,
144144
message: "A space is required before '{{token}}'.",
145145
data: {
146146
token: token.value

0 commit comments

Comments
 (0)