Skip to content

Commit

Permalink
feat: fix switch range issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amareshsm committed Aug 12, 2022
1 parent ecc2bd2 commit f0638f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rules/no-empty.js
Expand Up @@ -53,7 +53,6 @@ module.exports = {

return {
BlockStatement(node) {

const range = [node.range[0] + 1, node.range[1] - 1];

// if the body is not empty, we can just return immediately
Expand Down Expand Up @@ -92,8 +91,9 @@ module.exports = {
},

SwitchStatement(node) {

const range = [node.range[0] + 1, node.range[1] - 1];
const closingCurly = sourceCode.getLastToken(node);
const openingCurly = sourceCode.getTokenBefore(node.cases.length ? node.cases[0] : closingCurly);
const range = [openingCurly.range[0] + 1, closingCurly.range[1] - 1];

if (typeof node.cases === "undefined" || node.cases.length === 0) {
context.report({
Expand All @@ -103,7 +103,7 @@ module.exports = {
suggest: [
{
messageId: "suggestComment",
data: { type: "block" },
data: { type: "switch" },
fix(fixer) {
return fixer.replaceTextRange(range, " /* empty */ ");
}
Expand Down

0 comments on commit f0638f4

Please sign in to comment.