unguard 0.8.0 → 0.10.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 +80 -20
- package/dist/{chunk-YYX4R25B.js → chunk-5GVEUYZF.js} +1090 -408
- package/dist/chunk-5GVEUYZF.js.map +1 -0
- package/dist/cli.js +198 -50
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +95 -13
- package/dist/index.js +5 -1
- package/package.json +7 -3
- package/dist/chunk-YYX4R25B.js.map +0 -1
package/README.md
CHANGED
|
@@ -25,31 +25,71 @@ npx unguard
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
unguard src
|
|
29
|
-
unguard src --
|
|
30
|
-
unguard src --
|
|
31
|
-
unguard src --
|
|
32
|
-
unguard src --
|
|
33
|
-
unguard src --
|
|
28
|
+
unguard src # scan files/directories
|
|
29
|
+
unguard src --config ./unguard.config.json # load config
|
|
30
|
+
unguard src --ignore '**/*.gen.ts' # add ignore globs
|
|
31
|
+
unguard src --filter no-any-cast # run a single rule
|
|
32
|
+
unguard src --rule duplicate-*=warning # override rule severity/policy
|
|
33
|
+
unguard src --rule category:cross-file=warning
|
|
34
|
+
unguard src --rule tag:safety=error
|
|
35
|
+
unguard src --severity=error,warning # show errors+warnings
|
|
36
|
+
unguard src --fail-on=error # fail only on errors
|
|
37
|
+
unguard src --format=flat # one-line-per-diagnostic, grepable
|
|
34
38
|
unguard src --format=flat | grep error
|
|
35
39
|
```
|
|
36
40
|
|
|
37
41
|
Add `unguard` to your lint check, especially if code is written by AI.
|
|
38
42
|
|
|
43
|
+
### Config
|
|
44
|
+
|
|
45
|
+
`unguard` automatically loads `./unguard.config.json` (or `./.unguardrc.json`). Use `--config <path>` to specify another file.
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"paths": ["src", "apps/web/src"],
|
|
50
|
+
"ignore": ["**/*.gen.ts", "**/routeTree.gen.ts"],
|
|
51
|
+
"rules": {
|
|
52
|
+
"duplicate-*": "warning",
|
|
53
|
+
"category:cross-file": "warning",
|
|
54
|
+
"tag:safety": "error",
|
|
55
|
+
"no-ts-ignore": "error",
|
|
56
|
+
"prefer-*": "off"
|
|
57
|
+
},
|
|
58
|
+
"failOn": "error"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`rules` values can be `off`, `info`, `warning`, or `error`.
|
|
63
|
+
Selectors support:
|
|
64
|
+
- exact rule id: `no-ts-ignore`
|
|
65
|
+
- wildcard: `duplicate-*`
|
|
66
|
+
- category: `category:cross-file`
|
|
67
|
+
- tag: `tag:safety`
|
|
68
|
+
|
|
69
|
+
### Ignore behavior
|
|
70
|
+
|
|
71
|
+
`unguard` ignores:
|
|
72
|
+
- built-in: `node_modules`, `dist`, `.git`, declaration files (`*.d.ts`, `*.d.cts`, `*.d.mts`)
|
|
73
|
+
- generated files: `*.gen.*`, `*.generated.*`
|
|
74
|
+
- project `.gitignore`
|
|
75
|
+
- anything passed via `--ignore` or config `ignore`
|
|
76
|
+
|
|
39
77
|
### Exit codes
|
|
40
78
|
|
|
41
79
|
| Code | Meaning |
|
|
42
80
|
| ---- | ------- |
|
|
43
|
-
| 0 | No issues |
|
|
44
|
-
| 1 |
|
|
45
|
-
| 2 |
|
|
81
|
+
| 0 | No issues, or issues below `--fail-on` threshold |
|
|
82
|
+
| 1 | Failing diagnostics without errors |
|
|
83
|
+
| 2 | Failing diagnostics with at least one error |
|
|
46
84
|
|
|
47
|
-
Use `--
|
|
85
|
+
Use `--fail-on=error` in CI to fail only on errors while still showing all diagnostics:
|
|
48
86
|
|
|
49
87
|
```bash
|
|
50
|
-
unguard src --
|
|
88
|
+
unguard src --fail-on=error
|
|
51
89
|
```
|
|
52
90
|
|
|
91
|
+
`--severity` filters display only. `--fail-on` evaluates all diagnostics after rule policy.
|
|
92
|
+
|
|
53
93
|
### Output formats
|
|
54
94
|
|
|
55
95
|
**Grouped** (default) -- diagnostics grouped by file:
|
|
@@ -104,7 +144,6 @@ These rules use the TypeScript type checker. Non-nullable types suppress the dia
|
|
|
104
144
|
|
|
105
145
|
| Rule | Severity | What it catches |
|
|
106
146
|
| ---- | -------- | --------------- |
|
|
107
|
-
| `no-inline-type-in-params` | info | `fn(opts: { a: string; b: number })` |
|
|
108
147
|
| `prefer-default-param-value` | info | Optional param reassigned with `??` in the body |
|
|
109
148
|
| `prefer-required-param-with-guard` | info | `arg?: T` followed by `if (!arg) throw` |
|
|
110
149
|
|
|
@@ -112,10 +151,17 @@ These rules use the TypeScript type checker. Non-nullable types suppress the dia
|
|
|
112
151
|
|
|
113
152
|
| Rule | Severity | What it catches |
|
|
114
153
|
| ---- | -------- | --------------- |
|
|
115
|
-
| `duplicate-type-declaration` |
|
|
116
|
-
| `duplicate-type-name` |
|
|
117
|
-
| `duplicate-function-declaration` |
|
|
118
|
-
| `duplicate-function-name` |
|
|
154
|
+
| `duplicate-type-declaration` | warning | Same type shape in multiple files |
|
|
155
|
+
| `duplicate-type-name` | warning | Same exported type name, different shapes |
|
|
156
|
+
| `duplicate-function-declaration` | warning | Same function body in multiple files (2+ statements) |
|
|
157
|
+
| `duplicate-function-name` | warning | Same exported function name, different bodies |
|
|
158
|
+
| `duplicate-constant-declaration` | warning | Same constant value in multiple files |
|
|
159
|
+
| `duplicate-inline-type-in-params` | warning | Same inline `{ ... }` param type shape repeated 2+ times |
|
|
160
|
+
| `duplicate-file` | warning | File with identical content to another file |
|
|
161
|
+
| `near-duplicate-function` | warning | Function bodies identical after normalizing params, strings, numbers, `this` |
|
|
162
|
+
| `duplicate-statement-sequence` | info | Repeated contiguous statement blocks (3+ statements) |
|
|
163
|
+
| `trivial-wrapper` | info | Function that delegates to another without transformation |
|
|
164
|
+
| `unused-export` | info | Exported function with no usages in the project |
|
|
119
165
|
| `optional-arg-always-used` | warning | Optional param provided at every call site |
|
|
120
166
|
| `explicit-null-arg` | warning | `fn(null)` / `fn(undefined)` to project functions |
|
|
121
167
|
|
|
@@ -141,10 +187,24 @@ file.ts:2:31 error Explicit `any` annotation ... (intentional escape hatch for u
|
|
|
141
187
|
## API
|
|
142
188
|
|
|
143
189
|
```typescript
|
|
144
|
-
import { scan } from "unguard";
|
|
145
|
-
|
|
146
|
-
const result = await scan({ paths: ["src/"] });
|
|
147
|
-
|
|
190
|
+
import { executeScan, scan } from "unguard";
|
|
191
|
+
|
|
192
|
+
const result = await scan({ paths: ["src/"] }); // raw diagnostics
|
|
193
|
+
const execution = await executeScan({
|
|
194
|
+
paths: ["src"],
|
|
195
|
+
ignore: ["**/*.gen.ts"],
|
|
196
|
+
rulePolicy: {
|
|
197
|
+
"duplicate-*": "warning",
|
|
198
|
+
"category:cross-file": "warning",
|
|
199
|
+
"tag:safety": "error",
|
|
200
|
+
"prefer-*": "off",
|
|
201
|
+
},
|
|
202
|
+
showSeverities: ["error", "warning"],
|
|
203
|
+
failOn: "error",
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
console.log(execution.exitCode);
|
|
207
|
+
for (const d of execution.visibleDiagnostics) {
|
|
148
208
|
console.log(`${d.file}:${d.line} [${d.ruleId}] ${d.message}`);
|
|
149
209
|
}
|
|
150
210
|
```
|