@sarj/eslint-plugin 1.0.1 → 2.0.1
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 +1070 -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 +1049 -95
- package/dist/index.js.map +1 -0
- package/package.json +43 -26
- 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/README.md
CHANGED
|
@@ -1,138 +1,17 @@
|
|
|
1
1
|
# @sarj/eslint-plugin
|
|
2
2
|
|
|
3
|
-
Custom ESLint rules
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
3
|
+
Custom ESLint rules for hypermodern TypeScript / React / Next.js projects.
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
|
-
|
|
6
|
+
pnpm add -D @sarj/eslint-plugin
|
|
9
7
|
```
|
|
10
8
|
|
|
11
|
-
## Usage (ESLint 9+ Flat Config)
|
|
12
|
-
|
|
13
9
|
```js
|
|
14
|
-
// eslint.config.
|
|
15
|
-
import sarj
|
|
16
|
-
|
|
17
|
-
export default [
|
|
18
|
-
// Use a preset config
|
|
19
|
-
...configs.recommended,
|
|
20
|
-
|
|
21
|
-
// Or configure manually
|
|
22
|
-
{
|
|
23
|
-
plugins: {
|
|
24
|
-
"@sarj": sarj,
|
|
25
|
-
},
|
|
26
|
-
rules: {
|
|
27
|
-
"@sarj/zod-naming-convention": "warn",
|
|
28
|
-
"@sarj/require-assert-never": "error",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Available Configs
|
|
35
|
-
|
|
36
|
-
| Config | Description |
|
|
37
|
-
|--------|-------------|
|
|
38
|
-
| `configs.recommended` | Basic sarj rules for everyday use |
|
|
39
|
-
| `configs.strict` | All sarj rules at error level |
|
|
40
|
-
| `configs.style-guide` | Comprehensive rules (sarj + core ESLint) |
|
|
41
|
-
|
|
42
|
-
## Rules
|
|
43
|
-
|
|
44
|
-
| Rule | Description | Recommended |
|
|
45
|
-
|------|-------------|-------------|
|
|
46
|
-
| `@sarj/zod-naming-convention` | Enforce Zod schemas to be named with a Z prefix | warn |
|
|
47
|
-
| `@sarj/require-assert-never` | Require assertNever in switch default cases | error |
|
|
48
|
-
| `@sarj/require-zod-form-validation` | Require Zod validation when parsing FormData | error |
|
|
49
|
-
| `@sarj/enforce-file-structure` | Enforce consistent file structure | warn |
|
|
50
|
-
| `@sarj/no-raw-env` | Disallow direct process.env access | - |
|
|
51
|
-
| `@sarj/prefer-shadcn` | Prefer shadcn/ui components over native HTML | - |
|
|
52
|
-
| `@sarj/no-enum` | Disallow TypeScript enums | - |
|
|
53
|
-
|
|
54
|
-
## Rule Details
|
|
55
|
-
|
|
56
|
-
### `zod-naming-convention`
|
|
57
|
-
|
|
58
|
-
Ensures Zod schemas are named with a Z prefix for consistency.
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
// Bad
|
|
62
|
-
const userSchema = z.object({ name: z.string() });
|
|
63
|
-
|
|
64
|
-
// Good
|
|
65
|
-
const ZUserSchema = z.object({ name: z.string() });
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### `require-assert-never`
|
|
69
|
-
|
|
70
|
-
Ensures switch statements with default cases use assertNever for exhaustive type checking.
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
// Bad
|
|
74
|
-
switch (status) {
|
|
75
|
-
case "active":
|
|
76
|
-
return 1;
|
|
77
|
-
default:
|
|
78
|
-
return 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Good
|
|
82
|
-
switch (status) {
|
|
83
|
-
case "active":
|
|
84
|
-
return 1;
|
|
85
|
-
default:
|
|
86
|
-
assertNever(status);
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### `no-raw-env`
|
|
91
|
-
|
|
92
|
-
Disallows direct access to process.env. Use a Zod-validated env schema instead.
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
// Bad
|
|
96
|
-
const apiKey = process.env.API_KEY;
|
|
97
|
-
|
|
98
|
-
// Good
|
|
99
|
-
const apiKey = env.API_KEY; // from validated schema
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### `prefer-shadcn`
|
|
103
|
-
|
|
104
|
-
Encourages use of shadcn/ui components instead of native HTML elements.
|
|
105
|
-
|
|
106
|
-
```tsx
|
|
107
|
-
// Bad
|
|
108
|
-
<button onClick={handleClick}>Submit</button>
|
|
109
|
-
|
|
110
|
-
// Good
|
|
111
|
-
<Button onClick={handleClick}>Submit</Button>
|
|
10
|
+
// eslint.config.mjs
|
|
11
|
+
import sarj from "@sarj/eslint-plugin";
|
|
12
|
+
export default [...sarj.configs.recommended];
|
|
112
13
|
```
|
|
113
14
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Discourages TypeScript enums in favor of union types or const objects.
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
// Bad
|
|
120
|
-
enum Status {
|
|
121
|
-
Active,
|
|
122
|
-
Inactive,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Good
|
|
126
|
-
type Status = "active" | "inactive";
|
|
127
|
-
// or
|
|
128
|
-
const Status = { ACTIVE: "active", INACTIVE: "inactive" } as const;
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Requirements
|
|
132
|
-
|
|
133
|
-
- ESLint >= 9.0.0
|
|
134
|
-
- Node.js >= 18.0.0
|
|
135
|
-
|
|
136
|
-
## License
|
|
15
|
+
Each rule's source under `lib/rules/` carries its own `meta.docs.description` + `meta.messages` — read the file for full rationale.
|
|
137
16
|
|
|
138
|
-
|
|
17
|
+
Presets: `recommended` (warn-first), `strict` (every rule at error), `style-guide` (formatting/naming subset).
|