am-i-done 0.4.2 → 0.6.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 +18 -1
- package/bin/am-i-done.ts +2 -2
- package/bin/doing-it-wrong.ts +2 -2
- package/package.json +1 -1
- package/src/cache.ts +1 -1
- package/src/cli/am-i-done.ts +39 -16
- package/src/cli/doing-it-wrong.ts +6 -6
- package/src/cli/init.ts +2 -2
- package/src/config.ts +21 -2
- package/src/context.ts +1 -1
- package/src/engine/engine.ts +47 -13
- package/src/engine/evaluate.ts +5 -5
- package/src/engine/files.ts +2 -2
- package/src/engine/fixtures.ts +4 -4
- package/src/engine/graph.ts +1 -1
- package/src/engine/report.ts +3 -3
- package/src/engine/rule.ts +3 -3
- package/src/engine/suppress.ts +3 -3
- package/src/index.ts +7 -7
- package/src/log.ts +1 -1
- package/src/output-guard.ts +1 -1
- package/src/rules/no-as-any.rule.ts +1 -1
- package/src/rules/no-empty-catch.rule.ts +3 -3
- package/src/rules/no-focused-tests.rule.ts +1 -1
- package/src/rules/no-import-cycles.rule.ts +2 -2
- package/src/rules/no-raw-temp.rule.ts +2 -2
- package/src/rules/no-skipped-tests.rule.ts +1 -1
- package/src/rules/no-ts-expect-error.rule.ts +1 -1
- package/src/rules/no-ts-ignore.rule.ts +1 -1
- package/src/rules/shell-injection.rule.ts +1 -1
- package/src/rules/test-uses-bun-test.rule.ts +1 -1
- package/src/runner.ts +7 -7
- package/src/spawn.ts +1 -1
- package/src/spec-cache.ts +4 -4
- package/src/stage-process.ts +2 -2
- package/src/stages/builtin/bun-version.stage.ts +1 -1
- package/src/stages/builtin/lint.stage.ts +2 -2
- package/src/stages/builtin/rules.stage.ts +6 -6
- package/src/stages/builtin/test.stage.ts +5 -5
- package/src/stages/builtin/typecheck.stage.ts +1 -1
- package/src/stages/load.ts +7 -7
- package/src/stages/order.ts +2 -2
- package/src/tmp-preload.ts +1 -1
- package/src/types.ts +1 -1
- package/templates/done.toml +6 -0
package/README.md
CHANGED
|
@@ -57,7 +57,9 @@ A built-in whose tool is missing is left out, and every run says so (`left out:
|
|
|
57
57
|
tsconfig.json)`); one named in `[stages] load` must have its tool. `bun run am-i-done --list` prints
|
|
58
58
|
the plan. Modes pick stages: `--pre-commit`, `--pre-push`,
|
|
59
59
|
`--ci` (the default under CI), or `--mode <name>` for your own. `--only <stage>` and `--from <stage>`
|
|
60
|
-
rerun part of it; the failure message prints the exact command.
|
|
60
|
+
rerun part of it; the failure message prints the exact command. `--skip <stage>` (repeatable) leaves
|
|
61
|
+
a stage out where it cannot run (a CI job without the data it needs): such a run is never cached,
|
|
62
|
+
and says what it left out.
|
|
61
63
|
|
|
62
64
|
### What makes it strict
|
|
63
65
|
|
|
@@ -220,6 +222,19 @@ comment, not text in a string. `doing-it-wrong-ignore-file <rule-id>: <reason> (
|
|
|
220
222
|
its whole file. A missing reason, a reason without an issue (with `[suppression] require_issue`, the
|
|
221
223
|
default), and a suppression that no longer suppresses anything are each a violation of their own.
|
|
222
224
|
|
|
225
|
+
A file that cannot carry the comment (generated code, JSON, a published package whose comments are
|
|
226
|
+
checked) is waived in done.toml instead, by rule, file and text on the line:
|
|
227
|
+
|
|
228
|
+
```toml
|
|
229
|
+
[[suppression.waive]]
|
|
230
|
+
rule = "no-reexport-shim"
|
|
231
|
+
file = "packages/client/src/index.ts"
|
|
232
|
+
match = "export type {"
|
|
233
|
+
reason = "the public API re-exports its types until the next major (#123)"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
It has the same checks: the reason cites an issue, and a waiver that waives nothing fails the run.
|
|
237
|
+
|
|
223
238
|
### Built-in rules
|
|
224
239
|
|
|
225
240
|
`no-as-any`, `no-ts-ignore`, `no-ts-expect-error` (outside tests), `no-empty-catch`,
|
|
@@ -294,6 +309,8 @@ parser = "auto" # for ctx.ast(): the project's typescript, el
|
|
|
294
309
|
|
|
295
310
|
[suppression]
|
|
296
311
|
require_issue = true # every waiver (suppression, skip, warnUntil) cites an issue
|
|
312
|
+
# [[suppression.waive]] # for a file that cannot carry a comment; see Suppression above
|
|
313
|
+
# rule = "<id>", file = "<path>", match = "<text on the line>", reason = "<why> (#123)"
|
|
297
314
|
|
|
298
315
|
[cache]
|
|
299
316
|
skip = true
|
package/bin/am-i-done.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { amIDone, runCli } from "../src/cli/am-i-done.
|
|
3
|
-
import { init } from "../src/cli/init.
|
|
2
|
+
import { amIDone, runCli } from "../src/cli/am-i-done.js";
|
|
3
|
+
import { init } from "../src/cli/init.js";
|
|
4
4
|
|
|
5
5
|
await runCli((argv, io) => (argv[0] === "init" ? init(argv.slice(1), io) : amIDone(argv, io)));
|
package/bin/doing-it-wrong.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { runCli } from "../src/cli/am-i-done.
|
|
3
|
-
import { doingItWrong } from "../src/cli/doing-it-wrong.
|
|
2
|
+
import { runCli } from "../src/cli/am-i-done.js";
|
|
3
|
+
import { doingItWrong } from "../src/cli/doing-it-wrong.js";
|
|
4
4
|
|
|
5
5
|
await runCli(doingItWrong);
|
package/package.json
CHANGED
package/src/cache.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, lstatSync, readdirSync, readFileSync, readlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { dotenvLines, envLines, fileHash, type Git, gitIn, sha } from "./fingerprint.
|
|
3
|
+
import { dotenvLines, envLines, fileHash, type Git, gitIn, sha } from "./fingerprint.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The local skip: a run whose whole state matches a recent pass is not run again.
|
package/src/cli/am-i-done.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { availableParallelism } from "node:os";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { findPass, recordPass, stateKey } from "../cache.
|
|
5
|
-
import { type Config, loadConfig } from "../config.
|
|
6
|
-
import { detectContext } from "../context.
|
|
7
|
-
import { gitIn } from "../fingerprint.
|
|
8
|
-
import { consoleLogger, PLAIN, runOutput, styleFor } from "../log.
|
|
9
|
-
import { type PlannedStage, type RunOptions, runStages } from "../runner.
|
|
10
|
-
import { planStages } from "../stages/load.
|
|
11
|
-
import { today } from "../today.
|
|
12
|
-
import type { Context, Logger } from "../types.
|
|
4
|
+
import { findPass, recordPass, stateKey } from "../cache.js";
|
|
5
|
+
import { type Config, loadConfig } from "../config.js";
|
|
6
|
+
import { detectContext } from "../context.js";
|
|
7
|
+
import { gitIn } from "../fingerprint.js";
|
|
8
|
+
import { consoleLogger, PLAIN, runOutput, styleFor } from "../log.js";
|
|
9
|
+
import { type PlannedStage, type RunOptions, runStages } from "../runner.js";
|
|
10
|
+
import { planStages } from "../stages/load.js";
|
|
11
|
+
import { today } from "../today.js";
|
|
12
|
+
import type { Context, Logger } from "../types.js";
|
|
13
13
|
|
|
14
14
|
export const USAGE = `Usage: am-i-done [options]
|
|
15
15
|
|
|
@@ -19,6 +19,7 @@ Runs every stage of the project's definition of done, and says whether the work
|
|
|
19
19
|
--mode <name> Run a mode by name
|
|
20
20
|
--only <stage> Run one stage, by id or number
|
|
21
21
|
--from <stage> Start at a stage, by id or number
|
|
22
|
+
--skip <stage> Leave a stage out of this run (repeatable); the run is not a full one
|
|
22
23
|
--serial One stage at a time, output live
|
|
23
24
|
--cores <n> Core budget for running stages side by side
|
|
24
25
|
--no-fail-fast Keep going after a failure
|
|
@@ -48,6 +49,7 @@ const OPTIONS = {
|
|
|
48
49
|
mode: { type: "string" },
|
|
49
50
|
only: { type: "string" },
|
|
50
51
|
from: { type: "string" },
|
|
52
|
+
skip: { type: "string", multiple: true },
|
|
51
53
|
serial: { type: "boolean" },
|
|
52
54
|
cores: { type: "string" },
|
|
53
55
|
"no-fail-fast": { type: "boolean" },
|
|
@@ -82,8 +84,9 @@ export async function amIDone(argv: string[], io: Io): Promise<number> {
|
|
|
82
84
|
io.console.info(listPlan(plan, mode));
|
|
83
85
|
return 0;
|
|
84
86
|
}
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
+
const skipped = values.skip ?? [];
|
|
88
|
+
const selected = without(select(plan, values.only, values.from), skipped);
|
|
89
|
+
const whole = wholeRun(values);
|
|
87
90
|
const cache = whole ? localCache(config, context, mode, io.env) : undefined;
|
|
88
91
|
const age = cache?.lastPass();
|
|
89
92
|
if (age !== undefined) {
|
|
@@ -97,6 +100,7 @@ export async function amIDone(argv: string[], io: Io): Promise<number> {
|
|
|
97
100
|
progress: out.progress,
|
|
98
101
|
});
|
|
99
102
|
if (report.success) cache?.record();
|
|
103
|
+
if (skipped.length > 0) io.console.warn(`⚠ not a full run: --skip left out ${skipped.join(", ")}`);
|
|
100
104
|
const kept = out.finish(report.success);
|
|
101
105
|
if (kept !== undefined) io.console.error(`Full log: ${kept}`);
|
|
102
106
|
return report.success ? 0 : 1;
|
|
@@ -163,14 +167,33 @@ export function select(plan: readonly PlannedStage[], only?: string, from?: stri
|
|
|
163
167
|
return i;
|
|
164
168
|
};
|
|
165
169
|
if (only !== undefined) {
|
|
166
|
-
|
|
167
|
-
return [{ stage: stage.stage, deps: [] }];
|
|
170
|
+
return [{ ...(plan[at(only)] as PlannedStage), deps: [] }];
|
|
168
171
|
}
|
|
169
172
|
if (from === undefined) return [...plan];
|
|
170
173
|
const start = at(from);
|
|
171
|
-
return plan
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
return plan.slice(start).map((p) => ({ ...p, deps: p.deps.filter((d) => d >= start).map((d) => d - start) }));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A run of every stage this mode has, which alone may use or record the local skip. */
|
|
178
|
+
const wholeRun = (values: Flags): boolean =>
|
|
179
|
+
values.only === undefined && values.from === undefined && (values.skip ?? []).length === 0 && !values["no-cache"];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The plan without `ids`, for a run that cannot do some stages here (one that needs data this
|
|
183
|
+
* machine lacks). A stage that waited on a skipped one no longer waits. It never counts as a full
|
|
184
|
+
* run: nothing is cached, and the run says what it left out.
|
|
185
|
+
*/
|
|
186
|
+
export function without(plan: readonly PlannedStage[], ids: readonly string[]): PlannedStage[] {
|
|
187
|
+
const unknown = ids.filter((id) => !plan.some((p) => p.stage.id === id));
|
|
188
|
+
if (unknown.length > 0)
|
|
189
|
+
throw new Error(
|
|
190
|
+
`--skip: no stage ${unknown.map((id) => `"${id}"`).join(", ")} in this run. Stages: ${plan.map((p) => p.stage.id).join(", ")}`,
|
|
191
|
+
);
|
|
192
|
+
const kept = plan.flatMap((p, i) => (ids.includes(p.stage.id) ? [] : [i]));
|
|
193
|
+
return kept.map((i) => {
|
|
194
|
+
const p = plan[i] as PlannedStage;
|
|
195
|
+
return { ...p, deps: p.deps.flatMap((d) => (kept.includes(d) ? [kept.indexOf(d)] : [])) };
|
|
196
|
+
});
|
|
174
197
|
}
|
|
175
198
|
|
|
176
199
|
export function listPlan(plan: readonly PlannedStage[], mode: string): string {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { relative, resolve } from "node:path";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { loadConfig } from "../config.
|
|
4
|
-
import { loadRules, runEngine } from "../engine/engine.
|
|
5
|
-
import { formatCatalog, formatResult, SHOWN_PER_RULE } from "../engine/report.
|
|
6
|
-
import { styleFor } from "../log.
|
|
7
|
-
import { today } from "../today.
|
|
8
|
-
import type { Io } from "./am-i-done.
|
|
3
|
+
import { loadConfig } from "../config.js";
|
|
4
|
+
import { loadRules, runEngine } from "../engine/engine.js";
|
|
5
|
+
import { formatCatalog, formatResult, SHOWN_PER_RULE } from "../engine/report.js";
|
|
6
|
+
import { styleFor } from "../log.js";
|
|
7
|
+
import { today } from "../today.js";
|
|
8
|
+
import type { Io } from "./am-i-done.js";
|
|
9
9
|
|
|
10
10
|
export const USAGE = `Usage: doing-it-wrong [paths...] [options]
|
|
11
11
|
|
package/src/cli/init.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { CONFIG_FILE } from "../config.
|
|
5
|
-
import type { Io } from "./am-i-done.
|
|
4
|
+
import { CONFIG_FILE } from "../config.js";
|
|
5
|
+
import type { Io } from "./am-i-done.js";
|
|
6
6
|
|
|
7
7
|
export const TEMPLATES = join(import.meta.dir, "..", "..", "templates");
|
|
8
8
|
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { citesIssue } from "./waivers.
|
|
4
|
+
import { citesIssue } from "./waivers.js";
|
|
5
5
|
|
|
6
6
|
export const CONFIG_FILE = "done.toml";
|
|
7
7
|
|
|
@@ -71,6 +71,21 @@ const schema = z.strictObject({
|
|
|
71
71
|
.strictObject({
|
|
72
72
|
/** Every waiver (a suppression comment, a skip entry, a `warnUntil`) must cite an issue (`#123` or a URL). */
|
|
73
73
|
require_issue: z.boolean().default(true),
|
|
74
|
+
/**
|
|
75
|
+
* Waivers for files that cannot carry a suppression comment (generated files, JSON, a
|
|
76
|
+
* published package whose comments are checked). Each waives `rule` in `file` on the lines
|
|
77
|
+
* whose text contains `match`, and fails the run once it waives nothing.
|
|
78
|
+
*/
|
|
79
|
+
waive: z
|
|
80
|
+
.array(
|
|
81
|
+
z.strictObject({
|
|
82
|
+
rule: z.string().min(1),
|
|
83
|
+
file: z.string().min(1),
|
|
84
|
+
match: z.string().min(1),
|
|
85
|
+
reason: z.string().min(1),
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
.default([]),
|
|
74
89
|
})
|
|
75
90
|
.prefault({}),
|
|
76
91
|
cache: z
|
|
@@ -117,11 +132,15 @@ export function parseConfig(text: string, root: string): Config {
|
|
|
117
132
|
/** Skip entries whose reason cites no issue, when issues are required. */
|
|
118
133
|
function uncited(config: z.output<typeof schema>): string[] {
|
|
119
134
|
if (!config.suppression.require_issue) return [];
|
|
120
|
-
|
|
135
|
+
const skips = (["stages", "rules"] as const).flatMap((table) =>
|
|
121
136
|
config[table].skip
|
|
122
137
|
.filter((s) => !citesIssue(s.reason))
|
|
123
138
|
.map((s) => ` ${table}.skip "${s.id}": the reason must cite an issue (#123 or a URL)`),
|
|
124
139
|
);
|
|
140
|
+
const waivers = config.suppression.waive
|
|
141
|
+
.filter((w) => !citesIssue(w.reason))
|
|
142
|
+
.map((w) => ` suppression.waive "${w.rule}" in ${w.file}: the reason must cite an issue (#123 or a URL)`);
|
|
143
|
+
return [...skips, ...waivers];
|
|
125
144
|
}
|
|
126
145
|
|
|
127
146
|
/** Load the config governing `cwd`. A project with no `done.toml` gets the defaults, rooted at `cwd`. */
|
package/src/context.ts
CHANGED
package/src/engine/engine.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join, relative } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { Config } from "../config.
|
|
4
|
-
import { ID, loadModules } from "../modules.
|
|
5
|
-
import { today } from "../today.
|
|
6
|
-
import { warnUntilProblems, warnUntilSchema } from "../waivers.
|
|
7
|
-
import { chooseParser, loadParser } from "./ast.
|
|
8
|
-
import { evaluate, type Workspace, wantsTests, workspace } from "./evaluate.
|
|
9
|
-
import { fileMeta, listFiles, matchesAny } from "./files.
|
|
10
|
-
import { checkFixtures, FIXTURE_DIR, loadFixtures } from "./fixtures.
|
|
11
|
-
import type { FileMeta, Rule, Violation } from "./rule.
|
|
3
|
+
import type { Config } from "../config.js";
|
|
4
|
+
import { ID, loadModules } from "../modules.js";
|
|
5
|
+
import { today } from "../today.js";
|
|
6
|
+
import { warnUntilProblems, warnUntilSchema } from "../waivers.js";
|
|
7
|
+
import { chooseParser, loadParser } from "./ast.js";
|
|
8
|
+
import { evaluate, type Workspace, wantsTests, workspace } from "./evaluate.js";
|
|
9
|
+
import { fileMeta, listFiles, matchesAny } from "./files.js";
|
|
10
|
+
import { checkFixtures, FIXTURE_DIR, loadFixtures } from "./fixtures.js";
|
|
11
|
+
import type { FileMeta, Rule, Violation } from "./rule.js";
|
|
12
12
|
|
|
13
13
|
/** Where the built-in rules live. */
|
|
14
14
|
export const BUILTIN_RULES = join(import.meta.dir, "..", "rules");
|
|
@@ -103,20 +103,54 @@ export async function runEngine(config: Config, set: RuleSet, options: EngineOpt
|
|
|
103
103
|
if (parser !== undefined) await loadParser(parser);
|
|
104
104
|
const requireIssue = config.suppression.require_issue;
|
|
105
105
|
const ws = workspace(config.root, files, { requireIssue, ...(parser === undefined ? {} : { parser }) });
|
|
106
|
-
const
|
|
106
|
+
const scanned = scan(rules, ws, config, options.today);
|
|
107
107
|
const full = options.only === undefined && options.paths === undefined;
|
|
108
|
+
const waived = applyWaivers(config.suppression.waive, scanned, files, rules, full);
|
|
108
109
|
const unmatched = (paths ?? []).filter((p) => ![...files.keys()].some((path) => under(path, p)));
|
|
109
110
|
const problems = [
|
|
110
111
|
...unmatched.map((p) => `"${p || "."}" matches no file the rules check`),
|
|
111
|
-
...crashes,
|
|
112
|
-
...
|
|
112
|
+
...scanned.crashes,
|
|
113
|
+
...waived.unused,
|
|
114
|
+
...(full ? liveness(rules, scanned.counts, files) : []),
|
|
113
115
|
...checkFixtures(rules, loadFixtures(set.dirs), set.known, {
|
|
114
116
|
requireIssue,
|
|
115
117
|
include: config.rules.include,
|
|
116
118
|
...(parser === undefined ? {} : { parser }),
|
|
117
119
|
}),
|
|
118
120
|
];
|
|
119
|
-
return { violations, warnings, problems, rules, files: files.size };
|
|
121
|
+
return { violations: waived.violations, warnings: waived.warnings, problems, rules, files: files.size };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type Waiver = Config["suppression"]["waive"][number];
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* `[[suppression.waive]]` applied: a violation is waived when an entry names its rule and file and
|
|
128
|
+
* its line contains the entry's `match`. An entry whose rule ran over its file and waived nothing
|
|
129
|
+
* is stale, a problem as an unused suppression comment is.
|
|
130
|
+
*/
|
|
131
|
+
function applyWaivers(
|
|
132
|
+
waivers: readonly Waiver[],
|
|
133
|
+
found: { violations: Violation[]; warnings: Violation[] },
|
|
134
|
+
files: ReadonlyMap<string, FileMeta>,
|
|
135
|
+
rules: readonly Rule[],
|
|
136
|
+
full: boolean,
|
|
137
|
+
) {
|
|
138
|
+
const used = new Set<Waiver>();
|
|
139
|
+
const lineOf = (v: Violation) => files.get(v.file)?.content.split("\n")[v.line - 1] ?? "";
|
|
140
|
+
const keep = (v: Violation) => {
|
|
141
|
+
const waiver = waivers.find((w) => w.rule === v.rule.id && w.file === v.file && lineOf(v).includes(w.match));
|
|
142
|
+
if (waiver !== undefined) used.add(waiver);
|
|
143
|
+
return waiver === undefined;
|
|
144
|
+
};
|
|
145
|
+
const violations = found.violations.filter(keep);
|
|
146
|
+
const warnings = found.warnings.filter(keep);
|
|
147
|
+
const unused = waivers
|
|
148
|
+
.filter((w) => !used.has(w) && rules.some((r) => r.id === w.rule) && files.has(w.file))
|
|
149
|
+
.map((w) => `[[suppression.waive]] ${w.rule} in ${w.file} ("${w.match}") waives nothing: delete it`);
|
|
150
|
+
const unknown = waivers
|
|
151
|
+
.filter((w) => full && !files.has(w.file) && rules.some((r) => r.id === w.rule))
|
|
152
|
+
.map((w) => `[[suppression.waive]] ${w.rule}: ${w.file} is not a file the rules check`);
|
|
153
|
+
return { violations, warnings, unused: [...unused, ...unknown] };
|
|
120
154
|
}
|
|
121
155
|
|
|
122
156
|
/** Every rule over every file it wants: violations, early warnings, and how many files each rule inspected. */
|
package/src/engine/evaluate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Ast, type Parser, parseLoaded } from "./ast.
|
|
2
|
-
import { buildGraph, type ImportGraph } from "./graph.
|
|
3
|
-
import { jsxIn, maskComments, maskNonCode, maskNonComments } from "./mask.
|
|
1
|
+
import { type Ast, type Parser, parseLoaded } from "./ast.js";
|
|
2
|
+
import { buildGraph, type ImportGraph } from "./graph.js";
|
|
3
|
+
import { jsxIn, maskComments, maskNonCode, maskNonComments } from "./mask.js";
|
|
4
4
|
import {
|
|
5
5
|
type CheckRule,
|
|
6
6
|
type FileMeta,
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
snippetAt,
|
|
15
15
|
type Verdict,
|
|
16
16
|
type Violation,
|
|
17
|
-
} from "./rule.
|
|
18
|
-
import { covers, type Suppression, suppressions } from "./suppress.
|
|
17
|
+
} from "./rule.js";
|
|
18
|
+
import { covers, type Suppression, suppressions } from "./suppress.js";
|
|
19
19
|
|
|
20
20
|
/** Whether `rule` looks at `file` at all, by its `tests` setting. Path globs are the caller's concern. */
|
|
21
21
|
export function wantsTests(rule: Rule, file: FileMeta): boolean {
|
package/src/engine/files.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { extname, join } from "node:path";
|
|
3
|
-
import { gitIn } from "../fingerprint.
|
|
4
|
-
import type { FileMeta } from "./rule.
|
|
3
|
+
import { gitIn } from "../fingerprint.js";
|
|
4
|
+
import type { FileMeta } from "./rule.js";
|
|
5
5
|
|
|
6
6
|
const SCRIPT_LOADERS: Record<string, Bun.JavaScriptLoader> = {
|
|
7
7
|
ts: "ts",
|
package/src/engine/fixtures.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Parser } from "./ast.
|
|
4
|
-
import { type Evaluation, evaluate, wantsTests, workspace } from "./evaluate.
|
|
5
|
-
import { fileMeta, matchesAny } from "./files.
|
|
6
|
-
import type { FileMeta, Rule } from "./rule.
|
|
3
|
+
import type { Parser } from "./ast.js";
|
|
4
|
+
import { type Evaluation, evaluate, wantsTests, workspace } from "./evaluate.js";
|
|
5
|
+
import { fileMeta, matchesAny } from "./files.js";
|
|
6
|
+
import type { FileMeta, Rule } from "./rule.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Rule fixtures: one file per scenario, `<rulesDir>/fixtures/<rule-id>__<scenario>.<ext>.fixture`.
|
package/src/engine/graph.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, join, normalize, relative } from "node:path";
|
|
2
|
-
import { type FileMeta, SCRIPT_EXTENSION_ORDER } from "./rule.
|
|
2
|
+
import { type FileMeta, SCRIPT_EXTENSION_ORDER } from "./rule.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The project's import graph: which project file imports which.
|
package/src/engine/report.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Style } from "../log.
|
|
2
|
-
import type { EngineResult } from "./engine.
|
|
3
|
-
import type { Rule, Violation } from "./rule.
|
|
1
|
+
import type { Style } from "../log.js";
|
|
2
|
+
import type { EngineResult } from "./engine.js";
|
|
3
|
+
import type { Rule, Violation } from "./rule.js";
|
|
4
4
|
|
|
5
5
|
/** Violations shown per rule unless `--all`. */
|
|
6
6
|
export const SHOWN_PER_RULE = 10;
|
package/src/engine/rule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WarnUntil } from "../waivers.
|
|
1
|
+
import type { WarnUntil } from "../waivers.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The rule DSL.
|
|
@@ -11,8 +11,8 @@ import type { WarnUntil } from "../waivers.ts";
|
|
|
11
11
|
* clean.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type { Ast } from "./ast.
|
|
15
|
-
import type { ImportGraph } from "./graph.
|
|
14
|
+
import type { Ast } from "./ast.js";
|
|
15
|
+
import type { ImportGraph } from "./graph.js";
|
|
16
16
|
|
|
17
17
|
declare const VERDICT: unique symbol;
|
|
18
18
|
export type Verdict = { readonly [VERDICT]: "checked" | "skipped" };
|
package/src/engine/suppress.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { citesIssue } from "../waivers.
|
|
2
|
-
import { jsxIn, maskNonComments } from "./mask.
|
|
3
|
-
import { SCRIPT_EXTENSIONS } from "./rule.
|
|
1
|
+
import { citesIssue } from "../waivers.js";
|
|
2
|
+
import { jsxIn, maskNonComments } from "./mask.js";
|
|
3
|
+
import { SCRIPT_EXTENSIONS } from "./rule.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Suppression comments.
|
package/src/index.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* import type { Stage } from "am-i-done";
|
|
5
5
|
* export default { id: "docs", description: "Build the docs", command: "bun run docs" } satisfies Stage;
|
|
6
6
|
*/
|
|
7
|
-
export { type Ast, type Parser, type Raw, type TSESTree, walk } from "./engine/ast.
|
|
8
|
-
export type { ImportGraph } from "./engine/graph.
|
|
9
|
-
export type { CheckRule, FileMeta, ImportRule, PatternRule, Rule, RuleContext, Verdict } from "./engine/rule.
|
|
10
|
-
export { BIOME_LEFTOVERS, REACT_ACT } from "./output-guard.
|
|
11
|
-
export { type SpawnOptions, type SpawnResult, spawnCaptured } from "./spawn.
|
|
7
|
+
export { type Ast, type Parser, type Raw, type TSESTree, walk } from "./engine/ast.js";
|
|
8
|
+
export type { ImportGraph } from "./engine/graph.js";
|
|
9
|
+
export type { CheckRule, FileMeta, ImportRule, PatternRule, Rule, RuleContext, Verdict } from "./engine/rule.js";
|
|
10
|
+
export { BIOME_LEFTOVERS, REACT_ACT } from "./output-guard.js";
|
|
11
|
+
export { type SpawnOptions, type SpawnResult, spawnCaptured } from "./spawn.js";
|
|
12
12
|
export type {
|
|
13
13
|
Context,
|
|
14
14
|
ContextFilter,
|
|
@@ -19,5 +19,5 @@ export type {
|
|
|
19
19
|
StageFunction,
|
|
20
20
|
StageOptions,
|
|
21
21
|
StageResult,
|
|
22
|
-
} from "./types.
|
|
23
|
-
export type { WarnUntil } from "./waivers.
|
|
22
|
+
} from "./types.js";
|
|
23
|
+
export type { WarnUntil } from "./waivers.js";
|
package/src/log.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Context, Logger } from "./types.
|
|
3
|
+
import type { Context, Logger } from "./types.js";
|
|
4
4
|
|
|
5
5
|
type Paint = (text: string) => string;
|
|
6
6
|
export interface Style {
|
package/src/output-guard.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Rule } from "../engine/rule.
|
|
1
|
+
import type { Rule } from "../engine/rule.js";
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
id: "no-empty-catch",
|
|
@@ -10,8 +10,8 @@ export default {
|
|
|
10
10
|
scope: "all",
|
|
11
11
|
scold: "An empty catch swallows the error, and whatever went wrong goes on silently.",
|
|
12
12
|
guidance: [
|
|
13
|
-
"Handle the error, rethrow it
|
|
13
|
+
"Handle the error, or rethrow it. Returning `null` or `undefined` is still swallowing it, unless the caller treats that value as the failure.",
|
|
14
14
|
"If ignoring it is correct, say why in a comment inside the block: `catch { /* ENOENT: already gone */ }`,",
|
|
15
|
-
"or inside the handler: `.catch(() => { /* best effort: the cache is rebuilt on read */ })`.",
|
|
15
|
+
"or inside the handler: `.catch(() => { /* best effort: the cache is rebuilt on read */ })`, or before the value it returns: `.catch(() => /* absent means not cached */ null)`.",
|
|
16
16
|
],
|
|
17
17
|
} satisfies Rule;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxIn, maskComments } from "../engine/mask.
|
|
2
|
-
import { importOffset, position, type Rule, snippetAt } from "../engine/rule.
|
|
1
|
+
import { jsxIn, maskComments } from "../engine/mask.js";
|
|
2
|
+
import { importOffset, position, type Rule, snippetAt } from "../engine/rule.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A cycle makes load order matter: one module of it sees another half-initialised, and the bug
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { maskComments, maskNonCode } from "../engine/mask.
|
|
3
|
-
import { position, type Rule, snippetAt } from "../engine/rule.
|
|
2
|
+
import { maskComments, maskNonCode } from "../engine/mask.js";
|
|
3
|
+
import { position, type Rule, snippetAt } from "../engine/rule.js";
|
|
4
4
|
|
|
5
5
|
/** The helper itself: the one file allowed to make temp directories by hand. */
|
|
6
6
|
const OWNER = join(import.meta.dir, "..", "tmp.ts");
|
package/src/runner.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { availableParallelism, loadavg } from "node:os";
|
|
3
|
-
import { bufferedLogger, formatDuration, type Style } from "./log.
|
|
4
|
-
import { describeFindings, scanOutput } from "./output-guard.
|
|
5
|
-
import { schedule } from "./scheduler.
|
|
6
|
-
import { endAll, spawnCaptured } from "./spawn.
|
|
7
|
-
import { stageArgv } from "./stage-process.
|
|
8
|
-
import { tmpDir } from "./tmp.
|
|
9
|
-
import type { Context, Logger, Stage, StageOptions, StageResult } from "./types.
|
|
3
|
+
import { bufferedLogger, formatDuration, type Style } from "./log.js";
|
|
4
|
+
import { describeFindings, scanOutput } from "./output-guard.js";
|
|
5
|
+
import { schedule } from "./scheduler.js";
|
|
6
|
+
import { endAll, spawnCaptured } from "./spawn.js";
|
|
7
|
+
import { stageArgv } from "./stage-process.js";
|
|
8
|
+
import { tmpDir } from "./tmp.js";
|
|
9
|
+
import type { Context, Logger, Stage, StageOptions, StageResult } from "./types.js";
|
|
10
10
|
|
|
11
11
|
export type Rerun = "diagnose" | "off" | "pass";
|
|
12
12
|
/** `warn`: failed, but its `warnUntil` date has not come. `blocked`: never started. */
|
package/src/spawn.ts
CHANGED
package/src/spec-cache.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { extname, join, relative } from "node:path";
|
|
3
|
-
import { fileMeta, listFiles } from "./engine/files.
|
|
4
|
-
import { buildGraph } from "./engine/graph.
|
|
5
|
-
import { SCRIPT_EXTENSIONS } from "./engine/rule.
|
|
6
|
-
import { dotenvLines, envLines, fileHash, sha } from "./fingerprint.
|
|
3
|
+
import { fileMeta, listFiles } from "./engine/files.js";
|
|
4
|
+
import { buildGraph } from "./engine/graph.js";
|
|
5
|
+
import { SCRIPT_EXTENSIONS } from "./engine/rule.js";
|
|
6
|
+
import { dotenvLines, envLines, fileHash, sha } from "./fingerprint.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The per-spec cache: a spec whose inputs are unchanged since it last passed is not run again.
|
package/src/stage-process.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { consoleLogger } from "./log.
|
|
3
|
-
import type { Context, Logger, Stage, StageResult } from "./types.
|
|
2
|
+
import { consoleLogger } from "./log.js";
|
|
3
|
+
import type { Context, Logger, Stage, StageResult } from "./types.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Where a function stage runs: a `bun` process of its own, started by the runner like any command.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Stage } from "../../types.
|
|
3
|
+
import type { Stage } from "../../types.js";
|
|
4
4
|
|
|
5
5
|
/** `package.json`'s `packageManager` when it names Bun, else `undefined`. */
|
|
6
6
|
export function bunPin(root: string): string | undefined {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { BIOME_LEFTOVERS } from "../../output-guard.
|
|
4
|
-
import type { Stage, StageOptions } from "../../types.
|
|
3
|
+
import { BIOME_LEFTOVERS } from "../../output-guard.js";
|
|
4
|
+
import type { Stage, StageOptions } from "../../types.js";
|
|
5
5
|
|
|
6
6
|
const checkOnly = (options: StageOptions): StageOptions => ({ ...options, args: ["."] });
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { loadConfig } from "../../config.
|
|
2
|
-
import { loadRules, runEngine } from "../../engine/engine.
|
|
3
|
-
import { formatResult } from "../../engine/report.
|
|
4
|
-
import { PLAIN } from "../../log.
|
|
5
|
-
import { today } from "../../today.
|
|
6
|
-
import type { Stage } from "../../types.
|
|
1
|
+
import { loadConfig } from "../../config.js";
|
|
2
|
+
import { loadRules, runEngine } from "../../engine/engine.js";
|
|
3
|
+
import { formatResult } from "../../engine/report.js";
|
|
4
|
+
import { PLAIN } from "../../log.js";
|
|
5
|
+
import { today } from "../../today.js";
|
|
6
|
+
import type { Stage } from "../../types.js";
|
|
7
7
|
|
|
8
8
|
/** In-process: the rules share the runner's process and read every file once. */
|
|
9
9
|
export default {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type Config, loadConfig } from "../../config.
|
|
2
|
-
import { REACT_ACT, scanOutput } from "../../output-guard.
|
|
3
|
-
import { spawnCaptured } from "../../spawn.
|
|
4
|
-
import { measuresCoverage, planSpecs } from "../../spec-cache.
|
|
5
|
-
import type { Stage, StageOptions, StageResult } from "../../types.
|
|
1
|
+
import { type Config, loadConfig } from "../../config.js";
|
|
2
|
+
import { REACT_ACT, scanOutput } from "../../output-guard.js";
|
|
3
|
+
import { spawnCaptured } from "../../spawn.js";
|
|
4
|
+
import { measuresCoverage, planSpecs } from "../../spec-cache.js";
|
|
5
|
+
import type { Stage, StageOptions, StageResult } from "../../types.js";
|
|
6
6
|
|
|
7
7
|
async function bunTest(options: StageOptions, paths: string[]): Promise<StageResult> {
|
|
8
8
|
const argv = ["bun", "test", ...options.args, ...paths.map((p) => `./${p}`)];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Stage } from "../../types.
|
|
3
|
+
import type { Stage } from "../../types.js";
|
|
4
4
|
|
|
5
5
|
/** `--no-script`: without it `bun check` runs a package.json `check` script, which may be this gate. */
|
|
6
6
|
export default {
|
package/src/stages/load.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { Config } from "../config.
|
|
4
|
-
import { ID, loadModules } from "../modules.
|
|
5
|
-
import type { PlannedStage } from "../runner.
|
|
6
|
-
import { today } from "../today.
|
|
7
|
-
import { PHASES, type Stage, type StageFunction } from "../types.
|
|
8
|
-
import { warnUntilProblems, warnUntilSchema } from "../waivers.
|
|
9
|
-
import { order } from "./order.
|
|
3
|
+
import type { Config } from "../config.js";
|
|
4
|
+
import { ID, loadModules } from "../modules.js";
|
|
5
|
+
import type { PlannedStage } from "../runner.js";
|
|
6
|
+
import { today } from "../today.js";
|
|
7
|
+
import { PHASES, type Stage, type StageFunction } from "../types.js";
|
|
8
|
+
import { warnUntilProblems, warnUntilSchema } from "../waivers.js";
|
|
9
|
+
import { order } from "./order.js";
|
|
10
10
|
|
|
11
11
|
/** Where the built-in stages live. */
|
|
12
12
|
export const BUILTIN_DIR = join(import.meta.dir, "builtin");
|
package/src/stages/order.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PlannedStage } from "../runner.
|
|
2
|
-
import { PHASES, type Phase, type Stage } from "../types.
|
|
1
|
+
import type { PlannedStage } from "../runner.js";
|
|
2
|
+
import { PHASES, type Phase, type Stage } from "../types.js";
|
|
3
3
|
|
|
4
4
|
const rank = (stage: Stage): number => PHASES.indexOf(stage.phase ?? "check");
|
|
5
5
|
const phaseOf = (stage: Stage): Phase => stage.phase ?? "check";
|
package/src/tmp-preload.ts
CHANGED
package/src/types.ts
CHANGED
package/templates/done.toml
CHANGED
|
@@ -18,6 +18,12 @@ dirs = ["scripts/rules"] # this project's *.rule.ts, with fixtures in scripts/r
|
|
|
18
18
|
|
|
19
19
|
[suppression]
|
|
20
20
|
require_issue = true # every waiver cites an issue: // doing-it-wrong-ignore <rule>: <reason> (#123)
|
|
21
|
+
# A file that cannot carry that comment (generated, JSON) is waived here instead:
|
|
22
|
+
# [[suppression.waive]]
|
|
23
|
+
# rule = "<id>"
|
|
24
|
+
# file = "<path>"
|
|
25
|
+
# match = "<text on the line>"
|
|
26
|
+
# reason = "<why> (#123)"
|
|
21
27
|
|
|
22
28
|
[cache]
|
|
23
29
|
skip = true # a local rerun of an unchanged tree is skipped; never in CI
|