Skip to content

Commit

Permalink
Update: key-spacing loc changes for extra space (refs #12334) (#13362)
Browse files Browse the repository at this point in the history
* Update: key-spacing loc changes for extra (refs #12334)

* Chore: Fixed typo in variable name.

Co-authored-by: Kai Cataldo <kai@kaicataldo.com>

Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
  • Loading branch information
anikethsaha and kaicataldo committed Jun 11, 2020
1 parent 7ce7988 commit 2a21049
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 55 deletions.
8 changes: 6 additions & 2 deletions lib/rules/key-spacing.js
Expand Up @@ -433,11 +433,15 @@ module.exports = {
tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
isKeySide = side === "key",
locStart = isKeySide ? tokenBeforeColon.loc.start : tokenAfterColon.loc.start,
isExtra = diff > 0,
diffAbs = Math.abs(diff),
spaces = Array(diffAbs + 1).join(" ");

const locStart = isKeySide ? tokenBeforeColon.loc.end : nextColon.loc.start;
const locEnd = isKeySide ? nextColon.loc.start : tokenAfterColon.loc.start;
const missingLoc = isKeySide ? tokenBeforeColon.loc : tokenAfterColon.loc;
const loc = isExtra ? { start: locStart, end: locEnd } : missingLoc;

if ((
diff && mode === "strict" ||
diff < 0 && mode === "minimum" ||
Expand Down Expand Up @@ -482,7 +486,7 @@ module.exports = {

context.report({
node: property[side],
loc: locStart,
loc,
messageId,
data: {
computed: property.computed ? "computed " : "",
Expand Down

0 comments on commit 2a21049

Please sign in to comment.