Skip to content

Commit

Permalink
refactor(Label): early return
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Feb 27, 2024
1 parent e951fff commit 662a2c3
Showing 1 changed file with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,37 @@ module.exports = {
attr.name?.name === "isOverflowLabel"
);

if (isOverflowLabelAttribute) {
const variantAttribute = node.attributes.find(
(attr) =>
attr.type === "JSXAttribute" &&
attr.name?.name === "variant"
);
if (isOverflowLabelAttribute === undefined) {
return;
}

const baseMessage =
'The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`.';
const variantAttribute = node.attributes.find(
(attr) =>
attr.type === "JSXAttribute" && attr.name?.name === "variant"
);

context.report({
node,
message: variantAttribute
? `${baseMessage} Running the fix for this rule will replace an existing \`variant\` prop (which had no effect if \`isOverflowLabel\` was used).`
: baseMessage,
fix: <Rule.ReportFixer>function (fixer) {
const fixes = [
fixer.replaceText(
isOverflowLabelAttribute,
'variant="overflow"'
),
];
if (variantAttribute) {
fixes.push(fixer.remove(variantAttribute));
}
const baseMessage =
'The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`.';

return fixes;
},
});
}
context.report({
node,
message: variantAttribute
? `${baseMessage} Running the fix for this rule will replace an existing \`variant\` prop (which had no effect if \`isOverflowLabel\` was used).`
: baseMessage,
fix: <Rule.ReportFixer>function (fixer) {
const fixes = [
fixer.replaceText(
isOverflowLabelAttribute,
'variant="overflow"'
),
];
if (variantAttribute) {
fixes.push(fixer.remove(variantAttribute));
}

return fixes;
},
});
}
},
};
Expand Down

0 comments on commit 662a2c3

Please sign in to comment.