@jfalava/ts-standard 0.3.2 → 0.3.3
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/package.json +1 -1
- package/src/check.ts +2 -2
- package/src/lint.ts +55 -12
- package/src/repo.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jfalava/ts-standard",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Checks a Bun repo against the TypeScript scripts and workflows standard: package.json scripts, pins, tsconfig, lint setup and GitHub workflows. Also ships the anti-slop oxlint plugins the standard uses.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/check.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface Result {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Its exceptions name one plugin or rule of one package and match it exactly, not by prefix. */
|
|
26
|
-
const EXACT_RULES: ReadonlySet<string> = new Set(["lint/anti-slop"]);
|
|
26
|
+
const EXACT_RULES: ReadonlySet<string> = new Set(["lint/anti-slop", "lint/pending"]);
|
|
27
27
|
|
|
28
28
|
const matches = (e: Exception, f: Finding): boolean =>
|
|
29
29
|
e.rule === f.rule &&
|
|
@@ -48,7 +48,7 @@ export const check = (root: string, config: StandardConfig): Result => {
|
|
|
48
48
|
const broad: Finding[] = (config.exceptions ?? []).filter(isBroad).map((e) => ({
|
|
49
49
|
rule: "standard/broad-exception",
|
|
50
50
|
where: e.where ?? "*",
|
|
51
|
-
message: `exception for \`${e.rule}\` must name a plugin or rule, as \`<package dir>:<plugin>\` or \`<package dir>:<
|
|
51
|
+
message: `exception for \`${e.rule}\` must name a plugin or rule, as \`<package dir>:<plugin>\` or \`<package dir>:<rule>\``,
|
|
52
52
|
}));
|
|
53
53
|
const exceptions = (config.exceptions ?? []).filter((e) => !isBroad(e));
|
|
54
54
|
const used = new Set<Exception>();
|
package/src/lint.ts
CHANGED
|
@@ -98,10 +98,20 @@ const loads = (config: Resolved, plugin: Plugin): JsPlugin | undefined =>
|
|
|
98
98
|
return spec === plugin.specifier || (spec.startsWith("/") && isFileOf(spec, plugin));
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
type Setting = Level | readonly [Level, ...unknown[]];
|
|
102
|
+
const levelOf = (value: Setting): Level => (typeof value === "object" ? value[0] : value);
|
|
103
|
+
const isWarn = (value: Setting): boolean => {
|
|
104
|
+
const level = levelOf(value);
|
|
105
|
+
return level === "warn" || level === 1;
|
|
104
106
|
};
|
|
107
|
+
/** Off, or a warning: a warning fails nothing, so it parks findings the same way off does. */
|
|
108
|
+
const isQuiet = (value: Setting): boolean => {
|
|
109
|
+
const level = levelOf(value);
|
|
110
|
+
return level === "off" || level === 0 || isWarn(value);
|
|
111
|
+
};
|
|
112
|
+
const ruleId = (rule: string): string =>
|
|
113
|
+
rule.replaceAll("/", String.raw`\/`).replaceAll("-", String.raw`\-`);
|
|
114
|
+
const QUIET = `\\[?\\s*(?:["'](?:off|warn)["']|[01]\\b)`;
|
|
105
115
|
|
|
106
116
|
/**
|
|
107
117
|
* The repo files a config is built from: the config and every file it imports by relative path,
|
|
@@ -123,12 +133,18 @@ const sourcesOf = (path: string, seen = new Map<string, string>()): Map<string,
|
|
|
123
133
|
};
|
|
124
134
|
|
|
125
135
|
/**
|
|
126
|
-
* A rule kept off on purpose sits in a pending map with its finding count, as
|
|
127
|
-
* `"anti-slop/x": "off", // 4`, in one of the files the package's config
|
|
136
|
+
* A rule kept off or at `warn` on purpose sits in a pending map with its finding count, as
|
|
137
|
+
* `"anti-slop/x": "off", // 4` or `"x": "warn", // 4`, in one of the files the package's config
|
|
138
|
+
* is built from.
|
|
128
139
|
*/
|
|
129
140
|
const pendingIn = (texts: readonly string[], rule: string): boolean => {
|
|
130
|
-
const
|
|
131
|
-
|
|
141
|
+
const marker = new RegExp(`["']${ruleId(rule)}["']\\s*:\\s*${QUIET}[^\\n]*?//\\s*\\d`);
|
|
142
|
+
return texts.some((text) => marker.test(text));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Whether the repo's own config files set the rule to `warn`, rather than a preset. */
|
|
146
|
+
const warnedIn = (texts: readonly string[], rule: string): boolean => {
|
|
147
|
+
const marker = new RegExp(`["']${ruleId(rule)}["']\\s*:\\s*\\[?\\s*(?:["']warn["']|1\\b)`);
|
|
132
148
|
return texts.some((text) => marker.test(text));
|
|
133
149
|
};
|
|
134
150
|
|
|
@@ -141,6 +157,8 @@ const pluginRules = (repo: Repo): Finding[] => {
|
|
|
141
157
|
const out: Finding[] = [];
|
|
142
158
|
const f = (where: string, message: string) =>
|
|
143
159
|
out.push({ rule: "lint/anti-slop", where, message });
|
|
160
|
+
const pending = (where: string, message: string) =>
|
|
161
|
+
out.push({ rule: "lint/pending", where, message });
|
|
144
162
|
for (const pkg of [repo.rootPkg, ...repo.workspaces]) {
|
|
145
163
|
const path = lintConfigOf(repo, pkg);
|
|
146
164
|
if (path === undefined) {
|
|
@@ -156,6 +174,31 @@ const pluginRules = (repo: Repo): Finding[] => {
|
|
|
156
174
|
continue;
|
|
157
175
|
}
|
|
158
176
|
const texts = [...sourcesOf(path).values()];
|
|
177
|
+
// A rule the repo sets to `warn` is pending work that passes the gate: it carries its count.
|
|
178
|
+
// Warnings a preset sets, such as @effect/tsgo's diagnostics, are the preset's policy.
|
|
179
|
+
const scopes = [
|
|
180
|
+
{ label: "", rules: config.rules },
|
|
181
|
+
...(config.overrides ?? []).map((o, i) => ({
|
|
182
|
+
label: ` in \`overrides[${i}]\` (${(o.files ?? []).join(", ")})`,
|
|
183
|
+
rules: o.rules,
|
|
184
|
+
})),
|
|
185
|
+
];
|
|
186
|
+
for (const { label, rules } of scopes) {
|
|
187
|
+
for (const [rule, value] of Object.entries(rules ?? {})) {
|
|
188
|
+
if (
|
|
189
|
+
value !== undefined &&
|
|
190
|
+
!rule.startsWith("anti-slop") &&
|
|
191
|
+
isWarn(value) &&
|
|
192
|
+
warnedIn(texts, rule) &&
|
|
193
|
+
!pendingIn(texts, rule)
|
|
194
|
+
) {
|
|
195
|
+
pending(
|
|
196
|
+
`${pkg.dir}:${rule}`,
|
|
197
|
+
`is \`warn\`${label} with no pending count; turn it on, or list it as \`"${rule}": "warn", // <findings>\``,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
159
202
|
const effect = usesEffect(pkg);
|
|
160
203
|
for (const plugin of [GENERIC, EFFECT]) {
|
|
161
204
|
const at = `${pkg.dir}:${plugin.name}`;
|
|
@@ -184,19 +227,19 @@ const pluginRules = (repo: Repo): Finding[] => {
|
|
|
184
227
|
const value = config.rules?.[rule];
|
|
185
228
|
if (value === undefined) {
|
|
186
229
|
f(`${pkg.dir}:${rule}`, "is not configured, so it never runs; turn it on");
|
|
187
|
-
} else if (
|
|
230
|
+
} else if (isQuiet(value) && !pendingIn(texts, rule)) {
|
|
188
231
|
f(
|
|
189
232
|
`${pkg.dir}:${rule}`,
|
|
190
|
-
`is
|
|
233
|
+
`is \`${String(levelOf(value))}\` with no pending count; turn it on, or list it as \`"${rule}": "off", // <findings>\``,
|
|
191
234
|
);
|
|
192
235
|
}
|
|
193
|
-
// An override that
|
|
236
|
+
// An override that quiets a kept rule for some files is the same as quieting it.
|
|
194
237
|
for (const [i, override] of (config.overrides ?? []).entries()) {
|
|
195
238
|
const local = override.rules?.[rule];
|
|
196
|
-
if (local !== undefined &&
|
|
239
|
+
if (local !== undefined && isQuiet(local) && !pendingIn(texts, rule)) {
|
|
197
240
|
f(
|
|
198
241
|
`${pkg.dir}:${rule}`,
|
|
199
|
-
`is
|
|
242
|
+
`is \`${String(levelOf(local))}\` in \`overrides[${i}]\` (${(override.files ?? []).join(", ")}) with no pending count; turn it on there, or list it as \`"${rule}": "off", // <findings>\``,
|
|
200
243
|
);
|
|
201
244
|
}
|
|
202
245
|
}
|
package/src/repo.ts
CHANGED
|
@@ -42,7 +42,11 @@ const expandWorkspaceGlobs = (root: string, patterns: readonly string[]): string
|
|
|
42
42
|
for (const pattern of patterns) {
|
|
43
43
|
if (pattern.endsWith("/*")) {
|
|
44
44
|
const parent = pattern.slice(0, -2);
|
|
45
|
-
|
|
45
|
+
// Sorted: readdir order differs between filesystems, and findings follow this order.
|
|
46
|
+
const entries = readdirSync(join(root, parent), { withFileTypes: true }).toSorted((a, b) =>
|
|
47
|
+
a.name.localeCompare(b.name),
|
|
48
|
+
);
|
|
49
|
+
for (const entry of entries) {
|
|
46
50
|
if (entry.isDirectory() && existsSync(join(root, parent, entry.name, "package.json"))) {
|
|
47
51
|
dirs.push(`${parent}/${entry.name}`);
|
|
48
52
|
}
|