unguard 0.7.0 → 0.8.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 +30 -21
- package/dist/chunk-YYX4R25B.js +1519 -0
- package/dist/chunk-YYX4R25B.js.map +1 -0
- package/dist/cli.js +23 -34
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +27 -19
- package/dist/index.js +1 -1
- package/package.json +3 -6
- package/dist/chunk-NYM4SO7V.js +0 -1213
- package/dist/chunk-NYM4SO7V.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Unguard your code. Defend against overdefensive AI-generated code.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Type-aware static analysis powered by the TypeScript compiler API.
|
|
6
|
+
|
|
7
|
+
If `??` is on a non-nullable type, you don't need it.
|
|
8
|
+
|
|
9
|
+
If `?.` is on a guaranteed object, it's noise.
|
|
10
|
+
|
|
11
|
+
unguard proves it with types.
|
|
6
12
|
|
|
7
13
|
## Install
|
|
8
14
|
|
|
@@ -19,15 +25,16 @@ npx unguard
|
|
|
19
25
|
## Usage
|
|
20
26
|
|
|
21
27
|
```bash
|
|
22
|
-
unguard src
|
|
23
|
-
unguard src
|
|
24
|
-
unguard src
|
|
25
|
-
unguard src
|
|
26
|
-
unguard src
|
|
27
|
-
unguard src
|
|
28
|
+
unguard src
|
|
29
|
+
unguard src --strict # treat warnings as errors (CI)
|
|
30
|
+
unguard src --filter no-any-cast # run a single rule
|
|
31
|
+
unguard src --severity=error # only show errors
|
|
32
|
+
unguard src --severity=error,warning # errors and warnings only
|
|
33
|
+
unguard src --format=flat # one-line-per-diagnostic, grepable
|
|
34
|
+
unguard src --format=flat | grep error
|
|
28
35
|
```
|
|
29
36
|
|
|
30
|
-
Add `unguard` to your lint check.
|
|
37
|
+
Add `unguard` to your lint check, especially if code is written by AI.
|
|
31
38
|
|
|
32
39
|
### Exit codes
|
|
33
40
|
|
|
@@ -40,19 +47,19 @@ Add `unguard` to your lint check.
|
|
|
40
47
|
Use `--severity=error` in CI to only fail on errors:
|
|
41
48
|
|
|
42
49
|
```bash
|
|
43
|
-
unguard src
|
|
50
|
+
unguard src --severity=error || exit 1
|
|
44
51
|
```
|
|
45
52
|
|
|
46
53
|
### Output formats
|
|
47
54
|
|
|
48
|
-
**Grouped** (default)
|
|
55
|
+
**Grouped** (default) -- diagnostics grouped by file:
|
|
49
56
|
|
|
50
57
|
```txt
|
|
51
58
|
src/lib/probe.ts
|
|
52
59
|
37:4 error Empty catch blocks hide failures... no-empty-catch
|
|
53
60
|
```
|
|
54
61
|
|
|
55
|
-
**Flat** (`--format=flat`)
|
|
62
|
+
**Flat** (`--format=flat`) -- one line per diagnostic, grepable:
|
|
56
63
|
|
|
57
64
|
```txt
|
|
58
65
|
src/lib/probe.ts:37:4 error [no-empty-catch] Empty catch blocks hide failures...
|
|
@@ -69,26 +76,28 @@ src/lib/probe.ts:37:4 error [no-empty-catch] Empty catch blocks hide failures...
|
|
|
69
76
|
| `no-type-assertion` | error | `x as unknown as T` |
|
|
70
77
|
| `no-ts-ignore` | error | `@ts-ignore` / `@ts-expect-error` |
|
|
71
78
|
|
|
72
|
-
### Defensive code
|
|
79
|
+
### Defensive code (type-aware)
|
|
80
|
+
|
|
81
|
+
These rules use the TypeScript type checker. Non-nullable types suppress the diagnostic; nullable types are flagged.
|
|
73
82
|
|
|
74
83
|
| Rule | Severity | What it catches |
|
|
75
84
|
| ---- | -------- | --------------- |
|
|
76
|
-
| `no-optional-property-access` |
|
|
77
|
-
| `no-optional-element-access` |
|
|
78
|
-
| `no-optional-call` |
|
|
79
|
-
| `no-nullish-coalescing` |
|
|
80
|
-
| `no-logical-or-fallback` | warning | `
|
|
85
|
+
| `no-optional-property-access` | warning | `obj?.prop` on a non-nullable type |
|
|
86
|
+
| `no-optional-element-access` | warning | `obj?.[key]` on a non-nullable type |
|
|
87
|
+
| `no-optional-call` | warning | `fn?.()` on a non-nullable type |
|
|
88
|
+
| `no-nullish-coalescing` | warning | `x ?? fallback` on a non-nullable type |
|
|
89
|
+
| `no-logical-or-fallback` | warning | `map.get(k) \|\| fallback` -- data-structure lookups where `??` is correct; `\|\|` on numeric types that swallow `0` |
|
|
81
90
|
| `no-null-ternary-normalization` | warning | `x == null ? fallback : x` |
|
|
82
|
-
| `no-non-null-assertion` | warning | `x!` |
|
|
91
|
+
| `no-non-null-assertion` | warning | `x!` on a nullable type without a local narrowing guard |
|
|
83
92
|
| `no-double-negation-coercion` | info | `!!value` |
|
|
84
|
-
| `no-redundant-existence-guard` | warning | `obj && obj.prop` |
|
|
93
|
+
| `no-redundant-existence-guard` | warning | `obj && obj.prop` on a non-nullable type |
|
|
85
94
|
|
|
86
95
|
### Error handling
|
|
87
96
|
|
|
88
97
|
| Rule | Severity | What it catches |
|
|
89
98
|
| ---- | -------- | --------------- |
|
|
90
|
-
| `no-empty-catch` | error | `catch {}` with no body
|
|
91
|
-
| `no-catch-return` | warning | `catch { return fallback }`
|
|
99
|
+
| `no-empty-catch` | error | `catch {}` with no body and no comment |
|
|
100
|
+
| `no-catch-return` | warning | `catch { return fallback }` with no logging or rethrow |
|
|
92
101
|
| `no-error-rewrap` | error | `throw new Error(e.message)` without `{ cause: e }` |
|
|
93
102
|
|
|
94
103
|
### Interface design
|