am-i-done 0.7.0 → 0.7.1

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
@@ -235,6 +235,8 @@ reason = "the public API re-exports its types until the next major (#123)"
235
235
  ```
236
236
 
237
237
  It has the same checks: the reason cites an issue, and a waiver that waives nothing fails the run.
238
+ Leave `match` out to waive the rule for the whole file, for one that is never edited (vendored or
239
+ hash-pinned code).
238
240
 
239
241
  ### Built-in rules
240
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "am-i-done",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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
@@ -10,6 +10,9 @@ const ids = z.array(z.string().min(1));
10
10
  /** A stage or rule left out, and why: `{ id = "lint", reason = "… (#12)" }`. */
11
11
  const skips = z.array(z.strictObject({ id: z.string().min(1), reason: z.string().min(1) }));
12
12
 
13
+ /** `[rules] include` by default: every file Bun runs as a script. The built-in rules' fixtures assume it. */
14
+ export const DEFAULT_INCLUDE = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"] as const;
15
+
13
16
  const DEFAULT_CATEGORIES = {
14
17
  architecture: "where code lives and what it may import",
15
18
  conventions: "house style and banned escape hatches",
@@ -59,7 +62,7 @@ const schema = z.strictObject({
59
62
  skip: skips.default([]),
60
63
  dirs: z.array(z.string().min(1)).default(["scripts/rules"]),
61
64
  /** Files every rule sees unless it names its own `files`. */
62
- include: z.array(z.string().min(1)).default(["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"]),
65
+ include: z.array(z.string().min(1)).default([...DEFAULT_INCLUDE]),
63
66
  /** Excluded in addition to everything git ignores. */
64
67
  exclude: z.array(z.string().min(1)).default([]),
65
68
  categories: z.record(z.string().min(1), z.string()).default(DEFAULT_CATEGORIES),
@@ -81,7 +84,8 @@ const schema = z.strictObject({
81
84
  z.strictObject({
82
85
  rule: z.string().min(1),
83
86
  file: z.string().min(1),
84
- match: z.string().min(1),
87
+ /** Text on the violating line. Absent: the whole file, for one that is never edited. */
88
+ match: z.string().min(1).optional(),
85
89
  reason: z.string().min(1),
86
90
  }),
87
91
  )
@@ -1,10 +1,10 @@
1
1
  import { join, relative } from "node:path";
2
2
  import { z } from "zod";
3
- import type { Config } from "../config.js";
3
+ import { type Config, DEFAULT_INCLUDE } from "../config.js";
4
4
  import { ID, loadModules } from "../modules.js";
5
5
  import { today } from "../today.js";
6
6
  import { warnUntilProblems, warnUntilSchema } from "../waivers.js";
7
- import { chooseParser, loadParser } from "./ast.js";
7
+ import { chooseParser, loadParser, type Parser } from "./ast.js";
8
8
  import { evaluate, type Workspace, wantsTests, workspace } from "./evaluate.js";
9
9
  import { fileMeta, listFiles, matchesAny } from "./files.js";
10
10
  import { checkFixtures, FIXTURE_DIR, loadFixtures } from "./fixtures.js";
@@ -44,6 +44,8 @@ export interface RuleSet {
44
44
  dirs: string[];
45
45
  /** Every rule id defined, including skipped ones. */
46
46
  known: Set<string>;
47
+ /** Ids of the rules that came from the built-in directory. */
48
+ builtin: Set<string>;
47
49
  }
48
50
 
49
51
  /** The built-in rules (when recommended) and the project's, minus `[rules] skip`. A project rule may not reuse a built-in's id. */
@@ -63,7 +65,8 @@ export async function loadRules(config: Config, builtinDir: string = BUILTIN_RUL
63
65
  ];
64
66
  if (problems.length > 0) throw new Error(problems.join("\n"));
65
67
  const rules = loaded.map((m) => m.value).filter((r) => !skipped.has(r.id));
66
- return { rules: rules.sort((a, b) => a.id.localeCompare(b.id)), dirs: roots, known };
68
+ const builtin = new Set(loaded.filter((m) => m.path.startsWith(`${builtinDir}/`)).map((m) => m.value.id));
69
+ return { rules: rules.sort((a, b) => a.id.localeCompare(b.id)), dirs: roots, known, builtin };
67
70
  }
68
71
 
69
72
  export interface EngineOptions {
@@ -112,15 +115,36 @@ export async function runEngine(config: Config, set: RuleSet, options: EngineOpt
112
115
  ...scanned.crashes,
113
116
  ...waived.unused,
114
117
  ...(full ? liveness(rules, scanned.counts, files) : []),
115
- ...checkFixtures(rules, loadFixtures(set.dirs), set.known, {
116
- requireIssue,
117
- include: config.rules.include,
118
- ...(parser === undefined ? {} : { parser }),
119
- }),
118
+ ...fixtureProblems(rules, set, config, parser),
120
119
  ];
121
120
  return { violations: waived.violations, warnings: waived.warnings, problems, rules, files: files.size };
122
121
  }
123
122
 
123
+ /**
124
+ * Every rule's fixtures. A built-in rule's were written for the default `[rules] include`, so they
125
+ * are judged by it: a project that narrows its include narrows what the rules see, not what their
126
+ * fixtures may claim.
127
+ */
128
+ function fixtureProblems(rules: readonly Rule[], set: RuleSet, config: Config, parser: Parser | undefined): string[] {
129
+ const base = { requireIssue: config.suppression.require_issue, ...(parser === undefined ? {} : { parser }) };
130
+ const fixtures = loadFixtures(set.dirs);
131
+ const builtIn = (id: string) => set.builtin.has(id);
132
+ return [
133
+ ...checkFixtures(
134
+ rules.filter((r) => builtIn(r.id)),
135
+ fixtures.filter((f) => builtIn(f.ruleId)),
136
+ set.known,
137
+ { ...base, include: DEFAULT_INCLUDE },
138
+ ),
139
+ ...checkFixtures(
140
+ rules.filter((r) => !builtIn(r.id)),
141
+ fixtures.filter((f) => !builtIn(f.ruleId)),
142
+ set.known,
143
+ { ...base, include: config.rules.include },
144
+ ),
145
+ ];
146
+ }
147
+
124
148
  type Waiver = Config["suppression"]["waive"][number];
125
149
 
126
150
  /**
@@ -138,7 +162,9 @@ function applyWaivers(
138
162
  const used = new Set<Waiver>();
139
163
  const lineOf = (v: Violation) => files.get(v.file)?.content.split("\n")[v.line - 1] ?? "";
140
164
  const keep = (v: Violation) => {
141
- const waiver = waivers.find((w) => w.rule === v.rule.id && w.file === v.file && lineOf(v).includes(w.match));
165
+ const waiver = waivers.find(
166
+ (w) => w.rule === v.rule.id && w.file === v.file && (w.match === undefined || lineOf(v).includes(w.match)),
167
+ );
142
168
  if (waiver !== undefined) used.add(waiver);
143
169
  return waiver === undefined;
144
170
  };
@@ -146,7 +172,10 @@ function applyWaivers(
146
172
  const warnings = found.warnings.filter(keep);
147
173
  const unused = waivers
148
174
  .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`);
175
+ .map(
176
+ (w) =>
177
+ `[[suppression.waive]] ${w.rule} in ${w.file}${w.match === undefined ? "" : ` ("${w.match}")`} waives nothing: delete it`,
178
+ );
150
179
  const unknown = waivers
151
180
  .filter((w) => full && !files.has(w.file) && rules.some((r) => r.id === w.rule))
152
181
  .map((w) => `[[suppression.waive]] ${w.rule}: ${w.file} is not a file the rules check`);