Skip to content

Commit

Permalink
Fix: improve report location for array-bracket-spacing (#12653)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and btmills committed Dec 20, 2019
1 parent 45364af commit 51f9620
Show file tree
Hide file tree
Showing 2 changed files with 301 additions and 58 deletions.
16 changes: 8 additions & 8 deletions lib/rules/array-bracket-spacing.js
Expand Up @@ -84,16 +84,16 @@ module.exports = {
* @returns {void}
*/
function reportNoBeginningSpace(node, token) {
const nextToken = sourceCode.getTokenAfter(token);

context.report({
node,
loc: token.loc.start,
loc: { start: token.loc.end, end: nextToken.loc.start },
messageId: "unexpectedSpaceAfter",
data: {
tokenValue: token.value
},
fix(fixer) {
const nextToken = sourceCode.getTokenAfter(token);

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

context.report({
node,
loc: token.loc.start,
loc: { start: previousToken.loc.end, end: token.loc.start },
messageId: "unexpectedSpaceBefore",
data: {
tokenValue: token.value
},
fix(fixer) {
const previousToken = sourceCode.getTokenBefore(token);

return fixer.removeRange([previousToken.range[1], token.range[0]]);
}
});
Expand All @@ -130,7 +130,7 @@ module.exports = {
function reportRequiredBeginningSpace(node, token) {
context.report({
node,
loc: token.loc.start,
loc: token.loc,
messageId: "missingSpaceAfter",
data: {
tokenValue: token.value
Expand All @@ -150,7 +150,7 @@ module.exports = {
function reportRequiredEndingSpace(node, token) {
context.report({
node,
loc: token.loc.start,
loc: token.loc,
messageId: "missingSpaceBefore",
data: {
tokenValue: token.value
Expand Down

0 comments on commit 51f9620

Please sign in to comment.