@sarj/eslint-plugin 1.0.1 → 2.0.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 +7 -128
- package/dist/index.cjs +13512 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.ts +115 -12
- package/dist/index.js +13503 -93
- package/dist/index.js.map +1 -0
- package/package.json +35 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/rules/enforce-file-structure.d.ts +0 -4
- package/dist/rules/enforce-file-structure.d.ts.map +0 -1
- package/dist/rules/enforce-file-structure.js +0 -90
- package/dist/rules/no-enum.d.ts +0 -8
- package/dist/rules/no-enum.d.ts.map +0 -1
- package/dist/rules/no-enum.js +0 -29
- package/dist/rules/no-raw-env.d.ts +0 -8
- package/dist/rules/no-raw-env.d.ts.map +0 -1
- package/dist/rules/no-raw-env.js +0 -33
- package/dist/rules/prefer-shadcn.d.ts +0 -4
- package/dist/rules/prefer-shadcn.d.ts.map +0 -1
- package/dist/rules/prefer-shadcn.js +0 -50
- package/dist/rules/require-assert-never.d.ts +0 -8
- package/dist/rules/require-assert-never.d.ts.map +0 -1
- package/dist/rules/require-assert-never.js +0 -53
- package/dist/rules/require-zod-form-validation.d.ts +0 -8
- package/dist/rules/require-zod-form-validation.d.ts.map +0 -1
- package/dist/rules/require-zod-form-validation.js +0 -59
- package/dist/rules/zod-naming-convention.d.ts +0 -8
- package/dist/rules/zod-naming-convention.d.ts.map +0 -1
- package/dist/rules/zod-naming-convention.js +0 -53
package/package.json
CHANGED
|
@@ -1,52 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sarj/eslint-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Custom ESLint rules
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
10
12
|
"import": "./dist/index.js",
|
|
11
|
-
"
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
12
14
|
}
|
|
13
15
|
},
|
|
14
16
|
"files": [
|
|
15
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
16
19
|
],
|
|
17
20
|
"publishConfig": {
|
|
18
|
-
"access": "public"
|
|
21
|
+
"access": "public",
|
|
22
|
+
"provenance": true
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/sarj-ai/linting.git",
|
|
28
|
+
"directory": "packages/typescript"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/sarj-ai/linting/tree/main/packages/typescript",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/sarj-ai/linting/issues"
|
|
19
33
|
},
|
|
20
34
|
"scripts": {
|
|
21
|
-
"build": "
|
|
35
|
+
"build": "tsup",
|
|
22
36
|
"test": "vitest run",
|
|
23
|
-
"
|
|
24
|
-
"lint": "eslint src",
|
|
25
|
-
"prepublishOnly": "yarn build"
|
|
37
|
+
"typecheck": "tsc --noEmit"
|
|
26
38
|
},
|
|
27
39
|
"keywords": [
|
|
28
40
|
"eslint",
|
|
29
41
|
"eslintplugin",
|
|
30
42
|
"eslint-plugin",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
43
|
+
"sarj",
|
|
44
|
+
"react",
|
|
45
|
+
"nextjs",
|
|
46
|
+
"zod"
|
|
34
47
|
],
|
|
35
|
-
"author": "
|
|
48
|
+
"author": "sarj-ai",
|
|
36
49
|
"license": "MIT",
|
|
37
50
|
"devDependencies": {
|
|
38
|
-
"@types/
|
|
39
|
-
"@types/node": "^22.0.0",
|
|
51
|
+
"@types/node": "^20.0.0",
|
|
40
52
|
"@typescript-eslint/parser": "^8.0.0",
|
|
53
|
+
"@typescript-eslint/rule-tester": "^8.0.0",
|
|
54
|
+
"@typescript-eslint/utils": "^8.0.0",
|
|
41
55
|
"eslint": "^9.0.0",
|
|
42
|
-
"
|
|
56
|
+
"tsup": "^8.3.0",
|
|
57
|
+
"typescript": "^5.6.0",
|
|
43
58
|
"vitest": "^2.0.0"
|
|
44
59
|
},
|
|
45
60
|
"peerDependencies": {
|
|
46
61
|
"eslint": ">=9.0.0"
|
|
47
62
|
},
|
|
48
63
|
"engines": {
|
|
49
|
-
"node": ">=
|
|
50
|
-
}
|
|
51
|
-
"packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
|
|
64
|
+
"node": ">=20.0.0"
|
|
65
|
+
}
|
|
52
66
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAUnD;;;;;GAKG;AAEH,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAQ1C,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,MAMpB,CAAC;AAGF,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAsE5C,CAAC;AAEF,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enforce-file-structure.d.ts","sourceRoot":"","sources":["../../src/rules/enforce-file-structure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAgDnC,eAAO,MAAM,oBAAoB,EAAE,IAAI,CAAC,UA8DvC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Enforce consistent file structure
|
|
3
|
-
* @description Enforces: imports -> types -> constants -> functions -> exports
|
|
4
|
-
*/
|
|
5
|
-
const SECTIONS = ["imports", "types", "constants", "functions", "exports"];
|
|
6
|
-
function getStatementSection(statement) {
|
|
7
|
-
const type = statement.type;
|
|
8
|
-
switch (type) {
|
|
9
|
-
case "ImportDeclaration":
|
|
10
|
-
return 0; // imports
|
|
11
|
-
case "TSTypeAliasDeclaration":
|
|
12
|
-
case "TSInterfaceDeclaration":
|
|
13
|
-
case "TSEnumDeclaration":
|
|
14
|
-
return 1; // types
|
|
15
|
-
case "VariableDeclaration": {
|
|
16
|
-
// Check if it's a constant (const with UPPER_CASE or simple values)
|
|
17
|
-
const varDecl = statement;
|
|
18
|
-
if (varDecl.kind === "const") {
|
|
19
|
-
const declarator = varDecl.declarations[0];
|
|
20
|
-
if (declarator?.id.type === "Identifier" &&
|
|
21
|
-
declarator.id.name === declarator.id.name.toUpperCase()) {
|
|
22
|
-
return 2; // constants
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return 3; // functions (const fn = ...)
|
|
26
|
-
}
|
|
27
|
-
case "FunctionDeclaration":
|
|
28
|
-
return 3; // functions
|
|
29
|
-
case "ExportNamedDeclaration":
|
|
30
|
-
case "ExportDefaultDeclaration":
|
|
31
|
-
return 4; // exports
|
|
32
|
-
default:
|
|
33
|
-
return 3; // default to functions
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export const enforceFileStructure = {
|
|
37
|
-
meta: {
|
|
38
|
-
type: "suggestion",
|
|
39
|
-
docs: {
|
|
40
|
-
description: "Enforce consistent file structure: imports -> types -> constants -> functions -> exports",
|
|
41
|
-
recommended: true,
|
|
42
|
-
},
|
|
43
|
-
schema: [],
|
|
44
|
-
messages: {
|
|
45
|
-
incorrectOrder: "File structure violation: {{current}} should come after {{expected}}",
|
|
46
|
-
useServerDirective: "Server action files must start with 'use server' directive",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
create(context) {
|
|
50
|
-
const filename = context.filename;
|
|
51
|
-
const isServerAction = filename.includes("/actions/") || filename.includes("action");
|
|
52
|
-
return {
|
|
53
|
-
Program(node) {
|
|
54
|
-
const program = node;
|
|
55
|
-
const body = program.body;
|
|
56
|
-
let currentSection = 0;
|
|
57
|
-
// Check for "use server" directive in server action files
|
|
58
|
-
if (isServerAction) {
|
|
59
|
-
const firstNode = body[0];
|
|
60
|
-
if (!firstNode ||
|
|
61
|
-
firstNode.type !== "ExpressionStatement" ||
|
|
62
|
-
firstNode.expression.type !== "Literal" ||
|
|
63
|
-
firstNode.expression.value !== "use server") {
|
|
64
|
-
context.report({
|
|
65
|
-
node,
|
|
66
|
-
messageId: "useServerDirective",
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
for (const statement of body) {
|
|
71
|
-
const statementSection = getStatementSection(statement);
|
|
72
|
-
if (statementSection < currentSection) {
|
|
73
|
-
context.report({
|
|
74
|
-
node: statement,
|
|
75
|
-
messageId: "incorrectOrder",
|
|
76
|
-
data: {
|
|
77
|
-
current: SECTIONS[statementSection],
|
|
78
|
-
expected: SECTIONS[currentSection],
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
currentSection = Math.max(currentSection, statementSection);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
export default enforceFileStructure;
|
package/dist/rules/no-enum.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Disallow TypeScript enums, prefer union types
|
|
4
|
-
* @description Enums add runtime code and have unintuitive behavior. Use union types instead.
|
|
5
|
-
*/
|
|
6
|
-
export declare const noEnum: Rule.RuleModule;
|
|
7
|
-
export default noEnum;
|
|
8
|
-
//# sourceMappingURL=no-enum.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-enum.d.ts","sourceRoot":"","sources":["../../src/rules/no-enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;GAGG;AAEH,eAAO,MAAM,MAAM,EAAE,IAAI,CAAC,UAyBzB,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/rules/no-enum.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Disallow TypeScript enums, prefer union types
|
|
3
|
-
* @description Enums add runtime code and have unintuitive behavior. Use union types instead.
|
|
4
|
-
*/
|
|
5
|
-
export const noEnum = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "suggestion",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Disallow TypeScript enums, prefer union types or const objects",
|
|
10
|
-
recommended: true,
|
|
11
|
-
},
|
|
12
|
-
schema: [],
|
|
13
|
-
messages: {
|
|
14
|
-
noEnum: 'Enums are discouraged. Use union types (\'type Status = "active" | "inactive"\') or const objects instead.',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
create(context) {
|
|
18
|
-
return {
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
TSEnumDeclaration(node) {
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "noEnum",
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
export default noEnum;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Disallow direct process.env access
|
|
4
|
-
* @description Use Zod-validated env schema instead of process.env
|
|
5
|
-
*/
|
|
6
|
-
export declare const noRawEnv: Rule.RuleModule;
|
|
7
|
-
export default noRawEnv;
|
|
8
|
-
//# sourceMappingURL=no-raw-env.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-raw-env.d.ts","sourceRoot":"","sources":["../../src/rules/no-raw-env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGnC;;;GAGG;AAEH,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,UA8B3B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/rules/no-raw-env.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Disallow direct process.env access
|
|
3
|
-
* @description Use Zod-validated env schema instead of process.env
|
|
4
|
-
*/
|
|
5
|
-
export const noRawEnv = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Disallow direct process.env access",
|
|
10
|
-
recommended: true,
|
|
11
|
-
},
|
|
12
|
-
schema: [],
|
|
13
|
-
messages: {
|
|
14
|
-
noRawEnv: "Use Zod-validated env schema instead of process.env directly",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
create(context) {
|
|
18
|
-
return {
|
|
19
|
-
MemberExpression(node) {
|
|
20
|
-
if (node.object.type === "Identifier" &&
|
|
21
|
-
node.object.name === "process" &&
|
|
22
|
-
node.property.type === "Identifier" &&
|
|
23
|
-
node.property.name === "env") {
|
|
24
|
-
context.report({
|
|
25
|
-
node,
|
|
26
|
-
messageId: "noRawEnv",
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
export default noRawEnv;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-shadcn.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-shadcn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAgBnC,eAAO,MAAM,YAAY,EAAE,IAAI,CAAC,UAwC/B,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Prefer shadcn/ui components over native HTML elements
|
|
3
|
-
* @description Use shadcn components for consistent design system
|
|
4
|
-
*/
|
|
5
|
-
const REPLACEMENTS = {
|
|
6
|
-
button: "Button",
|
|
7
|
-
input: "Input",
|
|
8
|
-
select: "Select",
|
|
9
|
-
textarea: "Textarea",
|
|
10
|
-
table: "Table",
|
|
11
|
-
dialog: "Dialog",
|
|
12
|
-
};
|
|
13
|
-
export const preferShadcn = {
|
|
14
|
-
meta: {
|
|
15
|
-
type: "suggestion",
|
|
16
|
-
docs: {
|
|
17
|
-
description: "Prefer shadcn/ui components over native HTML elements",
|
|
18
|
-
recommended: true,
|
|
19
|
-
},
|
|
20
|
-
schema: [],
|
|
21
|
-
messages: {
|
|
22
|
-
preferShadcn: "Use shadcn <{{replacement}}> component from @/components/ui/{{lowercase}} instead of native <{{element}}>",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
create(context) {
|
|
26
|
-
return {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
JSXOpeningElement(node) {
|
|
29
|
-
// Only check lowercase element names (native HTML)
|
|
30
|
-
if (!node.name || node.name.type !== "JSXIdentifier") {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const elementName = node.name.name;
|
|
34
|
-
const replacement = REPLACEMENTS[elementName];
|
|
35
|
-
if (replacement) {
|
|
36
|
-
context.report({
|
|
37
|
-
node,
|
|
38
|
-
messageId: "preferShadcn",
|
|
39
|
-
data: {
|
|
40
|
-
element: elementName,
|
|
41
|
-
replacement,
|
|
42
|
-
lowercase: elementName,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
export default preferShadcn;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Require assertNever in switch statement default cases
|
|
4
|
-
* @description Ensures exhaustive type checking in switch statements
|
|
5
|
-
*/
|
|
6
|
-
export declare const requireAssertNever: Rule.RuleModule;
|
|
7
|
-
export default requireAssertNever;
|
|
8
|
-
//# sourceMappingURL=require-assert-never.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"require-assert-never.d.ts","sourceRoot":"","sources":["../../src/rules/require-assert-never.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGnC;;;GAGG;AAEH,eAAO,MAAM,kBAAkB,EAAE,IAAI,CAAC,UAwDrC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Require assertNever in switch statement default cases
|
|
3
|
-
* @description Ensures exhaustive type checking in switch statements
|
|
4
|
-
*/
|
|
5
|
-
export const requireAssertNever = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Require assertNever in switch statement default cases for exhaustive type checking",
|
|
10
|
-
recommended: true,
|
|
11
|
-
},
|
|
12
|
-
schema: [],
|
|
13
|
-
messages: {
|
|
14
|
-
missingAssertNever: "Switch statement default case must call assertNever() for exhaustive type checking",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
create(context) {
|
|
18
|
-
return {
|
|
19
|
-
SwitchStatement(node) {
|
|
20
|
-
const defaultCase = node.cases.find((caseNode) => caseNode.test === null);
|
|
21
|
-
if (!defaultCase) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const hasAssertNever = defaultCase.consequent.some((statement) => {
|
|
25
|
-
// Check for ExpressionStatement containing CallExpression
|
|
26
|
-
if (statement.type === "ExpressionStatement") {
|
|
27
|
-
const exprStmt = statement;
|
|
28
|
-
if (exprStmt.expression.type === "CallExpression") {
|
|
29
|
-
const callee = exprStmt.expression.callee;
|
|
30
|
-
return callee.type === "Identifier" && callee.name === "assertNever";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Check for ThrowStatement with assertNever call
|
|
34
|
-
if (statement.type === "ThrowStatement") {
|
|
35
|
-
const throwStmt = statement;
|
|
36
|
-
if (throwStmt.argument?.type === "CallExpression") {
|
|
37
|
-
const callee = throwStmt.argument.callee;
|
|
38
|
-
return callee.type === "Identifier" && callee.name === "assertNever";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
});
|
|
43
|
-
if (!hasAssertNever) {
|
|
44
|
-
context.report({
|
|
45
|
-
node: defaultCase,
|
|
46
|
-
messageId: "missingAssertNever",
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
export default requireAssertNever;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Require Zod validation when parsing FormData
|
|
4
|
-
* @description Ensures form data is validated with Zod schemas
|
|
5
|
-
*/
|
|
6
|
-
export declare const requireZodFormValidation: Rule.RuleModule;
|
|
7
|
-
export default requireZodFormValidation;
|
|
8
|
-
//# sourceMappingURL=require-zod-form-validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"require-zod-form-validation.d.ts","sourceRoot":"","sources":["../../src/rules/require-zod-form-validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGnC;;;GAGG;AAEH,eAAO,MAAM,wBAAwB,EAAE,IAAI,CAAC,UAkE3C,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Require Zod validation when parsing FormData
|
|
3
|
-
* @description Ensures form data is validated with Zod schemas
|
|
4
|
-
*/
|
|
5
|
-
export const requireZodFormValidation = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Require Zod validation when parsing FormData",
|
|
10
|
-
recommended: true,
|
|
11
|
-
},
|
|
12
|
-
schema: [],
|
|
13
|
-
messages: {
|
|
14
|
-
missingZodValidation: "FormData parsing must use Zod schema validation (e.g., Schema.parse())",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
create(context) {
|
|
18
|
-
return {
|
|
19
|
-
CallExpression(node) {
|
|
20
|
-
const callExpr = node;
|
|
21
|
-
// Check for formData.get() calls
|
|
22
|
-
if (callExpr.callee.type !== "MemberExpression") {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const callee = callExpr.callee;
|
|
26
|
-
if (callee.property.type !== "Identifier" ||
|
|
27
|
-
callee.property.name !== "get" ||
|
|
28
|
-
callee.object.type !== "Identifier" ||
|
|
29
|
-
callee.object.name !== "formData") {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// Check if this is inside a Zod .parse() call
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
let parent = node.parent;
|
|
35
|
-
let hasZodValidation = false;
|
|
36
|
-
// Traverse up to find if we're inside a .parse() call
|
|
37
|
-
while (parent) {
|
|
38
|
-
if (parent.type === "CallExpression" &&
|
|
39
|
-
parent.callee.type === "MemberExpression") {
|
|
40
|
-
const parentCallee = parent.callee;
|
|
41
|
-
if (parentCallee.property.type === "Identifier" &&
|
|
42
|
-
parentCallee.property.name === "parse") {
|
|
43
|
-
hasZodValidation = true;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
parent = parent.parent;
|
|
48
|
-
}
|
|
49
|
-
if (!hasZodValidation) {
|
|
50
|
-
context.report({
|
|
51
|
-
node: node,
|
|
52
|
-
messageId: "missingZodValidation",
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
export default requireZodFormValidation;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Enforce Zod schemas to be named with a Z prefix
|
|
4
|
-
* @description Ensures consistent naming for Zod schemas (e.g., ZUserSchema instead of userSchema)
|
|
5
|
-
*/
|
|
6
|
-
export declare const zodNamingConvention: Rule.RuleModule;
|
|
7
|
-
export default zodNamingConvention;
|
|
8
|
-
//# sourceMappingURL=zod-naming-convention.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod-naming-convention.d.ts","sourceRoot":"","sources":["../../src/rules/zod-naming-convention.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGnC;;;GAGG;AAEH,eAAO,MAAM,mBAAmB,EAAE,IAAI,CAAC,UAqDtC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Enforce Zod schemas to be named with a Z prefix
|
|
3
|
-
* @description Ensures consistent naming for Zod schemas (e.g., ZUserSchema instead of userSchema)
|
|
4
|
-
*/
|
|
5
|
-
export const zodNamingConvention = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "suggestion",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Enforce Zod schemas to be named with a Z prefix",
|
|
10
|
-
recommended: false,
|
|
11
|
-
},
|
|
12
|
-
schema: [],
|
|
13
|
-
messages: {
|
|
14
|
-
zodPrefix: "Zod schema names should start with 'Z' (e.g., Z{{suggestedName}})",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
create(context) {
|
|
18
|
-
return {
|
|
19
|
-
VariableDeclarator(node) {
|
|
20
|
-
const declarator = node;
|
|
21
|
-
if (!declarator.init || declarator.init.type !== "CallExpression") {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const callExpr = declarator.init;
|
|
25
|
-
if (!callExpr.callee || callExpr.callee.type !== "MemberExpression") {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const callee = callExpr.callee;
|
|
29
|
-
const isDirectZodCall = callee.object.type === "Identifier" &&
|
|
30
|
-
callee.object.name === "z";
|
|
31
|
-
const isChainedZodCall = callee.object.type === "CallExpression" &&
|
|
32
|
-
callee.object.callee?.type === "MemberExpression" &&
|
|
33
|
-
callee.object.callee.object?.type === "Identifier" &&
|
|
34
|
-
callee.object.callee.object.name === "z";
|
|
35
|
-
if (isDirectZodCall || isChainedZodCall) {
|
|
36
|
-
if (declarator.id.type !== "Identifier") {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const variableName = declarator.id.name;
|
|
40
|
-
if (!variableName.startsWith("Z")) {
|
|
41
|
-
const suggestedName = variableName.charAt(0).toUpperCase() + variableName.slice(1);
|
|
42
|
-
context.report({
|
|
43
|
-
node: declarator.id,
|
|
44
|
-
messageId: "zodPrefix",
|
|
45
|
-
data: { suggestedName },
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
export default zodNamingConvention;
|