Skip to content

Commit

Permalink
Fix: Keep indentation when fixing padded-blocks "never" (fixes esli…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mardak committed Jun 18, 2016
1 parent 414206c commit 18ff821
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rules/padded-blocks.js
Expand Up @@ -190,7 +190,7 @@ module.exports = {
node: node,
loc: { line: openBrace.loc.start.line, column: openBrace.loc.start.column },
fix: function(fixer) {
return fixer.replaceTextRange([openBrace.end, nextToken.start], "\n");
return fixer.replaceTextRange([openBrace.end, nextToken.start - nextToken.loc.start.column], "\n");
},
message: NEVER_MESSAGE
});
Expand All @@ -204,7 +204,7 @@ module.exports = {
loc: {line: closeBrace.loc.end.line, column: closeBrace.loc.end.column - 1 },
message: NEVER_MESSAGE,
fix: function(fixer) {
return fixer.replaceTextRange([previousToken.end, closeBrace.start], "\n");
return fixer.replaceTextRange([previousToken.end, closeBrace.start - closeBrace.loc.start.column], "\n");
}
});
}
Expand Down
26 changes: 24 additions & 2 deletions tests/lib/rules/padded-blocks.js
Expand Up @@ -307,7 +307,7 @@ ruleTester.run("padded-blocks", rule, {
},
{
code: "{\n\n\n a();\n\n\n}",
output: "{\na();\n}",
output: "{\n a();\n}",
options: ["never"],
errors: [
{
Expand All @@ -331,6 +331,17 @@ ruleTester.run("padded-blocks", rule, {
}
]
},
{
code: "{\n\n\ta();\n}",
output: "{\n\ta();\n}",
options: ["never"],
errors: [
{
message: NEVER_MESSAGE,
line: 1
}
]
},
{
code: "{\na();\n\n}",
output: "{\na();\n}",
Expand All @@ -342,6 +353,17 @@ ruleTester.run("padded-blocks", rule, {
}
]
},
{
code: " {\n a();\n\n }",
output: " {\n a();\n }",
options: ["never"],
errors: [
{
message: NEVER_MESSAGE,
line: 4
}
]
},
{
code: "{\n// comment\nif (\n// comment\n a) {}\n\n}",
output: "{\n\n// comment\nif (\n// comment\n a) {}\n\n}",
Expand Down Expand Up @@ -392,7 +414,7 @@ ruleTester.run("padded-blocks", rule, {
},
{
code: "switch (a) {\ncase 0: foo();\n\n }",
output: "switch (a) {\ncase 0: foo();\n}",
output: "switch (a) {\ncase 0: foo();\n }",
options: [{switches: "never"}],
errors: [
{
Expand Down

0 comments on commit 18ff821

Please sign in to comment.