Skip to content

Commit

Permalink
refactor: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Jan 22, 2025
1 parent b356acc commit 2021555
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/rules/no-empty-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ const getDataAndMessageId = (
| JsonAST.JSONProperty,
): {
data: Record<string, string>;
messageId: "emptyFields" | "emptyExpression";
messageId: "emptyExpression" | "emptyFields";
} => {
switch (node.type) {
case "JSONProperty":
return {
data: {
field: (node.key as JsonAST.JSONStringLiteral).value,
},
messageId: "emptyFields",
};
case "JSONArrayExpression":
return {
data: {
Expand All @@ -35,6 +28,13 @@ const getDataAndMessageId = (
},
messageId: "emptyExpression",
};
case "JSONProperty":
return {
data: {
field: (node.key as JsonAST.JSONStringLiteral).value,
},
messageId: "emptyFields",
};
}
};

Expand Down Expand Up @@ -110,10 +110,10 @@ export const rule = createRule({
},
hasSuggestions: true,
messages: {
emptyFields:
"The field '{{field}}' does nothing and can be removed.",
emptyExpression:
"This {{expressionType}} does nothing and can be removed.",
emptyFields:
"The field '{{field}}' does nothing and can be removed.",
remove: "Remove this empty field.",
},
schema: [],
Expand Down

0 comments on commit 2021555

Please sign in to comment.