Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: padded-blocks loc position changes (refs #12334) (#13328)
  • Loading branch information
anikethsaha committed May 23, 2020
1 parent bd3f092 commit df01af1
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 69 deletions.
21 changes: 17 additions & 4 deletions lib/rules/padded-blocks.js
Expand Up @@ -203,10 +203,14 @@ module.exports = {
}

if (requirePaddingFor(node)) {

if (!blockHasTopPadding) {
context.report({
node,
loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
loc: {
start: tokenBeforeFirst.loc.start,
end: firstBlockToken.loc.start
},
fix(fixer) {
return fixer.insertTextAfter(tokenBeforeFirst, "\n");
},
Expand All @@ -216,7 +220,10 @@ module.exports = {
if (!blockHasBottomPadding) {
context.report({
node,
loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
loc: {
end: tokenAfterLast.loc.start,
start: lastBlockToken.loc.end
},
fix(fixer) {
return fixer.insertTextBefore(tokenAfterLast, "\n");
},
Expand All @@ -228,7 +235,10 @@ module.exports = {

context.report({
node,
loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
loc: {
start: tokenBeforeFirst.loc.start,
end: firstBlockToken.loc.start
},
fix(fixer) {
return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], "\n");
},
Expand All @@ -240,7 +250,10 @@ module.exports = {

context.report({
node,
loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
loc: {
end: tokenAfterLast.loc.start,
start: lastBlockToken.loc.end
},
messageId: "neverPadBlock",
fix(fixer) {
return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], "\n");
Expand Down

0 comments on commit df01af1

Please sign in to comment.