am-i-done 0.5.0 → 0.7.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 CHANGED
@@ -159,7 +159,8 @@ A `check` rule returns `ctx.checked()` when it inspected the file and `ctx.skipp
159
159
  was out of scope. Its return type is a brand only the engine can mint, so a bare `return` does not
160
160
  compile.
161
161
 
162
- **Syntax trees.** A check rule that sets `ast: true` can call `ctx.ast()` for the file's tree, in
162
+ **Syntax trees.** A check rule that sets `ast: true` can call `ctx.ast()` for the file's tree (or `ctx.ast(path)` for another loaded file's, to follow an
163
+ import or a re-export), in
163
164
  [TSESTree](https://typescript-eslint.io/packages/typescript-estree/) form (the ESTree dialect
164
165
  typescript-eslint defines), with `range`, `loc` and `parent` on every node and the comments on the
165
166
  program. It is parsed once per file and shared by every rule. The parser is TypeScript (through
@@ -222,6 +223,19 @@ comment, not text in a string. `doing-it-wrong-ignore-file <rule-id>: <reason> (
222
223
  its whole file. A missing reason, a reason without an issue (with `[suppression] require_issue`, the
223
224
  default), and a suppression that no longer suppresses anything are each a violation of their own.
224
225
 
226
+ A file that cannot carry the comment (generated code, JSON, a published package whose comments are
227
+ checked) is waived in done.toml instead, by rule, file and text on the line:
228
+
229
+ ```toml
230
+ [[suppression.waive]]
231
+ rule = "no-reexport-shim"
232
+ file = "packages/client/src/index.ts"
233
+ match = "export type {"
234
+ reason = "the public API re-exports its types until the next major (#123)"
235
+ ```
236
+
237
+ It has the same checks: the reason cites an issue, and a waiver that waives nothing fails the run.
238
+
225
239
  ### Built-in rules
226
240
 
227
241
  `no-as-any`, `no-ts-ignore`, `no-ts-expect-error` (outside tests), `no-empty-catch`,
@@ -296,6 +310,8 @@ parser = "auto" # for ctx.ast(): the project's typescript, el
296
310
 
297
311
  [suppression]
298
312
  require_issue = true # every waiver (suppression, skip, warnUntil) cites an issue
313
+ # [[suppression.waive]] # for a file that cannot carry a comment; see Suppression above
314
+ # rule = "<id>", file = "<path>", match = "<text on the line>", reason = "<why> (#123)"
299
315
 
300
316
  [cache]
301
317
  skip = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "am-i-done",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "A definition of done for agentic projects: one command that says whether the work is finished.",
5
5
  "license": "MIT",
6
6
  "author": "theshadow27 (https://github.com/theshadow27)",
package/src/config.ts CHANGED
@@ -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
- return (["stages", "rules"] as const).flatMap((table) =>
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`. */
@@ -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 { violations, warnings, counts, crashes } = scan(rules, ws, config, options.today);
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
- ...(full ? liveness(rules, counts, files) : []),
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. */
@@ -125,7 +125,12 @@ export function evaluate(rule: Rule, file: FileMeta, ws: Workspace): Evaluation
125
125
  violated,
126
126
  checked: mintChecked,
127
127
  skipped: mintSkipped,
128
- ast: () => ws.ast(file),
128
+ ast: (path?: string) => {
129
+ if (path === undefined) return ws.ast(file);
130
+ const other = ws.files.get(path);
131
+ if (other === undefined) throw new Error(`ctx.ast("${path}"): not a loaded file`);
132
+ return ws.ast(other);
133
+ },
129
134
  graph: () => ws.graph(),
130
135
  };
131
136
  let checked: boolean;
@@ -47,8 +47,12 @@ export interface RuleContext {
47
47
  checked(): Verdict;
48
48
  /** This file is out of scope. Claims no work. */
49
49
  skipped(): Verdict;
50
- /** The file's syntax tree (TSESTree), parsed once and shared by every rule. Needs `ast: true`. */
51
- ast(): Ast;
50
+ /**
51
+ * A file's syntax tree (TSESTree), parsed once and shared by every rule. Needs `ast: true`. With
52
+ * a path (relative to the root, as in `files`), another loaded file's: for a rule that follows an
53
+ * import or a re-export. Throws for a path that is not loaded.
54
+ */
55
+ ast(path?: string): Ast;
52
56
  /** The project's import graph, built once per run. */
53
57
  graph(): ImportGraph;
54
58
  }
@@ -9,15 +9,21 @@ rerun = "diagnose" # a failure is run again to see if it repeats, and fai
9
9
  [stages]
10
10
  recommended = true # bun-version, typecheck, lint, rules, test: each where its tool is set up
11
11
  dirs = ["scripts/stages"] # this project's *.stage.ts
12
- # skip = [{ id = "lint", reason = "<why>, until #123" }]
12
+ # skip = [{ id = "lint", reason = "<why>, until #<issue>" }]
13
13
 
14
14
  [rules]
15
15
  recommended = true # the built-in rules (doing-it-wrong --list)
16
16
  dirs = ["scripts/rules"] # this project's *.rule.ts, with fixtures in scripts/rules/fixtures/
17
- # skip = [{ id = "no-as-any", reason = "<why>, until #123" }]
17
+ # skip = [{ id = "no-as-any", reason = "<why>, until #<issue>" }]
18
18
 
19
19
  [suppression]
20
- require_issue = true # every waiver cites an issue: // doing-it-wrong-ignore <rule>: <reason> (#123)
20
+ require_issue = true # every waiver cites an issue: // doing-it-wrong-ignore <rule>: <reason> (#<issue>)
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> (#<issue>)"
21
27
 
22
28
  [cache]
23
29
  skip = true # a local rerun of an unchanged tree is skipped; never in CI