Files
OpenFrontIO/eslint-plugin-local/rules/no-z-array.js
T
Scott Anderson 2ed0cef65c eslint: Prefer type.array() over z.array(type) (#1810)
## Description:

Prefer `type.array()` over `z.array(type)`.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
2025-08-14 01:43:25 -04:00

36 lines
905 B
JavaScript

export default {
create(context) {
return {
CallExpression(node) {
if (
node.callee.type === "MemberExpression" &&
node.callee.object.name === "z" &&
node.callee.property.name === "array" &&
node.arguments.length === 1
) {
const argSource = context.sourceCode.getText(node.arguments[0]);
context.report({
data: { type: argSource },
fix(fixer) {
return fixer.replaceText(node, `${argSource}.array()`);
},
messageId: "noZArray",
node,
});
}
},
};
},
meta: {
docs: {
description: "Disallow z.array(type) in favor of type.array()",
},
fixable: "code",
messages: {
noZArray: "Use `{{type}}.array()` instead of `z.array({{type}})`.",
},
schema: [],
type: "suggestion",
},
};