Skip to content

Commit

Permalink
Fix: improve report location for object-curly-spacing (#12563)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and kaicataldo committed Nov 15, 2019
1 parent 1110045 commit 40c8c32
Show file tree
Hide file tree
Showing 2 changed files with 338 additions and 81 deletions.
16 changes: 8 additions & 8 deletions lib/rules/object-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ module.exports = {
* @returns {void}
*/
function reportNoBeginningSpace(node, token) {
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });

context.report({
node,
loc: token.loc.start,
loc: { start: token.loc.end, end: nextToken.loc.start },
message: "There should be no space after '{{token}}'.",
data: {
token: token.value
},
fix(fixer) {
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });

return fixer.removeRange([token.range[1], nextToken.range[0]]);
}
});
Expand All @@ -96,16 +96,16 @@ module.exports = {
* @returns {void}
*/
function reportNoEndingSpace(node, token) {
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });

context.report({
node,
loc: token.loc.start,
loc: { start: previousToken.loc.end, end: token.loc.start },
message: "There should be no space before '{{token}}'.",
data: {
token: token.value
},
fix(fixer) {
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });

return fixer.removeRange([previousToken.range[1], token.range[0]]);
}
});
Expand All @@ -120,7 +120,7 @@ module.exports = {
function reportRequiredBeginningSpace(node, token) {
context.report({
node,
loc: token.loc.start,
loc: token.loc,
message: "A space is required after '{{token}}'.",
data: {
token: token.value
Expand All @@ -140,7 +140,7 @@ module.exports = {
function reportRequiredEndingSpace(node, token) {
context.report({
node,
loc: token.loc.start,
loc: token.loc,
message: "A space is required before '{{token}}'.",
data: {
token: token.value
Expand Down
Loading

0 comments on commit 40c8c32

Please sign in to comment.