@hailstails/hone 0.1.0-pre.3 → 0.1.0-pre.5
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/ADOPTING.md +44 -19
- package/MIGRATING.md +5 -5
- package/README.md +89 -24
- package/api/audit.d.ts +11 -0
- package/api/audit.mjs +1 -0
- package/api/rule-set.d.ts +4 -0
- package/api/rule-set.mjs +1 -0
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-7OVV6NEU.js +22 -0
- package/chunks/chunk-7PVPPH4C.js +13 -0
- package/chunks/chunk-HVABJ7T4.js +361 -0
- package/chunks/{chunk-TRCB27ET.js → chunk-IIMK5BCL.js} +55 -14
- package/chunks/{chunk-7ZJZZBSS.js → chunk-SWPCKTJV.js} +87 -380
- package/chunks/{chunk-HBY4ZWSP.js → chunk-VUG3DJHN.js} +7 -13
- package/chunks/{chunk-233U4FBA.js → chunk-YBWVUDIG.js} +1 -1
- package/core/check/tool-command.js +422 -115
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +13 -0
- package/core/mechanism-port/runner-result-types.d.ts +9 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/anchor.d.ts +10 -0
- package/core/values/branded.d.ts +5 -0
- package/core/values/clause-address-types.d.ts +9 -0
- package/core/values/identifier-types.d.ts +5 -0
- package/core/values/json-value.d.ts +6 -0
- package/core/values/repo-path-types.d.ts +2 -0
- package/core/values/result.d.ts +7 -0
- package/docs/adding-a-discipline-or-mechanism.md +8 -5
- package/docs/extending.md +357 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +82 -63
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-5/comments-directives.js +137 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +1 -0
- package/mechanisms/audit/runner/runner.js +39 -33
- package/mechanisms/audit/runner/typescript-parse.d.ts +26 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +60 -0
- package/mechanisms/eslint/runner/README.md +1 -1
- package/mechanisms/eslint/runner/eslint-piece-settings-types.d.ts +8 -0
- package/mechanisms/eslint/runner/runner.js +137 -71
- package/package.json +20 -3
- package/rules/CD-1/README.md +5 -5
- package/rules/CD-1/discipline.json +16 -6
- package/rules/CD-19/README.md +13 -3
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/README.md +8 -4
- package/rules/CD-2/discipline.json +25 -7
- package/rules/CD-5/README.md +17 -5
- package/rules/CD-5/discipline.json +66 -0
|
@@ -37,15 +37,25 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
3
|
|
39
39
|
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "array of any over a property value",
|
|
43
|
+
"fileName": "array-of-any.ts",
|
|
44
|
+
"source": "declare const result: { readonly value: unknown };\nexport const rows = result.value as Array<any>;\n",
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
2
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "record of any",
|
|
51
|
+
"fileName": "record-of-any.ts",
|
|
52
|
+
"source": "declare const candidate: unknown;\nexport const fields = candidate as Record<string, any>;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
2
|
|
55
|
+
]
|
|
40
56
|
}
|
|
41
57
|
],
|
|
42
58
|
"allow": [
|
|
43
|
-
{
|
|
44
|
-
"name": "as unknown assertion",
|
|
45
|
-
"fileName": "unknown.ts",
|
|
46
|
-
"source": "export const parsed = JSON.parse(text) as unknown;\n",
|
|
47
|
-
"expectedLines": []
|
|
48
|
-
},
|
|
49
59
|
{
|
|
50
60
|
"name": "const assertion",
|
|
51
61
|
"fileName": "const-assertion.ts",
|
package/rules/CD-19/README.md
CHANGED
|
@@ -10,17 +10,27 @@ The sections below describe what the audit check covers.
|
|
|
10
10
|
|
|
11
11
|
| Clause | Mechanism | Checks |
|
|
12
12
|
| --- | --- | --- |
|
|
13
|
-
| `CD-19#import-boundaries` | audit | imports of
|
|
13
|
+
| `CD-19#import-boundaries` | audit | imports of the packages the repository confines, and any `node:` import |
|
|
14
14
|
|
|
15
15
|
Review lens: [function-first](../../methods/lenses/function-first.md). The lens reviews the whole rule, including what no check flags.
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- A line with `from "<
|
|
19
|
+
- A line with `from "<specifier>"` where the specifier is a package listed in the clause's `confinedPackages` setting (see [Settings](#settings)) or a subpath of one: `hono` covers `hono` and `hono/cors`, and `@scope/name` covers `@scope/name` and `@scope/name/client`. A longer name is a different package, so `hono` does not cover `honox` or `hono-extra`. With no packages listed, which is the default, no library import is flagged. Type-only imports and matches inside strings are flagged too.
|
|
20
20
|
- A `node:` specifier in an import, `export ... from`, `import("node:...")`, `import type`, `import x = require(...)` or `require("node:...")`. Unprefixed `fs` is not detected.
|
|
21
|
-
- The source rule covers every third-party dependency; the check covers only the
|
|
21
|
+
- The source rule covers every third-party dependency; the check covers only the listed packages. The rest is left to review.
|
|
22
|
+
|
|
23
|
+
## Settings
|
|
24
|
+
List each package the repository confines behind a wrapping port in `disciplines.json`, then record each wrapping file as an `authorised-location`:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
"clauseSettings": {
|
|
28
|
+
"CD-19#import-boundaries": { "confinedPackages": ["winston", "uuid"] }
|
|
29
|
+
}
|
|
30
|
+
```
|
|
22
31
|
|
|
23
32
|
## Example violation
|
|
33
|
+
With `"confinedPackages": ["uuid"]`, both lines are flagged; with the default, only the first.
|
|
24
34
|
```ts
|
|
25
35
|
import { readFileSync } from "node:fs";
|
|
26
36
|
import { v4 } from "uuid";
|
|
@@ -14,14 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"cases": {
|
|
16
16
|
"flag": [
|
|
17
|
-
{
|
|
18
|
-
"name": "banned library import",
|
|
19
|
-
"fileName": "imports-winston.ts",
|
|
20
|
-
"source": "import winston from \"winston\";\n\nexport const useWinston = (): unknown => winston;\n",
|
|
21
|
-
"expectedLines": [
|
|
22
|
-
1
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
17
|
{
|
|
26
18
|
"name": "node: import",
|
|
27
19
|
"fileName": "reads-file.ts",
|
|
@@ -40,6 +32,12 @@
|
|
|
40
32
|
}
|
|
41
33
|
],
|
|
42
34
|
"allow": [
|
|
35
|
+
{
|
|
36
|
+
"name": "library import while no specifier is confined",
|
|
37
|
+
"fileName": "imports-winston.ts",
|
|
38
|
+
"source": "import winston from \"winston\";\n\nexport const useWinston = (): unknown => winston;\n",
|
|
39
|
+
"expectedLines": []
|
|
40
|
+
},
|
|
43
41
|
{
|
|
44
42
|
"name": "project-owned import",
|
|
45
43
|
"fileName": "own.ts",
|
package/rules/CD-2/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
A type assertion tells the compiler the value is something the compiler cannot see — it is a claim the type system can no longer check. Casting is therefore permitted only at a closed, enumerated list of sites where an external boundary genuinely forces it
|
|
5
|
+
A type assertion tells the compiler the value is something the compiler cannot see — it is a claim the type system can no longer check. Casting is therefore permitted only at a closed, enumerated list of sites where an external boundary genuinely forces it, each one an exception record for the file at that boundary. Everywhere else a cast is a design smell: the type is wrong, so fix the type rather than assert over it. Adding a site to the permitted list is a deliberate, recorded amendment, not an inline decision.
|
|
6
6
|
|
|
7
7
|
The sections below describe what the audit check covers.
|
|
8
8
|
|
|
@@ -16,9 +16,11 @@ Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens
|
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- Every `x as T` and `<T>x` assertion except
|
|
20
|
-
-
|
|
21
|
-
-
|
|
19
|
+
- Every `x as T` and `<T>x` assertion except a const assertion, `as const` or `<const>x`. Assertions whose type contains `any` are CD-1's and are not repeated here.
|
|
20
|
+
- `as unknown` and `<unknown>x` are flagged. Widening never needs an assertion: annotate instead, `const parsed: unknown = JSON.parse(text)`.
|
|
21
|
+
- A cast through `unknown`, such as `raw as unknown as User`, `(<unknown>raw) as User` or one wrapped in `!` or `satisfies`, is flagged with its own message, and so is its `unknown` half. It is the escape hatch that turns any value into any type; check the value's shape at runtime at the boundary instead.
|
|
22
|
+
- Test files, test helpers and scripts are checked like any other source; a test that needs a cast needs a typed fake or a narrower port.
|
|
23
|
+
- There are no settings: a boundary that forces a cast is an exception record, as below.
|
|
22
24
|
|
|
23
25
|
## Example violation
|
|
24
26
|
```ts
|
|
@@ -31,6 +33,8 @@ const user = userSchema.parse(response);
|
|
|
31
33
|
```
|
|
32
34
|
Parse or narrow the value so the type follows from a check rather than from an assertion.
|
|
33
35
|
|
|
36
|
+
When handing a value across a boundary truly forces a cast, such as a library that types its schemas loosely or a database driver that returns unparsed rows, put the cast in the one adapter file at that boundary and record that file as an `authorised-location` with a why-chain. With clean boundaries that is one file and one record; casts scattered across many files are the sign the boundary is missing.
|
|
37
|
+
|
|
34
38
|
## Exceptions
|
|
35
39
|
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file sits on an external boundary that forces an assertion, such as an adapter. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
36
40
|
|
|
@@ -37,15 +37,33 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
3
|
|
39
39
|
]
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
"allow": [
|
|
40
|
+
},
|
|
43
41
|
{
|
|
44
42
|
"name": "as unknown",
|
|
45
43
|
"fileName": "unknown.ts",
|
|
46
44
|
"source": "export const parsed = JSON.parse(text) as unknown;\n",
|
|
47
|
-
"expectedLines": [
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
1
|
|
47
|
+
]
|
|
48
48
|
},
|
|
49
|
+
{
|
|
50
|
+
"name": "double cast through unknown",
|
|
51
|
+
"fileName": "double-cast.ts",
|
|
52
|
+
"source": "interface User { readonly id: string }\ndeclare const raw: string;\nexport const user = raw as unknown as User;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
3
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "as a name imported from a package",
|
|
59
|
+
"fileName": "package-type-cast.ts",
|
|
60
|
+
"source": "import { z } from \"zod\";\ndeclare const raw: unknown;\nexport const schema = raw as z;\n",
|
|
61
|
+
"expectedLines": [
|
|
62
|
+
3
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"allow": [
|
|
49
67
|
{
|
|
50
68
|
"name": "as const",
|
|
51
69
|
"fileName": "const-assertion.ts",
|
|
@@ -53,9 +71,9 @@
|
|
|
53
71
|
"expectedLines": []
|
|
54
72
|
},
|
|
55
73
|
{
|
|
56
|
-
"name": "
|
|
57
|
-
"fileName": "
|
|
58
|
-
"source": "
|
|
74
|
+
"name": "angle-bracket const",
|
|
75
|
+
"fileName": "angle-const-assertion.ts",
|
|
76
|
+
"source": "export const PERMITTED_LITERAL = <const>\"permitted\";\n",
|
|
59
77
|
"expectedLines": []
|
|
60
78
|
}
|
|
61
79
|
]
|
package/rules/CD-5/README.md
CHANGED
|
@@ -16,12 +16,24 @@ Review lens: [naming](../../methods/lenses/naming.md). The lens reviews the whol
|
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- `// TODO` not followed
|
|
20
|
-
- A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment
|
|
21
|
-
-
|
|
22
|
-
-
|
|
19
|
+
- `// TODO` not followed, after optional spaces, by a tracked reference, for example `// TODO(#42) ...`.
|
|
20
|
+
- A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment carries a tracked reference.
|
|
21
|
+
- A TypeScript directive without a tracked reference after it, in each form the compiler honours: `@ts-expect-error` or `@ts-ignore` opening a `//` or `///` comment, or opening the last line of a block comment after any `/` and `*`; and `@ts-nocheck`, in any letter case, opening a `//` or `///` comment among the comments that start the file. As in the compiler, `@ts-ignore` and `@ts-expect-error` are matched as written, so `@ts-ignored` counts and `@Ts-Ignore` does not. Forms the compiler ignores, such as `/* @ts-nocheck */`, a directive above a block comment's closing line, or `////`, are not flagged. `@ts-check` turns checking on and is not flagged.
|
|
22
|
+
- A tracked reference is a parenthesised token with no spaces that contains a digit, such as `(#42)`, `(PROJ-7)`, `(spec-42)` or `(https://tracker.example/issues/42)`. `()`, `(legacy)` and `(issue 42)` are not tracked references.
|
|
23
|
+
- TODO is matched on raw lines, so the same text inside a string is flagged too; linter and type directives are read from comments only.
|
|
23
24
|
- Ordinary explanatory comments and JSDoc are not flagged; keeping them out is left to review.
|
|
24
25
|
|
|
26
|
+
## Settings
|
|
27
|
+
`trackerPatterns` narrows which tracked references count, for example to your own tracker's format. Each entry is a regular expression, as JavaScript source text, tested against each tracked reference with its parentheses; a reference counts when any entry matches. The test is an unanchored search unless the pattern anchors itself with `^` and `$`. The default, `["^\\(\\S+\\)$"]`, lets every tracked reference count.
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
"clauseSettings": {
|
|
31
|
+
"CD-5#comments-directives": { "trackerPatterns": ["^\\(spec-\\d+\\)$", "^\\(#\\d+\\)$"] }
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The patterns only narrow: a reference must still be a parenthesised token with no spaces that contains a digit, so a pattern such as `.*` cannot make `(legacy)` count. The same measure applies to TODO, where the reference must come right after `TODO`. Each entry must be a non-empty string that compiles as a regular expression; otherwise the check stops with a piece-invalid failure naming the clause and the entry.
|
|
36
|
+
|
|
25
37
|
## Example violation
|
|
26
38
|
```ts
|
|
27
39
|
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
@@ -32,7 +44,7 @@ const first = items[0]!;
|
|
|
32
44
|
```ts
|
|
33
45
|
const first = items[0];
|
|
34
46
|
```
|
|
35
|
-
Remove the need for the directive. If it must stay, add the
|
|
47
|
+
Remove the need for the directive. If it must stay, add the tracked reference: `// biome-ignore lint/style/noNonNullAssertion: legacy (#42)`.
|
|
36
48
|
|
|
37
49
|
## Exceptions
|
|
38
50
|
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file legitimately carries untracked directives, such as generated code. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
@@ -37,6 +37,54 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
1
|
|
39
39
|
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "eslint-disable with blank parentheses",
|
|
43
|
+
"fileName": "blank-tracker.ts",
|
|
44
|
+
"source": "// eslint-disable-next-line no-console ( )\nconsole.log(1);\n",
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
1
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "biome-ignore with a word in parentheses",
|
|
51
|
+
"fileName": "word-tracker.ts",
|
|
52
|
+
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (legacy)\nexport const portNumber = 8080;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
1
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "todo with empty parentheses",
|
|
59
|
+
"fileName": "empty-todo.ts",
|
|
60
|
+
"source": "// TODO() rename this\nexport const someValue = 1;\n",
|
|
61
|
+
"expectedLines": [
|
|
62
|
+
1
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "ts-ignore without tracker",
|
|
67
|
+
"fileName": "ts-ignore.ts",
|
|
68
|
+
"source": "// @ts-ignore\nexport const broken: number = \"text\";\n",
|
|
69
|
+
"expectedLines": [
|
|
70
|
+
1
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "ts-nocheck in a triple-slash comment without tracker",
|
|
75
|
+
"fileName": "ts-nocheck.ts",
|
|
76
|
+
"source": "/// @ts-nocheck\nexport const broken: number = \"text\";\n",
|
|
77
|
+
"expectedLines": [
|
|
78
|
+
1
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "ts-ignore on the last line of a block comment without tracker",
|
|
83
|
+
"fileName": "block-ts-ignore.ts",
|
|
84
|
+
"source": "/*\n * legacy shape\n * @ts-ignore */\nexport const broken: number = \"text\";\n",
|
|
85
|
+
"expectedLines": [
|
|
86
|
+
1
|
|
87
|
+
]
|
|
40
88
|
}
|
|
41
89
|
],
|
|
42
90
|
"allow": [
|
|
@@ -52,6 +100,24 @@
|
|
|
52
100
|
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (spec-7)\nexport const portNumber = 8080;\n",
|
|
53
101
|
"expectedLines": []
|
|
54
102
|
},
|
|
103
|
+
{
|
|
104
|
+
"name": "biome-ignore with issue reference",
|
|
105
|
+
"fileName": "issue-ignore.ts",
|
|
106
|
+
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (#42)\nexport const portNumber = 8080;\n",
|
|
107
|
+
"expectedLines": []
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "ts-expect-error with ticket reference",
|
|
111
|
+
"fileName": "tracked-expect-error.ts",
|
|
112
|
+
"source": "// @ts-expect-error legacy shape (PROJ-7)\nexport const broken: number = \"text\";\n",
|
|
113
|
+
"expectedLines": []
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "ts-nocheck in a block comment, which TypeScript does not honour",
|
|
117
|
+
"fileName": "block-ts-nocheck.ts",
|
|
118
|
+
"source": "/* @ts-nocheck */\nexport const checked: number = 1;\n",
|
|
119
|
+
"expectedLines": []
|
|
120
|
+
},
|
|
55
121
|
{
|
|
56
122
|
"name": "ordinary comment is left to review",
|
|
57
123
|
"fileName": "plain.ts",
|