@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.6
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 +172 -38
- package/MIGRATING.md +58 -7
- package/README.md +117 -35
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/api/audit.d.ts +3 -2
- package/api/rule-set.d.ts +2 -4
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-5LCLBXP7.js +76 -0
- package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
- package/chunks/chunk-LDQUT742.js +15 -0
- package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
- package/chunks/chunk-MVK5KFJI.js +421 -0
- package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
- package/chunks/chunk-WPRR2MPJ.js +22 -0
- package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
- package/core/check/tool-command.js +1130 -230
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +5 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/json-value.d.ts +3 -0
- package/docs/adding-a-discipline-or-mechanism.md +29 -13
- package/docs/extending.md +358 -0
- package/docs/output-contract.md +326 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-2/piece.json +6 -1
- package/mechanisms/audit/CD-5/comments-directives.js +121 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +4 -2
- package/mechanisms/audit/runner/runner.js +102 -36
- package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
- package/mechanisms/eslint/CD-2/README.md +12 -0
- package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-2/piece.json +25 -0
- package/mechanisms/eslint/runner/README.md +12 -5
- package/mechanisms/eslint/runner/runner.js +940 -232
- package/methods/README.md +2 -0
- package/methods/assessment-template.md +35 -0
- package/methods/lenses/clean-architecture.md +2 -2
- package/methods/lenses/decomposition.md +2 -2
- package/methods/lenses/defended-on-intent.md +7 -7
- package/methods/lenses/di-discipline.md +38 -26
- package/methods/lenses/errors-as-data.md +2 -2
- package/methods/lenses/function-first.md +2 -2
- package/methods/lenses/naming.md +2 -2
- package/methods/lenses/test-discipline.md +15 -13
- package/methods/lenses/type-soundness.md +2 -2
- package/methods/lenses/zod-boundary.md +2 -2
- package/package.json +5 -4
- package/rules/CD-1/CHECKS.md +37 -0
- package/rules/CD-1/README.md +17 -32
- package/rules/CD-1/discipline.json +16 -6
- package/rules/CD-10/CHECKS.md +49 -0
- package/rules/CD-10/README.md +21 -49
- package/rules/CD-11/CHECKS.md +13 -0
- package/rules/CD-11/README.md +14 -8
- package/rules/CD-12/CHECKS.md +13 -0
- package/rules/CD-12/README.md +14 -8
- package/rules/CD-13/CHECKS.md +13 -0
- package/rules/CD-13/README.md +14 -8
- package/rules/CD-14/CHECKS.md +49 -0
- package/rules/CD-14/README.md +22 -48
- package/rules/CD-15/CHECKS.md +40 -0
- package/rules/CD-15/README.md +22 -40
- package/rules/CD-16/CHECKS.md +7 -0
- package/rules/CD-16/README.md +3 -5
- package/rules/CD-17/CHECKS.md +37 -0
- package/rules/CD-17/README.md +17 -31
- package/rules/CD-18/CHECKS.md +13 -0
- package/rules/CD-18/README.md +15 -9
- package/rules/CD-19/CHECKS.md +49 -0
- package/rules/CD-19/README.md +18 -34
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/CHECKS.md +56 -0
- package/rules/CD-2/README.md +19 -32
- package/rules/CD-2/discipline.json +93 -7
- package/rules/CD-20/CHECKS.md +7 -0
- package/rules/CD-20/README.md +3 -5
- package/rules/CD-21/CHECKS.md +13 -0
- package/rules/CD-21/README.md +14 -9
- package/rules/CD-22/CHECKS.md +13 -0
- package/rules/CD-22/README.md +13 -8
- package/rules/CD-23/CHECKS.md +35 -0
- package/rules/CD-23/README.md +14 -29
- package/rules/CD-24/CHECKS.md +7 -0
- package/rules/CD-24/README.md +3 -5
- package/rules/CD-25/CHECKS.md +38 -0
- package/rules/CD-25/README.md +20 -32
- package/rules/CD-26/CHECKS.md +36 -0
- package/rules/CD-26/README.md +18 -31
- package/rules/CD-27/CHECKS.md +45 -0
- package/rules/CD-27/README.md +18 -40
- package/rules/CD-28/CHECKS.md +13 -0
- package/rules/CD-28/README.md +14 -8
- package/rules/CD-29/CHECKS.md +13 -0
- package/rules/CD-29/README.md +12 -8
- package/rules/CD-3/CHECKS.md +42 -0
- package/rules/CD-3/README.md +20 -42
- package/rules/CD-30/CHECKS.md +13 -0
- package/rules/CD-30/README.md +13 -8
- package/rules/CD-31/CHECKS.md +13 -0
- package/rules/CD-31/README.md +12 -8
- package/rules/CD-32/CHECKS.md +13 -0
- package/rules/CD-32/README.md +13 -8
- package/rules/CD-33/CHECKS.md +13 -0
- package/rules/CD-33/README.md +13 -8
- package/rules/CD-34/CHECKS.md +13 -0
- package/rules/CD-34/README.md +12 -8
- package/rules/CD-39/CHECKS.md +13 -0
- package/rules/CD-39/README.md +13 -8
- package/rules/CD-4/CHECKS.md +13 -0
- package/rules/CD-4/README.md +15 -8
- package/rules/CD-40/CHECKS.md +39 -0
- package/rules/CD-40/README.md +17 -33
- package/rules/CD-41/CHECKS.md +54 -0
- package/rules/CD-41/README.md +23 -54
- package/rules/CD-42/CHECKS.md +47 -0
- package/rules/CD-42/README.md +19 -47
- package/rules/CD-43/CHECKS.md +37 -0
- package/rules/CD-43/README.md +15 -31
- package/rules/CD-44/CHECKS.md +48 -0
- package/rules/CD-44/README.md +20 -48
- package/rules/CD-45/CHECKS.md +13 -0
- package/rules/CD-45/README.md +14 -8
- package/rules/CD-46/CHECKS.md +7 -0
- package/rules/CD-46/README.md +16 -4
- package/rules/CD-47/CHECKS.md +37 -0
- package/rules/CD-47/README.md +16 -32
- package/rules/CD-5/CHECKS.md +52 -0
- package/rules/CD-5/README.md +22 -40
- package/rules/CD-5/discipline.json +66 -0
- package/rules/CD-6/CHECKS.md +51 -0
- package/rules/CD-6/README.md +22 -51
- package/rules/CD-7/CHECKS.md +46 -0
- package/rules/CD-7/README.md +23 -46
- package/rules/CD-7a/CHECKS.md +38 -0
- package/rules/CD-7a/README.md +14 -32
- package/rules/CD-8/CHECKS.md +42 -0
- package/rules/CD-8/README.md +20 -42
- package/rules/CD-9/CHECKS.md +13 -0
- package/rules/CD-9/README.md +15 -8
- package/rules/README.md +5 -3
- package/rules/SPIRIT.md +50 -0
- package/core/mechanism-port/runner-failure-types.d.ts +0 -38
- package/core/rule-set-reader/rule-set-types.d.ts +0 -41
- /package/api/{audit.js → audit.mjs} +0 -0
- /package/api/{rule-set.js → rule-set.mjs} +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Output contract
|
|
2
|
+
|
|
3
|
+
This page lists everything the `hone` command prints, exactly as it prints it: the help, the version, the report, the load failures and the `hone project` lines. It says which parts a hook, CI job or agent can parse and rely on. [Compatibility](../README.md#compatibility) says which releases may change them.
|
|
4
|
+
|
|
5
|
+
A test renders every kind of line the command can print, fills each template below with that line's own sample values, and requires the result to equal the printed line exactly: a line Hone can print that is not listed here fails the build, and so does a line listed here that Hone cannot print. The synopsis and help blocks below are compared with what the command prints, character for character.
|
|
6
|
+
|
|
7
|
+
## Streams and exit codes
|
|
8
|
+
|
|
9
|
+
Hone prints everything to standard output: the report, the help, the version, `hone project` lines and every load failure, including an error Hone did not expect. Hone writes nothing to standard error itself; Node can write its own warnings there, so a hook should not read output on standard error as a failure.
|
|
10
|
+
|
|
11
|
+
The exit code is the signal a hook should act on:
|
|
12
|
+
|
|
13
|
+
- `0`: `hone check` printed `verdict: pass`, `hone project` wrote or confirmed every projection, or help or the version was printed;
|
|
14
|
+
- `1`: `hone check` printed `verdict: fail` as its last line. Exit `1` always comes with that line, and with nothing else;
|
|
15
|
+
- `2`: Hone could not decide. It printed exactly one line, starting with `load failure: `, and no verdict. That covers a command typed wrongly, an input that could not be loaded, a mechanism that failed, and an error Hone did not expect, which prints as `unexpected-error`.
|
|
16
|
+
|
|
17
|
+
A 1.0 hook can rely on this: run `hone check`, block on any non-zero exit, and show standard output as it came.
|
|
18
|
+
|
|
19
|
+
## What a tool can parse
|
|
20
|
+
|
|
21
|
+
A tool can rely on these, and a change to any of them is a major release:
|
|
22
|
+
|
|
23
|
+
- the command names, option names, option values, exit codes and streams above;
|
|
24
|
+
- the verdict line, which is always the last line of a `hone check` report and is one of the four lines under [The report](#the-report);
|
|
25
|
+
- the section names, their order and roles, the heading and count lines, and the output modes;
|
|
26
|
+
- the first word of a load failure after `load failure: `, its kind;
|
|
27
|
+
- in each line below, the fixed words and values up to the first value that may hold a space, and the single spaces between them.
|
|
28
|
+
|
|
29
|
+
The values in the [table of values](#values) marked "may hold a space" can contain spaces, and Hone does not quote or escape them. Everything from the first such value to the end of the line is one piece of text: a tool cannot split it into fields, and should not try. For a finding, a tool can read the clause and the mechanism; the file, position and snippet that follow are for a person. Hone has no machine-readable report yet, so a tool that needs each finding's file and position has nothing stable to read them from.
|
|
30
|
+
|
|
31
|
+
These are not stable, so a minor release may change them:
|
|
32
|
+
|
|
33
|
+
- the help text, though the synopsis and the exit codes it lists are stable;
|
|
34
|
+
- the text of a `<detail>`, which comes from Node, git, ESLint or a schema check;
|
|
35
|
+
- the wording after `load failure: arguments-invalid`, written for the person who typed the command;
|
|
36
|
+
- the text after a load failure's values, which says what to do next: the repair text of `selection-absent`, `judgement-clause-listed` and `config-root-untracked`, and everything after the kind in `toolchain-unavailable` and `toolchain-shadowed`;
|
|
37
|
+
- the `readFirst` lines and their leading note, written for a person;
|
|
38
|
+
- the words of an `unmeasured` or `projectionProblems` line after the `:` that ends its leading fields (its kind and reason, or its mechanism, state and slice), which say why and what to do next.
|
|
39
|
+
|
|
40
|
+
A minor release may add a section, a kind of line in a section, a load failure kind, an option or a command. A tool reading the report should pass over a section heading or a line kind it does not know.
|
|
41
|
+
|
|
42
|
+
## Values
|
|
43
|
+
|
|
44
|
+
In the tables below, a word in angle brackets, such as `<clause>`, stands for a value; everything else is printed as shown. Every line ends with a line feed. A value that holds a line break prints it as `\n` or `\r`, so each entry and each load failure stays on one line.
|
|
45
|
+
|
|
46
|
+
| Value | Printed as | Space |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `<clause>` | in the report, a clause address: `CD-15#loops` for Hone's own rule set, `<rule set>/<ID>#<clause>` for a team's; in a load failure, the address as written in `disciplines.json` | never in the report; may hold a space in a load failure |
|
|
49
|
+
| `<mechanism>` | a mechanism id, such as `audit` or `eslint` | never |
|
|
50
|
+
| `<record kind>`, `<section>`, `<package>` | a word from the lines below, a section name, or an npm package name | never |
|
|
51
|
+
| `<line>`, `<column>` | a 1-based line and a 0-based column | never |
|
|
52
|
+
| `<count>`, `<index>`, `<earlier index>` | a whole number; an index counts from 0 | never |
|
|
53
|
+
| `<version>` | the installed package's version | never |
|
|
54
|
+
| `<file>`, `<path>`, `<slice>`, `<suppressions file>`, `<package file>`, `<config root>`, `<piece folder>`, `<location>`, `<install folder>`, `<rule page>`, `<adoption guide>` | a path, as described below | may hold a space |
|
|
55
|
+
| `<folders>` | paths separated by `, ` | may hold a space |
|
|
56
|
+
| `<folder>` | the folder that holds a `<slice>` | may hold a space |
|
|
57
|
+
| `<project command>` | the command that runs `hone project` for this repository: `node`, the installed command's absolute path, `project --repo` and the repository's absolute path, each path with forward slashes and in double quotes when it holds a character other than a letter, digit or one of `_ . / @ : + -` | may hold a space |
|
|
58
|
+
| `<revision>`, `<git message>` | the `--base-revision` value as given and what git said, each as a JSON string in double quotes | may hold a space |
|
|
59
|
+
| `<dir>` | the `--repo` value as typed | may hold a space |
|
|
60
|
+
| `<url>` | the module URL Hone could not resolve, as given | may hold a space |
|
|
61
|
+
| `<snippet>` | the source text at a finding: at most 200 characters, or the first 200 followed by `…` when it is longer | may hold a space |
|
|
62
|
+
| `<comment>`, `<script>`, `<option>`, `<source>` | the native exception's comment, the `package.json` script name and the option in it, or where an imported record came from | may hold a space |
|
|
63
|
+
| `<detail>`, `<given>`, `<values>`, `<rule set>`, `<other rule set>`, `<clause with its rule set>`, `<version found>`, `<other package>`, `<range>` | text from the input, a tool or the command as typed | may hold a space |
|
|
64
|
+
|
|
65
|
+
Paths are printed with forward slashes. A path inside the `--repo` folder is printed relative to it, in the report and in load failures alike. A path outside it is printed absolute, such as `C:/Users/me/shared/rule.json` on Windows. A load failure from before `--repo` is resolved names the folder as typed (`<dir>`). A load failure reading the installed package's own `package.json`, which only `hone --version` reads, prints its absolute path. A path inside a `<detail>` is printed however the tool that wrote the detail printed it.
|
|
66
|
+
|
|
67
|
+
## Commands
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
hone check --repo <dir> [--base-revision <revision>] [--report-output <full|failures-only|counts|verdict-only>] [--forfeiture <this-run|elsewhere>]
|
|
71
|
+
hone project --repo <dir>
|
|
72
|
+
hone --help
|
|
73
|
+
hone --version
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Each option is followed by its value as the next argument; a value that starts with `-` is read as a missing value. `--help` or `-h` after a command prints that command's help instead of running it, and `hone --help <command>` prints the same. `hone --help` and `hone --version` take nothing else after them.
|
|
77
|
+
|
|
78
|
+
`hone --help` prints:
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
usage: hone <command> [options]
|
|
82
|
+
|
|
83
|
+
Checks a repository against the disciplines it selects, applies its recorded exceptions and prints one verdict.
|
|
84
|
+
|
|
85
|
+
commands:
|
|
86
|
+
check check the repository against the disciplines it selects and print the report, ending in its verdict
|
|
87
|
+
project write the native configuration each selected embedded mechanism needs, printing each file as written or unchanged
|
|
88
|
+
|
|
89
|
+
options:
|
|
90
|
+
--help, -h print this help; after a command, print that command's help
|
|
91
|
+
--version print the installed version of @hailstails/hone
|
|
92
|
+
|
|
93
|
+
run hone <command> --help for a command's options and exit codes
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`hone check --help` prints:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
usage: hone check --repo <dir> [--base-revision <revision>] [--report-output <full|failures-only|counts|verdict-only>] [--forfeiture <this-run|elsewhere>]
|
|
100
|
+
|
|
101
|
+
check the repository against the disciplines it selects and print the report, ending in its verdict
|
|
102
|
+
|
|
103
|
+
options:
|
|
104
|
+
--repo <dir>
|
|
105
|
+
the folder that holds disciplines.json, usually the repository root
|
|
106
|
+
--base-revision <revision>
|
|
107
|
+
the revision the change is measured from; without it no file carve-out can be forfeited
|
|
108
|
+
--report-output <full|failures-only|counts|verdict-only>
|
|
109
|
+
how much of the report to print, over reportOutput in disciplines.json; full when neither is set
|
|
110
|
+
--forfeiture <this-run|elsewhere>
|
|
111
|
+
assess file carve-out decay in this run or leave it to another, over assessment.forfeiture in disciplines.json; this-run when neither is set
|
|
112
|
+
--help, -h
|
|
113
|
+
print this help
|
|
114
|
+
|
|
115
|
+
exit codes:
|
|
116
|
+
0 the verdict is pass
|
|
117
|
+
1 the verdict is fail
|
|
118
|
+
2 a load failure: an input could not be loaded, a mechanism failed, or Hone failed unexpectedly
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`hone project --help` prints:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
usage: hone project --repo <dir>
|
|
125
|
+
|
|
126
|
+
write the native configuration each selected embedded mechanism needs, printing each file as written or unchanged
|
|
127
|
+
|
|
128
|
+
options:
|
|
129
|
+
--repo <dir>
|
|
130
|
+
the folder that holds disciplines.json, usually the repository root
|
|
131
|
+
--help, -h
|
|
132
|
+
print this help
|
|
133
|
+
|
|
134
|
+
exit codes:
|
|
135
|
+
0 every projection was written or already current
|
|
136
|
+
2 any failure
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`hone --version` prints the version of the installed package, read from its `package.json`, and exits `0`:
|
|
140
|
+
|
|
141
|
+
| Output | Line |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| `version` | `<version>` |
|
|
144
|
+
|
|
145
|
+
## The report
|
|
146
|
+
|
|
147
|
+
`hone check` prints the report's non-empty sections in this order, then the verdict line. A failing section makes the verdict `fail`; an informational or guidance section never does.
|
|
148
|
+
|
|
149
|
+
| Section | Role | What it lists |
|
|
150
|
+
| --- | --- | --- |
|
|
151
|
+
| `excluded` | informational | paths that `exclude` in `disciplines.json` leaves out |
|
|
152
|
+
| `notAdopted` | informational | clauses marked `not-adopted` |
|
|
153
|
+
| `notRun` | informational | clauses marked `not-run` |
|
|
154
|
+
| `findings` | failing | each place a clause is broken |
|
|
155
|
+
| `exempted` | informational | findings an exception covers, with the exceptions that cover them |
|
|
156
|
+
| `uncovered` | failing | clauses of a selected discipline that are neither selected nor marked |
|
|
157
|
+
| `stale` | failing | exceptions that cover no finding |
|
|
158
|
+
| `forfeited` | failing | file carve-outs on files this change touched |
|
|
159
|
+
| `unrecorded` | failing | native exceptions with no record in `discipline-exceptions.json` |
|
|
160
|
+
| `doublyHeld` | failing | files both authorised and carved out for one clause |
|
|
161
|
+
| `invalidRecords` | failing | entries in `discipline-exceptions.json` that cannot be applied |
|
|
162
|
+
| `unmeasured` | failing | what this run could not measure |
|
|
163
|
+
| `projectionProblems` | failing | ESLint projections that are out of date |
|
|
164
|
+
| `assessment` | informational | concerns this run left to another run |
|
|
165
|
+
| `readFirst` | guidance | where to read before changing code, for each clause with findings |
|
|
166
|
+
|
|
167
|
+
`--report-output`, or `reportOutput` in `disciplines.json`, sets how much is printed. The verdict and the exit code are the same in every output.
|
|
168
|
+
|
|
169
|
+
| Output | Prints |
|
|
170
|
+
| --- | --- |
|
|
171
|
+
| `full` | each non-empty section's heading and entries, then the verdict line |
|
|
172
|
+
| `failures-only` | the same without the informational sections |
|
|
173
|
+
| `counts` | each non-empty section's heading only, with its role after an informational or guidance section, then the verdict line |
|
|
174
|
+
| `verdict-only` | the verdict line |
|
|
175
|
+
|
|
176
|
+
A section heading counts its entries. In `counts`, an informational or guidance section's heading names its role. The `readFirst` count includes its leading note line when there is one.
|
|
177
|
+
|
|
178
|
+
| Line | Template |
|
|
179
|
+
| --- | --- |
|
|
180
|
+
| `heading` | `<section> (<count>)` |
|
|
181
|
+
| `heading` | `<section> (<count>) informational` |
|
|
182
|
+
| `heading` | `<section> (<count>) guidance` |
|
|
183
|
+
| `verdict` | `verdict: pass` |
|
|
184
|
+
| `verdict` | `verdict: fail` |
|
|
185
|
+
| `verdict` | `verdict: pass (partial assessment)` |
|
|
186
|
+
| `verdict` | `verdict: fail (partial assessment)` |
|
|
187
|
+
|
|
188
|
+
The verdict line reads `(partial assessment)` whenever the report has an `assessment` section.
|
|
189
|
+
|
|
190
|
+
## Report lines
|
|
191
|
+
|
|
192
|
+
Each section's entries take one of these shapes. An exempted finding repeats ` exempted by <record kind>` once for each exception that covers it. In `projectionProblems`, a `<slice>` is the `disciplines.eslint.mjs` projection file of one config root, the repository root or a folder in `eslintConfigRoots`; `unconfigured` means that root has no `eslint.config.*`.
|
|
193
|
+
|
|
194
|
+
| Section | Line |
|
|
195
|
+
| --- | --- |
|
|
196
|
+
| `excluded` | `<path>` |
|
|
197
|
+
| `notAdopted` | `<clause>` |
|
|
198
|
+
| `notRun` | `<clause> adopted, mechanism not run: enforced by review` |
|
|
199
|
+
| `findings` | `<clause> <mechanism> <file>:<line>:<column> <snippet>` |
|
|
200
|
+
| `exempted` | `<clause> <mechanism> <file>:<line>:<column> <snippet> exempted by <record kind>` |
|
|
201
|
+
| `exempted` | `<clause> <mechanism> <file>:<line>:<column> <snippet> exempted by <record kind> imported from <source>` |
|
|
202
|
+
| `uncovered` | `<clause>` |
|
|
203
|
+
| `stale` | `<clause> <mechanism> authorised-location <file>` |
|
|
204
|
+
| `stale` | `<clause> <mechanism> file-carve-out <file>` |
|
|
205
|
+
| `stale` | `<clause> <mechanism> clause-wide-carve-out *` |
|
|
206
|
+
| `forfeited` | `<clause> <mechanism> file-carve-out <file>` |
|
|
207
|
+
| `unrecorded` | `<clause> <mechanism> ignore <file>` |
|
|
208
|
+
| `unrecorded` | `<clause> <mechanism> config-override <file>` |
|
|
209
|
+
| `unrecorded` | `<clause> <mechanism> suppression-entry <file> <suppressions file>` |
|
|
210
|
+
| `unrecorded` | `<clause> <mechanism> inline-disable <file>:<line> <comment>` |
|
|
211
|
+
| `unrecorded` | `<clause> <mechanism> inline-disable <file>:<line> <comment> names no rule and escapes every selected clause: naming the rule is the cheap fix` |
|
|
212
|
+
| `unrecorded` | `<clause> <mechanism> inline-rule-config <file>:<line> <comment>` |
|
|
213
|
+
| `unrecorded` | `<clause> <mechanism> command-line-option <package file> <script> <option> weakens the script's whole run, so no record can cover it: remove it from the script` |
|
|
214
|
+
| `unrecorded` | `<clause> <mechanism> command-line-option <package file> <script> <option>: <command> is not the first command of its script, so Hone cannot tell what the option does to the files under check; give <command> a script of its own, such as <invocation>` |
|
|
215
|
+
| `unrecorded` | `<clause> <mechanism> command-line-option <package file> <script> <option>: <wrapper> comes before <command> and is neither a package runner nor a NAME=value setting, so Hone cannot tell what the option does to the files under check; put only package runners and NAME=value settings before <command>` |
|
|
216
|
+
| `doublyHeld` | `<clause> <mechanism> doubly-held <file>` |
|
|
217
|
+
| `invalidRecords` | `exceptions[<index>] clause-unparseable <detail>` |
|
|
218
|
+
| `invalidRecords` | `exceptions[<index>] clause-not-selected <clause>` |
|
|
219
|
+
| `invalidRecords` | `exceptions[<index>] clause-not-adopted <clause>` |
|
|
220
|
+
| `invalidRecords` | `exceptions[<index>] clause-not-run <clause>` |
|
|
221
|
+
| `invalidRecords` | `exceptions[<index>] file-not-repo-path <file>` |
|
|
222
|
+
| `invalidRecords` | `exceptions[<index>] why-chain-refused <detail>` |
|
|
223
|
+
| `invalidRecords` | `exceptions[<index>] evidence-refused <detail>` |
|
|
224
|
+
| `invalidRecords` | `exceptions[<index>] import-unverified <detail>` |
|
|
225
|
+
| `invalidRecords` | `exceptions[<index>] non-exemptible-clause <clause>` |
|
|
226
|
+
| `invalidRecords` | `exceptions[<index>] duplicate of <earlier index>` |
|
|
227
|
+
| `unmeasured` | `forfeiture-unmeasured no-base-revision: no --base-revision was given, so file carve-outs cannot be checked for decay; pass --base-revision with the branch's base, such as origin/main, or leave decay to another run with "assessment": { "forfeiture": "elsewhere" } in disciplines.json or --forfeiture elsewhere` |
|
|
228
|
+
| `unmeasured` | `forfeiture-unmeasured base-git-failed <revision>: git could not list the files changed since that revision and said <git message>; Hone needs that revision and the history back to where this branch left it, or leave decay to another run with "assessment": { "forfeiture": "elsewhere" } in disciplines.json or --forfeiture elsewhere` |
|
|
229
|
+
| `unmeasured` | `import-unmeasured no-base-revision: no --base-revision was given, so imported records cannot be checked against it; pass --base-revision with the branch's base, such as origin/main` |
|
|
230
|
+
| `unmeasured` | `import-unmeasured base-git-failed <revision>: git could not read the exception records at that revision and said <git message>; Hone needs the exception records as they were at that revision` |
|
|
231
|
+
| `unmeasured` | `legacy-chain-unmeasured no-base-revision: no --base-revision was given, so legacy-chain records cannot be checked against it; pass --base-revision with the branch's base, such as origin/main` |
|
|
232
|
+
| `unmeasured` | `legacy-chain-unmeasured base-git-failed <revision>: git could not read the exception records at that revision and said <git message>; Hone needs the exception records as they were at that revision` |
|
|
233
|
+
| `unmeasured` | `mechanism-not-run <mechanism> missing: disciplines.<mechanism>.mjs is not written; run <project command> and commit every disciplines.<mechanism>.mjs it writes` |
|
|
234
|
+
| `unmeasured` | `mechanism-not-run <mechanism> not-included: the <mechanism> configuration leaves the projection out of effect for a file under check; spread the default export of disciplines.<mechanism>.mjs, or of a package's own disciplines.<mechanism>.mjs in that package, last in the configuration that file loads, after every other block (an import placed last without the spread applies nothing), or, where a tool such as sku generates the configuration, last in the configuration the tool takes` |
|
|
235
|
+
| `unmeasured` | `mechanism-not-run <mechanism> not-included: the <mechanism> configuration leaves the projection out of effect for a file under check; spread the default export of disciplines.<mechanism>.mjs, or of a package's own disciplines.<mechanism>.mjs in that package, last in the configuration that file loads, after every other block (an import placed last without the spread applies nothing), or, where a tool such as sku generates the configuration, last in the configuration the tool takes; the <mechanism> lines under projectionProblems name the package slices involved` |
|
|
236
|
+
| `unmeasured` | `mechanism-not-run <mechanism> not-included: the <mechanism> configuration leaves the projection out of effect for a file under check; spread the default export of disciplines.<mechanism>.mjs, or of a package's own disciplines.<mechanism>.mjs in that package, last in the configuration that file loads, after every other block (an import placed last without the spread applies nothing), or, where a tool such as sku generates the configuration, last in the configuration the tool takes; <folders> hold their own disciplines.json, and nested Hone configurations are not supported yet (https://github.com/HailsTails/hone/issues/72): to govern such a folder from this repository, remove its disciplines.json and keep its records here, then run <project command>, which writes its slice` |
|
|
237
|
+
| `unmeasured` | `mechanism-not-run <mechanism> not-included: the <mechanism> configuration leaves the projection out of effect for a file under check; spread the default export of disciplines.<mechanism>.mjs, or of a package's own disciplines.<mechanism>.mjs in that package, last in the configuration that file loads, after every other block (an import placed last without the spread applies nothing), or, where a tool such as sku generates the configuration, last in the configuration the tool takes; the <mechanism> lines under projectionProblems name the package slices involved; <folders> hold their own disciplines.json, and nested Hone configurations are not supported yet (https://github.com/HailsTails/hone/issues/72): to govern such a folder from this repository, remove its disciplines.json and keep its records here, then run <project command>, which writes its slice` |
|
|
238
|
+
| `projectionProblems` | `<mechanism> out-of-date: disciplines.<mechanism>.mjs differs from what hone project writes now; run <project command> and commit every disciplines.<mechanism>.mjs it writes` |
|
|
239
|
+
| `projectionProblems` | `<mechanism> out-of-date <slice>: that slice differs from what hone project writes now; run <project command> and commit every disciplines.<mechanism>.mjs it writes` |
|
|
240
|
+
| `projectionProblems` | `<mechanism> missing <slice>: that slice is not written; run <project command> and commit every disciplines.<mechanism>.mjs it writes` |
|
|
241
|
+
| `projectionProblems` | `<mechanism> not-applied <slice>: the <mechanism> configuration for <folder> leaves records of that slice out of effect; spread the default export of <slice> last in that package's configuration, in place of any other projection it spreads, or, where a tool such as sku generates the configuration, last in the configuration the tool takes` |
|
|
242
|
+
| `projectionProblems` | `<mechanism> unconfigured <slice>: <folder> has no <mechanism> configuration file on disk, so nothing loads that slice; run the tool that generates it (for sku, sku configure) before the check` |
|
|
243
|
+
| `assessment` | `forfeiture elsewhere: 1 file carve-out not checked for decay in this run` |
|
|
244
|
+
| `assessment` | `forfeiture elsewhere: <count> file carve-outs not checked for decay in this run` |
|
|
245
|
+
| `readFirst` | `Start from each rule's Spirit below. disciplines.assessment.md, where this repository records its own causes, forward goal and steps for a clause, is not written yet; <adoption guide>#5a-write-the-assessment says how to write it.` |
|
|
246
|
+
| `readFirst` | `disciplines.assessment.md, where this repository records its own causes, forward goal and steps for a clause, is not written yet; <adoption guide>#5a-write-the-assessment says how to write it.` |
|
|
247
|
+
| `readFirst` | `Start from each rule's Spirit below. disciplines.assessment.md could not be read.` |
|
|
248
|
+
| `readFirst` | `disciplines.assessment.md could not be read.` |
|
|
249
|
+
| `readFirst` | `<clause>: read the "## <clause>" section of disciplines.assessment.md, then <rule page>#spirit` |
|
|
250
|
+
| `readFirst` | `<clause>: read <rule page>#spirit; disciplines.assessment.md does not assess this clause` |
|
|
251
|
+
| `readFirst` | `<clause>: read <rule page>#spirit` |
|
|
252
|
+
| `readFirst` | `<clause>: read the "## <clause>" section of disciplines.assessment.md; its rule set has no rule page at <rule page>` |
|
|
253
|
+
| `readFirst` | `<clause>: its rule set has no rule page at <rule page>; disciplines.assessment.md does not assess this clause` |
|
|
254
|
+
| `readFirst` | `<clause>: its rule set has no rule page at <rule page>` |
|
|
255
|
+
|
|
256
|
+
`readFirst` has one clause line per clause with findings, in the order the findings first name them. When `disciplines.assessment.md` is not written yet, or cannot be read, one note line comes first; it starts with `Start from each rule's Spirit below.` only when at least one clause line names a rule page. A clause line's first word is a clause address, which holds a `#`, followed by `:`; a note line's first word holds no `#`, which is how a tool tells them apart. The `<adoption guide>` is `ADOPTING.md` in the installed package, such as `node_modules/@hailstails/hone/ADOPTING.md`. A clause line names the clause's section in `disciplines.assessment.md` when the file has one, says `does not assess this clause` when the file is there without that section, and says neither when the file is not read. [The README](../README.md#commands) says how a section is matched.
|
|
257
|
+
|
|
258
|
+
## Load failures
|
|
259
|
+
|
|
260
|
+
A run that cannot decide prints one line and exits `2`. It prints the same line in every output. The line starts with `load failure: ` and its kind; the values follow in the order shown, and any text after the values is not stable.
|
|
261
|
+
|
|
262
|
+
| Kind | Line |
|
|
263
|
+
| --- | --- |
|
|
264
|
+
| `arguments-invalid` | `load failure: arguments-invalid <detail>` |
|
|
265
|
+
| `selection-absent` | `load failure: selection-absent <dir> holds no disciplines.json; give the folder that holds it, usually the repository root` |
|
|
266
|
+
| `install-root-unresolvable` | `load failure: install-root-unresolvable <url> <detail>` |
|
|
267
|
+
| `file-unreadable` | `load failure: file-unreadable <path> <detail>` |
|
|
268
|
+
| `file-malformed` | `load failure: file-malformed <path> <detail>` |
|
|
269
|
+
| `unsupported-version` | `load failure: unsupported-version <path> <version found>` |
|
|
270
|
+
| `reserved-rule-set-name` | `load failure: reserved-rule-set-name <rule set>` |
|
|
271
|
+
| `rule-set-name-collision` | `load failure: rule-set-name-collision <rule set> <other rule set>` |
|
|
272
|
+
| `duplicate-clause` | `load failure: duplicate-clause <clause> <clause with its rule set>` |
|
|
273
|
+
| `unknown-rule-set` | `load failure: unknown-rule-set <rule set>` |
|
|
274
|
+
| `unknown-discipline` | `load failure: unknown-discipline <clause>` |
|
|
275
|
+
| `unknown-clause` | `load failure: unknown-clause <clause>` |
|
|
276
|
+
| `judgement-clause-selected` | `load failure: judgement-clause-selected <clause>` |
|
|
277
|
+
| `judgement-clause-listed` | `load failure: judgement-clause-listed <clause>: a judgement clause is enforced by review and is left out of clauses, adopted or not; remove it` |
|
|
278
|
+
| `mechanism-not-allowed` | `load failure: mechanism-not-allowed <clause> <mechanism>` |
|
|
279
|
+
| `runner-missing` | `load failure: runner-missing <mechanism>` |
|
|
280
|
+
| `runner-invalid` | `load failure: runner-invalid <mechanism> <detail>` |
|
|
281
|
+
| `piece-missing` | `load failure: piece-missing <clause> <mechanism>` |
|
|
282
|
+
| `rule-set-invalid` | `load failure: rule-set-invalid <path> <detail>` |
|
|
283
|
+
| `git-failed` | `load failure: git-failed <detail>` |
|
|
284
|
+
| `config-root-untracked` | `load failure: config-root-untracked <config root>: an eslintConfigRoots entry is a folder git tracks files under outside every excluded path, spelled exactly as git spells it; fix or remove it in disciplines.json` |
|
|
285
|
+
| `unexpected-error` | `load failure: unexpected-error <detail>` |
|
|
286
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> piece-invalid <piece folder> <detail>` |
|
|
287
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> file-unreadable <file> <detail>` |
|
|
288
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> file-unparseable <file> <detail>` |
|
|
289
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> tool-failed <detail>` |
|
|
290
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> plugin-conflict <detail>` |
|
|
291
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> team-config-unloadable <detail>` |
|
|
292
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> runner-invalid-output <detail>` |
|
|
293
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> toolchain-unavailable <package> found <version found>, supported <range>: add a supported version to the devDependencies of the repository root` |
|
|
294
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> toolchain-unavailable <package> found not installed, supported <range>: <package> is a required peer of @hailstails/hone, so this install is incomplete; add a supported version to the devDependencies of the repository root and reinstall` |
|
|
295
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> toolchain-unavailable <package> found <version found>, supported <range>; <other package> found <version found>, supported <range>: add a supported version of each to the devDependencies of the repository root` |
|
|
296
|
+
| `runner-failed` | `load failure: runner-failed <mechanism> toolchain-shadowed <package> resolved from <location> inside the core install <install folder>: delete <install folder>/node_modules, then reinstall the package with the repository's package manager, so the repository's own copy is used` |
|
|
297
|
+
|
|
298
|
+
The last `toolchain-unavailable` line lists every unavailable package, separated by `; `. An `unexpected-error` is a fault in Hone, not in the repository; its `<detail>` is the error's message.
|
|
299
|
+
|
|
300
|
+
An `arguments-invalid` line says what was wrong with the command as typed. Its wording is not stable.
|
|
301
|
+
|
|
302
|
+
| Problem | Line |
|
|
303
|
+
| --- | --- |
|
|
304
|
+
| `command-missing` | `load failure: arguments-invalid hone needs a command, check or project; run hone --help for usage` |
|
|
305
|
+
| `command-unknown` | `load failure: arguments-invalid hone has no command "<given>"; its commands are check and project; run hone --help for usage` |
|
|
306
|
+
| `flag-extra` | `load failure: arguments-invalid hone <flag> takes nothing after it, not "<given>"; run hone --help for usage` |
|
|
307
|
+
| `argument-unexpected` | `load failure: arguments-invalid hone <command> takes options, not "<given>" on its own; give each option and its value as two arguments, as in <option> <value>; run hone <command> --help for its options` |
|
|
308
|
+
| `option-unknown` | `load failure: arguments-invalid hone <command> has no option "<given>"; run hone <command> --help for its options` |
|
|
309
|
+
| `option-joined` | `load failure: arguments-invalid give <option> and its value as two arguments, as in <option> <value>, not "<given>"` |
|
|
310
|
+
| `value-missing` | `load failure: arguments-invalid <option> needs a value, as in <option> <value>` |
|
|
311
|
+
| `option-repeated` | `load failure: arguments-invalid <option> is given more than once; give it once` |
|
|
312
|
+
| `option-required` | `load failure: arguments-invalid hone <command> needs --repo <dir>: the folder that holds disciplines.json, usually the repository root` |
|
|
313
|
+
| `choice-invalid` | `load failure: arguments-invalid <option> takes <values>, not "<given>"` |
|
|
314
|
+
| `option-removed` | `load failure: arguments-invalid removed: "--waived-clauses"; in clauses, mark a clause "not-run" when its mechanism does not run, or "not-adopted" when its rule does not apply; see MIGRATING.md section 12` |
|
|
315
|
+
| `repo-unresolvable` | `load failure: arguments-invalid --repo <dir> resolves to no absolute path` |
|
|
316
|
+
|
|
317
|
+
## hone project
|
|
318
|
+
|
|
319
|
+
`hone project` prints one line per projection file it manages, and nothing when no selected mechanism needs one.
|
|
320
|
+
|
|
321
|
+
| Output | Line |
|
|
322
|
+
| --- | --- |
|
|
323
|
+
| `project` | `<path> written` |
|
|
324
|
+
| `project` | `<path> unchanged` |
|
|
325
|
+
| `project` | `<path> removed` |
|
|
326
|
+
| `project` | `<path> left-in-place` |
|
|
@@ -1,46 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
anyBearingOf,
|
|
3
|
+
assertionOf,
|
|
4
|
+
castSnippetAt
|
|
5
|
+
} from "../../../chunks/chunk-3HFJHJDO.js";
|
|
1
6
|
import {
|
|
2
7
|
folderScope
|
|
3
8
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
9
|
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
10
|
|
|
6
11
|
// mechanisms/audit/CD-1/any-cast.ts
|
|
7
|
-
var SNIPPET_MAX_LENGTH = 80;
|
|
8
|
-
var ZOD_MODULE_SPECIFIER_PATTERN = /^zod(\/.*)?$/;
|
|
9
|
-
var CD1_ANY_PATTERN = /\bas\s+any\b|:\s*any\b|<any>/;
|
|
10
12
|
var sourceEligibility = (request) => {
|
|
11
13
|
if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
|
|
12
14
|
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
13
15
|
return "eligible";
|
|
14
16
|
};
|
|
15
|
-
var namesImportedFromZod = (request) => new Set(
|
|
16
|
-
request.sourceFile.statements.flatMap((statement) => {
|
|
17
|
-
if (!request.syntaxApi.isImportDeclaration(statement)) return [];
|
|
18
|
-
if (!request.syntaxApi.isStringLiteral(statement.moduleSpecifier)) return [];
|
|
19
|
-
if (!ZOD_MODULE_SPECIFIER_PATTERN.test(statement.moduleSpecifier.text)) return [];
|
|
20
|
-
const namedBindings = statement.importClause?.namedBindings;
|
|
21
|
-
if (namedBindings === void 0 || !request.syntaxApi.isNamedImports(namedBindings)) return [];
|
|
22
|
-
return namedBindings.elements.map((element) => element.name.text);
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
var castPermission = (request) => {
|
|
26
|
-
if (!request.syntaxApi.isAsExpression(request.node)) return "forbidden";
|
|
27
|
-
const typeNode = request.node.type;
|
|
28
|
-
if (typeNode.kind === request.syntaxApi.SyntaxKind.UnknownKeyword) return "permitted";
|
|
29
|
-
if (request.syntaxApi.isTypeReferenceNode(typeNode) && request.syntaxApi.isIdentifier(typeNode.typeName)) {
|
|
30
|
-
const typeName = typeNode.typeName.text;
|
|
31
|
-
if (typeName === "const" || request.zodImportedNames.has(typeName)) return "permitted";
|
|
32
|
-
if (request.syntaxApi.isPropertyAccessExpression(request.node.expression) && request.node.expression.name.text === "value" && (typeName === "ReadonlyArray" || typeName === "Array")) return "permitted";
|
|
33
|
-
}
|
|
34
|
-
if (!request.syntaxApi.isIndexedAccessTypeNode(typeNode)) return "forbidden";
|
|
35
|
-
const objectType = typeNode.objectType;
|
|
36
|
-
const indexType = typeNode.indexType;
|
|
37
|
-
if (request.syntaxApi.isTypeReferenceNode(objectType) && request.syntaxApi.isIdentifier(objectType.typeName) && objectType.typeName.text === "Tool" && request.syntaxApi.isLiteralTypeNode(indexType) && request.syntaxApi.isStringLiteral(indexType.literal) && indexType.literal.text === "inputSchema") return "permitted";
|
|
38
|
-
return "forbidden";
|
|
39
|
-
};
|
|
40
|
-
var snippetAt = (request) => {
|
|
41
|
-
const snippet = request.sourceFile.text.slice(request.position, request.position + SNIPPET_MAX_LENGTH).replace(/\n/g, " ");
|
|
42
|
-
return snippet.length === SNIPPET_MAX_LENGTH ? `${snippet}\u2026` : snippet;
|
|
43
|
-
};
|
|
44
17
|
var check = {
|
|
45
18
|
prepare: ({ clauses, syntaxApi }) => ({
|
|
46
19
|
outcome: "ok",
|
|
@@ -54,15 +27,14 @@ var check = {
|
|
|
54
27
|
value: {
|
|
55
28
|
kind: "syntax",
|
|
56
29
|
begin: ({ sourceFile, anchorAt }) => {
|
|
57
|
-
const zodImportedNames = namesImportedFromZod({ sourceFile, syntaxApi });
|
|
58
30
|
const hits = [];
|
|
59
31
|
return {
|
|
60
32
|
enter: ({ node }) => {
|
|
61
|
-
|
|
62
|
-
if (
|
|
33
|
+
const assertion = assertionOf({ node, syntaxApi });
|
|
34
|
+
if (assertion === void 0) return;
|
|
35
|
+
if (anyBearingOf({ typeNode: assertion.type, syntaxApi }) === "any-free") return;
|
|
63
36
|
const position = node.getStart(sourceFile);
|
|
64
|
-
const snippet =
|
|
65
|
-
if (!CD1_ANY_PATTERN.test(snippet)) return;
|
|
37
|
+
const snippet = castSnippetAt({ sourceFile, position });
|
|
66
38
|
const anchor = anchorAt({ position });
|
|
67
39
|
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
68
40
|
},
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stringListClauseSettings
|
|
3
|
+
} from "../../../chunks/chunk-WPRR2MPJ.js";
|
|
4
|
+
import {
|
|
5
|
+
gatheredOutcomes
|
|
6
|
+
} from "../../../chunks/chunk-LDQUT742.js";
|
|
7
|
+
import "../../../chunks/chunk-NCDYOPHG.js";
|
|
1
8
|
import {
|
|
2
9
|
folderScope
|
|
3
10
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
@@ -9,79 +16,83 @@ var sourceEligibility = (request) => {
|
|
|
9
16
|
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
10
17
|
return "eligible";
|
|
11
18
|
};
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"hono/utils/http-status",
|
|
24
|
-
"jose",
|
|
25
|
-
"@modelcontextprotocol/sdk",
|
|
26
|
-
"zod-to-json-schema",
|
|
27
|
-
"uuid"
|
|
28
|
-
];
|
|
29
|
-
var escapedSpecifier = (request) => request.specifier.replace(/[/.]/g, "\\$&");
|
|
30
|
-
var bannedImportPattern = (request) => new RegExp(`from\\s+["'](?:${request.specifiers.map((specifier) => escapedSpecifier({ specifier })).join("|")})["']`);
|
|
31
|
-
var BANNED_IMPORT_ANYWHERE = bannedImportPattern({ specifiers: BANNED_THIRD_PARTY_IMPORTS });
|
|
32
|
-
var BANNED_IMPORT_PATTERNS = BANNED_THIRD_PARTY_IMPORTS.map((specifier) => ({ specifier, pattern: bannedImportPattern({ specifiers: [specifier] }) }));
|
|
33
|
-
var bannedImportsIn = (request) => {
|
|
34
|
-
if (!BANNED_IMPORT_ANYWHERE.test(request.text)) return [];
|
|
19
|
+
var escapedPackage = (request) => request.packageName.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
20
|
+
var confinedImportPattern = (request) => new RegExp(
|
|
21
|
+
`from\\s+["']((?:${request.packageNames.map((packageName) => escapedPackage({ packageName })).join("|")})(?:/[^"']*)?)["']`
|
|
22
|
+
);
|
|
23
|
+
var confinedClauseOf = (request) => ({
|
|
24
|
+
clause: request.clause,
|
|
25
|
+
anywhere: request.packageNames.length === 0 ? void 0 : confinedImportPattern({ packageNames: request.packageNames }),
|
|
26
|
+
patterns: request.packageNames.map((packageName) => ({ pattern: confinedImportPattern({ packageNames: [packageName] }) }))
|
|
27
|
+
});
|
|
28
|
+
var confinedImportsIn = (request) => {
|
|
29
|
+
if (request.confined.anywhere === void 0 || !request.confined.anywhere.test(request.text)) return [];
|
|
35
30
|
return request.text.split("\n").flatMap(
|
|
36
|
-
(text, index) =>
|
|
31
|
+
(text, index) => request.confined.patterns.flatMap(({ pattern }) => {
|
|
32
|
+
const specifier = pattern.exec(text)?.[1];
|
|
33
|
+
return specifier === void 0 ? [] : [{ line: index + 1, specifier }];
|
|
34
|
+
})
|
|
37
35
|
);
|
|
38
36
|
};
|
|
37
|
+
var confinedImportHits = (request) => request.confined.flatMap(
|
|
38
|
+
(confined) => confinedImportsIn({ text: request.text, confined }).map(({ line, specifier }) => ({
|
|
39
|
+
clause: confined.clause.address,
|
|
40
|
+
anchor: { line, column: 0 },
|
|
41
|
+
snippet: `banned third-party import: ${specifier} \u2014 use its recorded wrapping boundary`
|
|
42
|
+
}))
|
|
43
|
+
);
|
|
44
|
+
var confinedClausesOf = (request) => gatheredOutcomes({
|
|
45
|
+
outcomes: request.clauses.map((clause) => {
|
|
46
|
+
const settings = stringListClauseSettings({ clause, keys: ["confinedPackages"] });
|
|
47
|
+
if (settings.outcome === "failed") return settings;
|
|
48
|
+
return { outcome: "ok", value: [confinedClauseOf({ clause, packageNames: settings.value.confinedPackages })] };
|
|
49
|
+
})
|
|
50
|
+
});
|
|
39
51
|
var check = {
|
|
40
|
-
prepare: ({ clauses, syntaxApi }) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
};
|
|
52
|
+
prepare: ({ clauses, syntaxApi }) => {
|
|
53
|
+
const settled = confinedClausesOf({ clauses });
|
|
54
|
+
if (settled.outcome === "failed") return settled;
|
|
55
|
+
const confined = settled.value;
|
|
56
|
+
return {
|
|
57
|
+
outcome: "ok",
|
|
58
|
+
value: {
|
|
59
|
+
prepareFile: ({ file }) => {
|
|
60
|
+
if (sourceEligibility({ file }) === "excluded") return { outcome: "ok", value: { kind: "skipped" } };
|
|
61
|
+
return {
|
|
62
|
+
outcome: "ok",
|
|
63
|
+
value: {
|
|
64
|
+
kind: "syntax",
|
|
65
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
66
|
+
const rawHits = confinedImportHits({ text: sourceFile.text, confined });
|
|
67
|
+
const nodeHits = [];
|
|
68
|
+
const record = (specifier) => {
|
|
69
|
+
if (specifier === void 0 || !syntaxApi.isStringLiteralLike(specifier) || !specifier.text.startsWith("node:")) return;
|
|
70
|
+
const anchor = anchorAt({ position: specifier.getStart(sourceFile) });
|
|
71
|
+
const snippet = `bare node: stdlib import - use the kernel port package: ${specifier.text}`;
|
|
72
|
+
nodeHits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
enter: ({ node }) => {
|
|
76
|
+
if (syntaxApi.isImportDeclaration(node) || syntaxApi.isExportDeclaration(node)) {
|
|
77
|
+
record(node.moduleSpecifier);
|
|
78
|
+
} else if (syntaxApi.isImportTypeNode(node) && syntaxApi.isLiteralTypeNode(node.argument)) {
|
|
79
|
+
record(node.argument.literal);
|
|
80
|
+
} else if (syntaxApi.isImportEqualsDeclaration(node) && syntaxApi.isExternalModuleReference(node.moduleReference)) {
|
|
81
|
+
record(node.moduleReference.expression);
|
|
82
|
+
} else if (syntaxApi.isCallExpression(node) && (node.expression.kind === syntaxApi.SyntaxKind.ImportKeyword || syntaxApi.isIdentifier(node.expression) && node.expression.text === "require")) {
|
|
83
|
+
record(node.arguments[0]);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
finish: () => [...rawHits, ...nodeHits]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
78
89
|
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
85
96
|
};
|
|
86
97
|
export {
|
|
87
98
|
check
|