@sarj/eslint-plugin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # sarj-eslint
2
+
3
+ Collection of custom ESLint rules.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install sarj-eslint --save-dev
9
+ ```
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ rules: {
3
+ "zod-naming-convention": require("./rules/zod-naming-convention"),
4
+ },
5
+ configs: {
6
+ recommended: {
7
+ plugins: ["sarj-eslint"],
8
+ rules: {
9
+ "sarj-eslint/zod-naming-convention": "warn",
10
+ },
11
+ },
12
+ },
13
+ };
@@ -0,0 +1,47 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "Enforce Zod schemas to be named with a Z prefix",
6
+ category: "Stylistic Issues",
7
+ recommended: false
8
+ },
9
+ fixable: "code",
10
+ schema: []
11
+ },
12
+ create(context) {
13
+ return {
14
+ VariableDeclarator(node) {
15
+ // Check if the right side involves z.object() or other Zod schema creation
16
+ if (
17
+ node.init &&
18
+ node.init.type === "CallExpression" &&
19
+ node.init.callee &&
20
+ (
21
+ // Check direct calls like z.object()
22
+ (node.init.callee.type === "MemberExpression" &&
23
+ node.init.callee.object &&
24
+ node.init.callee.object.name === "z") ||
25
+ // Check chained calls like z.object().extend()
26
+ (node.init.callee.type === "MemberExpression" &&
27
+ node.init.callee.object &&
28
+ node.init.callee.object.callee &&
29
+ node.init.callee.object.callee.object &&
30
+ node.init.callee.object.callee.object.name === "z")
31
+ )
32
+ ) {
33
+ const variableName = node.id.name;
34
+ if (!variableName.startsWith("Z")) {
35
+ context.report({
36
+ node: node.id,
37
+ message: "Zod schema names should start with Z",
38
+ fix(fixer) {
39
+ return fixer.replaceText(node.id, `Z${variableName}`);
40
+ },
41
+ });
42
+ }
43
+ }
44
+ },
45
+ };
46
+ },
47
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@sarj/eslint-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Custom ESLint rules collection",
5
+ "main": "lib/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "test": "mocha tests/**/*.test.js"
11
+ },
12
+ "keywords": [
13
+ "eslint",
14
+ "eslintplugin",
15
+ "eslint-plugin",
16
+ "zod"
17
+ ],
18
+ "author": "Your Name",
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "eslint": "^8.0.0",
22
+ "mocha": "^10.0.0"
23
+ },
24
+ "peerDependencies": {
25
+ "eslint": ">=6.0.0"
26
+ },
27
+ "engines": {
28
+ "node": ">=14.0.0"
29
+ }
30
+ }