am-i-done 0.5.0 → 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 +15 -0
- package/package.json +1 -1
- package/src/config.ts +20 -1
- package/src/engine/engine.ts +38 -4
- package/templates/done.toml +6 -0
package/README.md
CHANGED
|
@@ -222,6 +222,19 @@ comment, not text in a string. `doing-it-wrong-ignore-file <rule-id>: <reason> (
|
|
|
222
222
|
its whole file. A missing reason, a reason without an issue (with `[suppression] require_issue`, the
|
|
223
223
|
default), and a suppression that no longer suppresses anything are each a violation of their own.
|
|
224
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
|
+
|
|
225
238
|
### Built-in rules
|
|
226
239
|
|
|
227
240
|
`no-as-any`, `no-ts-ignore`, `no-ts-expect-error` (outside tests), `no-empty-catch`,
|
|
@@ -296,6 +309,8 @@ parser = "auto" # for ctx.ast(): the project's typescript, el
|
|
|
296
309
|
|
|
297
310
|
[suppression]
|
|
298
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)"
|
|
299
314
|
|
|
300
315
|
[cache]
|
|
301
316
|
skip = true
|
package/package.json
CHANGED
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
|
-
|
|
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/engine/engine.ts
CHANGED
|
@@ -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/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
|