@shivaedev/quality 0.51.0 → 0.53.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/CHANGELOG.md +41 -0
- package/README.md +26 -13
- package/biome/declarations.json +0 -5
- package/biome/plugins/ambient-runtime.grit +1 -1
- package/biome/preset.json +1 -1
- package/dist/baseline/format.d.ts +1 -0
- package/dist/baseline/format.d.ts.map +1 -1
- package/dist/baseline/format.js +3 -2
- package/dist/baseline/format.js.map +1 -1
- package/dist/baseline/update.js +1 -1
- package/dist/baseline/update.js.map +1 -1
- package/dist/cli/lint.d.ts +2 -3
- package/dist/cli/lint.d.ts.map +1 -1
- package/dist/cli/lint.js +4 -2
- package/dist/cli/lint.js.map +1 -1
- package/dist/config/globs.d.ts +17 -0
- package/dist/config/globs.d.ts.map +1 -0
- package/dist/config/globs.js +18 -0
- package/dist/config/globs.js.map +1 -0
- package/dist/engine/runRules.d.ts +2 -1
- package/dist/engine/runRules.d.ts.map +1 -1
- package/dist/engine/runRules.js +4 -1
- package/dist/engine/runRules.js.map +1 -1
- package/dist/engine/session.d.ts +1 -1
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +9 -5
- package/dist/engine/session.js.map +1 -1
- package/dist/hooks/preCommit.d.ts +2 -1
- package/dist/hooks/preCommit.d.ts.map +1 -1
- package/dist/imports/fences/compilePolicy.d.ts.map +1 -1
- package/dist/imports/fences/compilePolicy.js +6 -2
- package/dist/imports/fences/compilePolicy.js.map +1 -1
- package/dist/inventory/shadcnAlias.js.map +1 -1
- package/dist/rule.d.ts +1 -0
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js +7 -3
- package/dist/rule.js.map +1 -1
- package/dist/rules/builtIn.d.ts +36 -9
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/effect/boundary.js +1 -1
- package/dist/rules/effect/boundary.js.map +1 -1
- package/dist/rules/effect/boundaryCalls.js +1 -1
- package/dist/rules/effect/boundaryCalls.js.map +1 -1
- package/dist/rules/effect/boundaryReference.js +1 -1
- package/dist/rules/effect/boundaryReference.js.map +1 -1
- package/dist/rules/files/folderNames.d.ts +8 -2
- package/dist/rules/files/folderNames.d.ts.map +1 -1
- package/dist/rules/files/folderNames.js +7 -5
- package/dist/rules/files/folderNames.js.map +1 -1
- package/dist/rules/files/namedAfterExport.d.ts +4 -1
- package/dist/rules/files/namedAfterExport.d.ts.map +1 -1
- package/dist/rules/files/namedAfterExport.js +6 -7
- package/dist/rules/files/namedAfterExport.js.map +1 -1
- package/dist/rules/files/otherNames.d.ts +8 -2
- package/dist/rules/files/otherNames.d.ts.map +1 -1
- package/dist/rules/files/otherNames.js +7 -5
- package/dist/rules/files/otherNames.js.map +1 -1
- package/dist/rules/noBarrel.js +1 -1
- package/dist/rules/noBarrel.js.map +1 -1
- package/dist/rules/secondNames.d.ts.map +1 -1
- package/dist/rules/secondNames.js +5 -1
- package/dist/rules/secondNames.js.map +1 -1
- package/dist/rules/stories/authSql.d.ts +4 -1
- package/dist/rules/stories/authSql.d.ts.map +1 -1
- package/dist/rules/stories/authSql.js +6 -3
- package/dist/rules/stories/authSql.js.map +1 -1
- package/dist/rules/stories/collectionOrigins.d.ts +5 -0
- package/dist/rules/stories/collectionOrigins.d.ts.map +1 -0
- package/dist/rules/stories/collectionOrigins.js +17 -0
- package/dist/rules/stories/collectionOrigins.js.map +1 -0
- package/dist/rules/stories/httpStatus.d.ts +4 -1
- package/dist/rules/stories/httpStatus.d.ts.map +1 -1
- package/dist/rules/stories/httpStatus.js +6 -3
- package/dist/rules/stories/httpStatus.js.map +1 -1
- package/dist/rules/stories/namedValues.d.ts.map +1 -1
- package/dist/rules/stories/namedValues.js +5 -5
- package/dist/rules/stories/namedValues.js.map +1 -1
- package/dist/rules/stories/noLimitImports.d.ts.map +1 -1
- package/dist/rules/stories/noLimitImports.js +4 -2
- package/dist/rules/stories/noLimitImports.js.map +1 -1
- package/dist/rules/stories/origins.d.ts +1 -2
- package/dist/rules/stories/origins.d.ts.map +1 -1
- package/dist/rules/stories/origins.js +12 -6
- package/dist/rules/stories/origins.js.map +1 -1
- package/dist/rules/stories/prerequisites.d.ts.map +1 -1
- package/dist/rules/stories/prerequisites.js +6 -24
- package/dist/rules/stories/prerequisites.js.map +1 -1
- package/dist/rules/stories/program.d.ts.map +1 -1
- package/dist/rules/stories/program.js +8 -1
- package/dist/rules/stories/program.js.map +1 -1
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/dist/rules/stories/sources.js +19 -7
- package/dist/rules/stories/sources.js.map +1 -1
- package/dist/rules/stories/specHelpers.d.ts.map +1 -1
- package/dist/rules/stories/specHelpers.js +4 -2
- package/dist/rules/stories/specHelpers.js.map +1 -1
- package/dist/rules/stories/specs.js +1 -1
- package/dist/rules/stories/specs.js.map +1 -1
- package/dist/rules/stories/syntax.d.ts +0 -1
- package/dist/rules/stories/syntax.d.ts.map +1 -1
- package/dist/rules/stories/syntax.js +0 -4
- package/dist/rules/stories/syntax.js.map +1 -1
- package/dist/rules/suppressions/hiddenCast.d.ts +4 -0
- package/dist/rules/suppressions/hiddenCast.d.ts.map +1 -0
- package/dist/rules/suppressions/hiddenCast.js +80 -0
- package/dist/rules/suppressions/hiddenCast.js.map +1 -0
- package/dist/rules/suppressions/noDoubleCast.d.ts.map +1 -1
- package/dist/rules/suppressions/noDoubleCast.js +55 -4
- package/dist/rules/suppressions/noDoubleCast.js.map +1 -1
- package/dist/rules/suppressions/readonlyWrite.d.ts +4 -0
- package/dist/rules/suppressions/readonlyWrite.d.ts.map +1 -0
- package/dist/rules/suppressions/readonlyWrite.js +113 -0
- package/dist/rules/suppressions/readonlyWrite.js.map +1 -0
- package/dist/rules/test-names/colocated.d.ts +4 -1
- package/dist/rules/test-names/colocated.d.ts.map +1 -1
- package/dist/rules/test-names/colocated.js +5 -3
- package/dist/rules/test-names/colocated.js.map +1 -1
- package/dist/rules/test-names/follow.d.ts +4 -1
- package/dist/rules/test-names/follow.d.ts.map +1 -1
- package/dist/rules/test-names/follow.js +5 -3
- package/dist/rules/test-names/follow.js.map +1 -1
- package/dist/unitIoGuard.config.js +2 -2
- package/dist/unitIoGuard.config.js.map +1 -1
- package/package.json +3 -2
- package/src/baseline/format.ts +4 -2
- package/src/baseline/update.ts +1 -1
- package/src/cli/lint.ts +33 -27
- package/src/config/globs.ts +31 -0
- package/src/engine/runRules.ts +7 -2
- package/src/engine/session.ts +10 -5
- package/src/imports/fences/compilePolicy.ts +10 -2
- package/src/inventory/shadcnAlias.ts +1 -1
- package/src/rule.ts +12 -2
- package/src/rules/effect/boundary.ts +1 -1
- package/src/rules/effect/boundaryCalls.ts +1 -1
- package/src/rules/effect/boundaryReference.ts +1 -1
- package/src/rules/files/folderNames.ts +7 -5
- package/src/rules/files/namedAfterExport.ts +6 -7
- package/src/rules/files/otherNames.ts +7 -5
- package/src/rules/noBarrel.ts +1 -1
- package/src/rules/secondNames.ts +7 -1
- package/src/rules/stories/authSql.ts +6 -3
- package/src/rules/stories/collectionOrigins.ts +20 -0
- package/src/rules/stories/httpStatus.ts +6 -3
- package/src/rules/stories/namedValues.ts +7 -5
- package/src/rules/stories/noLimitImports.ts +4 -2
- package/src/rules/stories/origins.ts +12 -8
- package/src/rules/stories/prerequisites.ts +6 -25
- package/src/rules/stories/program.ts +9 -1
- package/src/rules/stories/sources.ts +21 -9
- package/src/rules/stories/specHelpers.ts +4 -2
- package/src/rules/stories/specs.ts +1 -1
- package/src/rules/stories/syntax.ts +0 -5
- package/src/rules/suppressions/hiddenCast.ts +95 -0
- package/src/rules/suppressions/noDoubleCast.ts +61 -5
- package/src/rules/suppressions/readonlyWrite.ts +140 -0
- package/src/rules/test-names/colocated.ts +5 -3
- package/src/rules/test-names/follow.ts +5 -3
- package/src/unitIoGuard.config.ts +3 -3
package/src/baseline/format.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { keyOf } from "#engine/violation.ts";
|
|
|
5
5
|
const Line = Schema.Struct({
|
|
6
6
|
count: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
7
7
|
path: Schema.NonEmptyString,
|
|
8
|
+
reason: Schema.optionalKey(Schema.NonEmptyString),
|
|
8
9
|
rule: Schema.NonEmptyString,
|
|
9
10
|
});
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ const BaselineLine = Schema.fromJsonString(Line);
|
|
|
13
14
|
export interface BaselineEntry {
|
|
14
15
|
readonly count: number;
|
|
15
16
|
readonly file: string;
|
|
17
|
+
readonly reason?: string;
|
|
16
18
|
readonly rule: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -51,10 +53,10 @@ export async function decodeBaseline(raw: string | undefined): Promise<Decoded<r
|
|
|
51
53
|
return issues.length === 0 ? { _tag: "Valid", value: entries } : { _tag: "Invalid", issues };
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
const LINE_KEYS = ["path", "rule", "count"];
|
|
56
|
+
const LINE_KEYS = ["path", "rule", "count", "reason"];
|
|
55
57
|
|
|
56
58
|
export function encodeEntry(entry: BaselineEntry): string {
|
|
57
|
-
return JSON.stringify({ count: entry.count, path: entry.file, rule: entry.rule }, LINE_KEYS);
|
|
59
|
+
return JSON.stringify({ count: entry.count, path: entry.file, reason: entry.reason, rule: entry.rule }, LINE_KEYS);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export function encodeBaseline(entries: readonly BaselineEntry[]): string {
|
package/src/baseline/update.ts
CHANGED
|
@@ -96,7 +96,7 @@ export function prune(
|
|
|
96
96
|
return [];
|
|
97
97
|
}
|
|
98
98
|
moved += Number(now.file !== before.file);
|
|
99
|
-
return [{ after: { count: Math.min(before.count, now.count), file: now.file
|
|
99
|
+
return [{ after: { ...before, count: Math.min(before.count, now.count), file: now.file }, before }];
|
|
100
100
|
});
|
|
101
101
|
return {
|
|
102
102
|
entries: kept.map(({ after }) => after),
|
package/src/cli/lint.ts
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
|
+
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
3
|
import { Console, Effect } from "effect";
|
|
4
|
+
import { withHeavyLock } from "@shivaedev/heavy-lock/withHeavyLock.ts";
|
|
3
5
|
import { looseStagedEntries } from "#baseline/looseStagedEntries.ts";
|
|
4
6
|
import { evaluate, passes } from "#engine/evaluate.ts";
|
|
5
7
|
import { openSession } from "#engine/session.ts";
|
|
6
8
|
import { keyOf } from "#engine/violation.ts";
|
|
7
|
-
import { GateFailed,
|
|
9
|
+
import { GateFailed, SetupFailure } from "#failure.ts";
|
|
8
10
|
import { render } from "#report/render.ts";
|
|
9
11
|
import type { RuleServices } from "#rule.ts";
|
|
10
12
|
|
|
11
|
-
export const lint = Effect.fn("Cli.lint")(
|
|
12
|
-
cwd: string,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
13
|
+
export const lint = Effect.fn("Cli.lint")(
|
|
14
|
+
function* (cwd: string, config: string | undefined, staged = false): Effect.fn.Return<void, SetupFailure | GateFailed, RuleServices> {
|
|
15
|
+
const session = yield* openSession(cwd, config);
|
|
16
|
+
const evaluated = evaluate(session.violations, session.registry, session.baseline.entries, session.config);
|
|
17
|
+
const loose = staged ? yield* looseStagedEntries(session) : [];
|
|
18
|
+
const rejected = new Set(loose.map(({ entry }) => keyOf(entry.rule, entry.file)));
|
|
19
|
+
const outcome = {
|
|
20
|
+
...evaluated,
|
|
21
|
+
looseBaseline: evaluated.looseBaseline.filter(({ entry }) => !rejected.has(keyOf(entry.rule, entry.file))),
|
|
22
|
+
staleBaseline: [...evaluated.staleBaseline, ...loose],
|
|
23
|
+
};
|
|
24
|
+
yield* Console.log(
|
|
25
|
+
render(outcome, {
|
|
26
|
+
baseline: session.config.baseline,
|
|
27
|
+
checked: session.inventory.sources.length,
|
|
28
|
+
descriptions: new Map(session.config.active.map((rule) => [rule.id, rule.description])),
|
|
29
|
+
registry:
|
|
30
|
+
session.config.exceptions.length === 0 ? session.config.registry : `${relative(session.config.root, session.config.file)} exceptions`,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
if (!passes(outcome)) {
|
|
34
|
+
return yield* new GateFailed();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
(effect) =>
|
|
38
|
+
withHeavyLock(effect, { command: "quality lint" }).pipe(
|
|
39
|
+
Effect.catchTag("HeavyLockError", (cause) => new SetupFailure({ cause, message: cause.message })),
|
|
40
|
+
Effect.provide(NodePath.layer),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import ignore from "ignore";
|
|
3
|
+
|
|
4
|
+
const GlobDeclaration = Schema.Struct({
|
|
5
|
+
glob: Schema.NonEmptyString,
|
|
6
|
+
reason: Schema.String.check(Schema.isPattern(/\S/u, { expected: "a reason for this glob" })),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const GlobDeclarations = Schema.Array(GlobDeclaration).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])));
|
|
10
|
+
|
|
11
|
+
type GlobOptions = Readonly<Record<string, readonly (typeof GlobDeclaration.Type)[]>>;
|
|
12
|
+
|
|
13
|
+
export function globPatterns(declarations: readonly (typeof GlobDeclaration.Type)[]): readonly string[] {
|
|
14
|
+
return declarations.map(({ glob }) => glob);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function matchesIgnorePattern(file: string, glob: string): boolean {
|
|
18
|
+
const result = ignore().add(glob).test(file);
|
|
19
|
+
return result.ignored || result.unignored;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function validateGlobs(
|
|
23
|
+
{ files, options }: { readonly files: readonly string[]; readonly options: GlobOptions },
|
|
24
|
+
matches: (file: string, glob: string) => boolean = matchesIgnorePattern,
|
|
25
|
+
): readonly string[] {
|
|
26
|
+
return Object.entries(options).flatMap(([option, declarations]) =>
|
|
27
|
+
declarations.flatMap(({ glob }, index) =>
|
|
28
|
+
files.some((file) => matches(file, glob)) ? [] : [`${option}.${index}.glob: "${glob}" matches no current file. Remove the stale glob.`],
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
}
|
package/src/engine/runRules.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isAbsolute, relative } from "node:path";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { ManifestFailure } from "#adapters/manifestInventory.ts";
|
|
4
|
+
import { SetupFailure } from "#failure.ts";
|
|
4
5
|
import { posix } from "#inventory/ignoreScope.ts";
|
|
5
6
|
import type { Finding, RuleCheck, RuleInputs, RuleServices } from "#rule.ts";
|
|
6
7
|
import type { ActiveLevel, Violation } from "./violation.ts";
|
|
@@ -48,9 +49,13 @@ function violationOf(rule: ActiveRule, root: string, finding: Finding, exception
|
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
function runRule(rule: ActiveRule, inputs: RuleInputs, exceptionFile: string): Effect.Effect<readonly Violation[],
|
|
52
|
+
function runRule(rule: ActiveRule, inputs: RuleInputs, exceptionFile: string): Effect.Effect<readonly Violation[], SetupFailure, RuleServices> {
|
|
52
53
|
return Effect.suspend(() => rule.check(inputs)).pipe(
|
|
53
|
-
Effect.
|
|
54
|
+
Effect.catch((cause) =>
|
|
55
|
+
cause instanceof SetupFailure
|
|
56
|
+
? Effect.fail(new SetupFailure({ cause, message: `rule ${rule.id} failed: ${cause.message}` }))
|
|
57
|
+
: Effect.die(cause),
|
|
58
|
+
),
|
|
54
59
|
Effect.map((findings) => findings.map((finding) => violationOf(rule, inputs.root, finding, exceptionFile))),
|
|
55
60
|
Effect.catchDefect((cause) =>
|
|
56
61
|
cause instanceof ManifestFailure
|
package/src/engine/session.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { Effect } from "effect";
|
|
|
3
3
|
import { setManifestFiles } from "#adapters/manifestInventory.ts";
|
|
4
4
|
import { manifestReader } from "#adapters/manifestReader.ts";
|
|
5
5
|
import { loadConfig, type ResolvedConfig } from "#config/load.ts";
|
|
6
|
-
import {
|
|
7
|
-
import { decodeRegistry, type RegistryEntry } from "#exceptions/registry.ts";
|
|
6
|
+
import type { RegistryEntry } from "#exceptions/registry.ts";
|
|
8
7
|
import { registryEntries } from "#exceptions/registryEntries.ts";
|
|
9
8
|
import { SetupFailure } from "#failure.ts";
|
|
10
9
|
import { collectInventory, type Inventory } from "#inventory/collect.ts";
|
|
@@ -52,9 +51,15 @@ export const openSession = Effect.fn("Engine.openSession")(function* (
|
|
|
52
51
|
configPath: string | undefined,
|
|
53
52
|
): Effect.fn.Return<Session, SetupFailure, RuleServices> {
|
|
54
53
|
const config = yield* loadConfig(cwd, configPath);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
54
|
+
const selection = configPath === undefined ? "" : ` --config ${configPath}`;
|
|
55
|
+
for (const path of new Set([config.registry, "quality/registry.json"])) {
|
|
56
|
+
if ((yield* readInput(config.root, path)) !== undefined) {
|
|
57
|
+
return yield* new SetupFailure({
|
|
58
|
+
message: `${path} holds legacy exceptions. Run \`quality exceptions migrate${selection} --from ${path}\` to move them into ${config.file}.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
57
62
|
const baseline = yield* readBaseline(config);
|
|
58
63
|
const { inventory, violations } = yield* scan(config);
|
|
59
|
-
return { baseline, config, inventory, registry:
|
|
64
|
+
return { baseline, config, inventory, registry: registryEntries(config.exceptions), violations };
|
|
60
65
|
});
|
|
@@ -31,8 +31,16 @@ function crossedBy(policy: readonly CompiledFence[], graph: FenceGraph): readonl
|
|
|
31
31
|
return policy.filter((compiled) => compiled.evaluate(graph).length > 0).map((compiled) => compiled.fence.name);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function exampleIssues(policy: readonly CompiledFence[], fence: Fence): readonly string[] {
|
|
34
|
+
function exampleIssues(policy: readonly CompiledFence[], fence: Fence, scope: PolicyScope): readonly string[] {
|
|
35
35
|
const where = `fence "${fence.name}"`;
|
|
36
|
+
const missing = (["illegal", "legal"] as const).flatMap((kind) =>
|
|
37
|
+
fence.examples[kind].flatMap((step) =>
|
|
38
|
+
typeof step === "string" && !scope.files.includes(step) ? [`${where}: the ${kind} example names "${step}", which is no checked file`] : [],
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
if (missing.length > 0) {
|
|
42
|
+
return missing;
|
|
43
|
+
}
|
|
36
44
|
const illegal = graphOf(fence.examples.illegal);
|
|
37
45
|
const legal = graphOf(fence.examples.legal);
|
|
38
46
|
if (illegal === undefined || legal === undefined) {
|
|
@@ -62,7 +70,7 @@ export function compilePolicy(fences: readonly Fence[], scope: PolicyScope): rea
|
|
|
62
70
|
const issues = [...declarationIssues(fences)];
|
|
63
71
|
const policy = fences.map((fence) => compileFence({ issues, scope }, fence));
|
|
64
72
|
if (issues.length === 0) {
|
|
65
|
-
issues.push(...fences.flatMap((fence) => exampleIssues(policy, fence)));
|
|
73
|
+
issues.push(...fences.flatMap((fence) => exampleIssues(policy, fence, scope)));
|
|
66
74
|
}
|
|
67
75
|
if (issues.length > 0) {
|
|
68
76
|
throw new Error(`the fence policy is invalid:\n${issues.map((issue) => ` - ${issue}`).join("\n")}`);
|
|
@@ -16,7 +16,7 @@ function capture(pattern: string, alias: string): string | undefined {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function pathTarget(alias: string, options: ts.CompilerOptions, directory: string): string | undefined {
|
|
19
|
-
const pathsBase = Reflect.get(options, "pathsBasePath");
|
|
19
|
+
const pathsBase: unknown = Reflect.get(options, "pathsBasePath");
|
|
20
20
|
const base = options.baseUrl ?? (typeof pathsBase === "string" ? pathsBase : directory);
|
|
21
21
|
const patterns = Object.entries(options.paths ?? {}).toSorted(([left], [right]) => right.indexOf("*") - left.indexOf("*"));
|
|
22
22
|
const exact = options.paths?.[alias]?.[0];
|
package/src/rule.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, type FileSystem } from "effect";
|
|
2
2
|
import type { ChildProcessSpawner } from "effect/process";
|
|
3
3
|
import type { Bivariant } from "@shivaedev/types/Bivariant.ts";
|
|
4
|
+
import { validOrFail } from "#decoded.ts";
|
|
4
5
|
import type { ExceptionDeclaration } from "#exceptions/declaration.ts";
|
|
5
6
|
import { describeIssue, type StandardSchemaV1 } from "./standardSchema.ts";
|
|
6
7
|
|
|
@@ -57,6 +58,7 @@ interface RuleDefinition<TId extends string, TOptions, TServices> {
|
|
|
57
58
|
readonly description: string;
|
|
58
59
|
readonly id: TId;
|
|
59
60
|
readonly registrable?: false;
|
|
61
|
+
readonly validate?: (context: RuleContext<TOptions>) => readonly string[];
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
interface RuleDefinitionWithOptions<TId extends string, TInput, TOptions, TServices> extends RuleDefinition<TId, TOptions, TServices> {
|
|
@@ -78,7 +80,9 @@ const noOptions: StandardSchemaV1<undefined, undefined> = {
|
|
|
78
80
|
function configureWith<TInput, TOptions, TServices>(
|
|
79
81
|
schema: StandardSchemaV1<TInput, TOptions>,
|
|
80
82
|
check: RuleDefinition<string, TOptions, TServices>["check"],
|
|
83
|
+
id: string,
|
|
81
84
|
absent: unknown,
|
|
85
|
+
validate?: RuleDefinition<string, TOptions, TServices>["validate"],
|
|
82
86
|
) {
|
|
83
87
|
return async (options: unknown): Promise<Configured<TServices>> => {
|
|
84
88
|
const result = await schema["~standard"].validate(options ?? absent);
|
|
@@ -91,6 +95,12 @@ function configureWith<TInput, TOptions, TServices>(
|
|
|
91
95
|
check: (inputs) =>
|
|
92
96
|
Effect.scoped(
|
|
93
97
|
Effect.gen(function* () {
|
|
98
|
+
const context = { ...inputs, options: value };
|
|
99
|
+
const issues = validate?.(context).map((issue) => `rules.${id}.options: ${issue}`) ?? [];
|
|
100
|
+
yield* validOrFail(
|
|
101
|
+
inputs.configFile ?? "quality.config.ts",
|
|
102
|
+
issues.length === 0 ? { _tag: "Valid", value: undefined } : { _tag: "Invalid", issues },
|
|
103
|
+
);
|
|
94
104
|
const signal = yield* Effect.abortSignal;
|
|
95
105
|
const checked = check({ ...inputs, options: value, signal });
|
|
96
106
|
return yield* Effect.isEffect(checked) ? checked : Effect.promise(() => Promise.resolve(checked));
|
|
@@ -111,7 +121,7 @@ export function defineRule<const TId extends string, TInput, TOptions, TServices
|
|
|
111
121
|
): Rule<TId, TInput, TServices> | Rule<TId, undefined, TServices> {
|
|
112
122
|
const configure =
|
|
113
123
|
definition.options === undefined
|
|
114
|
-
? configureWith(noOptions, definition.check, undefined)
|
|
115
|
-
: configureWith(definition.options, definition.check, {});
|
|
124
|
+
? configureWith(noOptions, definition.check, definition.id, undefined, definition.validate)
|
|
125
|
+
: configureWith(definition.options, definition.check, definition.id, {}, definition.validate);
|
|
116
126
|
return { configure, description: definition.description, id: definition.id, registrable: definition.registrable ?? true };
|
|
117
127
|
}
|
|
@@ -93,7 +93,7 @@ export const effectBoundary = defineRule({
|
|
|
93
93
|
return [...groups.values()].flatMap((sources) => checkBoundary({ ...inputs, sources }));
|
|
94
94
|
},
|
|
95
95
|
description:
|
|
96
|
-
"Use Effect instead of Promise syntax and parameters, synchronous Node IO, throwing helper calls or Effect.sync with throwing APIs. Runners belong at entry points, tool configs and tests. Only adapters/ and test-support/ folders are exempt. Use Effect services and tagged errors; bridge outside libraries in adapters/. No config exceptions or inline suppressions; baseline existing debt.",
|
|
96
|
+
"Use Effect instead of Promise syntax and parameters, synchronous Node IO, throwing helper calls or Effect.sync with throwing APIs. Runners belong at entry points (including main.tsx and entry.tsx), tool configs and tests. Only adapters/ and test-support/ folders are exempt; calls to throwing helpers defined in adapters/ are accepted. Use Effect services and tagged errors; bridge outside libraries in adapters/. No config exceptions or inline suppressions; baseline existing debt.",
|
|
97
97
|
id: "effect/boundary",
|
|
98
98
|
registrable: false,
|
|
99
99
|
});
|
|
@@ -77,7 +77,7 @@ export function boundaryCalls(checker: ts.TypeChecker) {
|
|
|
77
77
|
}
|
|
78
78
|
function guard(call: ts.CallExpression): boolean {
|
|
79
79
|
const body = functionBody(checker, call.expression);
|
|
80
|
-
return body !== undefined && throws(body);
|
|
80
|
+
return body !== undefined && !/(?:^|\/)adapters\//u.test(body.getSourceFile().fileName) && throws(body);
|
|
81
81
|
}
|
|
82
82
|
function unsafeSync(call: ts.CallExpression): boolean {
|
|
83
83
|
const callback = call.arguments[0];
|
|
@@ -66,7 +66,7 @@ export function boundaryReference(checker: ts.TypeChecker, node: ts.Node, seen =
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function boundaryEntryPoint(path: string, source: ts.SourceFile, checker: ts.TypeChecker): boolean {
|
|
69
|
-
if (/(?:^|\/)(?:cli|main|[^/]+-cli)\.[cm]?[jt]sx?$|\.(?:config|test|spec)\.[cm]?[jt]sx?$/u.test(path)) {
|
|
69
|
+
if (/(?:^|\/)(?:cli|main|entry|[^/]+-cli)\.[cm]?[jt]sx?$|\.(?:config|test|spec)\.[cm]?[jt]sx?$/u.test(path)) {
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
72
|
function visit(node: ts.Node): boolean {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { Order, Schema } from "effect";
|
|
3
3
|
import ignore, { type Ignore } from "ignore";
|
|
4
|
+
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
4
5
|
import { nativeNames } from "#naming/nativeNames.ts";
|
|
5
6
|
import { packageLayout } from "#naming/packageLayout.ts";
|
|
6
7
|
import { KEBAB, PASCAL } from "#naming/words.ts";
|
|
@@ -11,8 +12,8 @@ const SNAKE = /^[a-z0-9]+(?:_[a-z0-9]+)*$/u;
|
|
|
11
12
|
const CODE = /\.[cm]?[jt]sx?$/u;
|
|
12
13
|
|
|
13
14
|
const FolderNamesOptions = Schema.Struct({
|
|
14
|
-
content:
|
|
15
|
-
toolOwned:
|
|
15
|
+
content: GlobDeclarations,
|
|
16
|
+
toolOwned: GlobDeclarations,
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
function foldersIn(files: readonly string[]): readonly string[] {
|
|
@@ -75,11 +76,11 @@ export const folderNames = defineRule({
|
|
|
75
76
|
check: async ({ files, options, readText }) => {
|
|
76
77
|
const layout = await packageLayout({ files, readText });
|
|
77
78
|
const context: Context = {
|
|
78
|
-
content: ignore().add([...options.content]),
|
|
79
|
+
content: ignore().add([...globPatterns(options.content)]),
|
|
79
80
|
names: layout.names,
|
|
80
81
|
native: nativeNames(files).folders,
|
|
81
82
|
stems: stemsIn(files),
|
|
82
|
-
toolOwned: ignore().add([...options.toolOwned]),
|
|
83
|
+
toolOwned: ignore().add([...globPatterns(options.toolOwned)]),
|
|
83
84
|
};
|
|
84
85
|
return foldersIn(files).flatMap((folder): readonly Finding[] => {
|
|
85
86
|
const message = messageFor(folder, context);
|
|
@@ -90,4 +91,5 @@ export const folderNames = defineRule({
|
|
|
90
91
|
"A package folder is named after its package, a module folder after its main file, a content folder in snake_case and every other folder in kebab-case.",
|
|
91
92
|
id: "files/folder-names",
|
|
92
93
|
options: Schema.toStandardSchemaV1(FolderNamesOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
94
|
+
validate: validateGlobs,
|
|
93
95
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { Schema } from "effect";
|
|
3
3
|
import ignore from "ignore";
|
|
4
|
+
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
4
5
|
import { exportFits } from "#naming/exportFits.ts";
|
|
5
6
|
import { mainExport } from "#naming/mainExport.ts";
|
|
6
7
|
import { isMigrationFile } from "#naming/migrationFile.ts";
|
|
@@ -28,7 +29,7 @@ const SHAPES =
|
|
|
28
29
|
"The file name and the names of its folders spell the export, in any order, and the file's first letter follows the export's case: listItems in items/ is items/list.ts, ItemPanel is ItemPanel.tsx or item/Panel.tsx.";
|
|
29
30
|
|
|
30
31
|
const NamedAfterExportOptions = Schema.Struct({
|
|
31
|
-
toolOwned:
|
|
32
|
+
toolOwned: GlobDeclarations,
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
function stemOf(path: string): string {
|
|
@@ -52,9 +53,6 @@ function nameFinding(file: SourceFile, stem: string, folders: readonly string[])
|
|
|
52
53
|
? undefined
|
|
53
54
|
: `"${stem}" exports nothing, so it is named in camelCase, such as setupTests.ts. A file that a package.json script or bin runs is kebab-case.`;
|
|
54
55
|
}
|
|
55
|
-
if (exports.length === 1 && only.constant) {
|
|
56
|
-
return `"${stem}" exports only the constant ${only.name}. Constants live in a topic file with related constants, such as limits.ts holding MAX_ITEMS and MAX_DEPTH.`;
|
|
57
|
-
}
|
|
58
56
|
if (exports.some((entry) => exportFits(entry.name, stem, folders))) {
|
|
59
57
|
return undefined;
|
|
60
58
|
}
|
|
@@ -86,13 +84,14 @@ function findingsOf(file: SourceFile, layout: PackageLayout): readonly Finding[]
|
|
|
86
84
|
export const namedAfterExport = defineRule({
|
|
87
85
|
check: async ({ files, options, readText, sources }) => {
|
|
88
86
|
const layout = await packageLayout({ files, readText });
|
|
89
|
-
const toolOwned = ignore().add([...DEFAULT_TOOL_OWNED, ...options.toolOwned]);
|
|
87
|
+
const toolOwned = ignore().add([...DEFAULT_TOOL_OWNED, ...globPatterns(options.toolOwned)]);
|
|
90
88
|
return sources
|
|
91
89
|
.filter((file) => !(TEST.test(file.path) || isMigrationFile(file.path) || toolOwned.ignores(file.path)))
|
|
92
90
|
.flatMap((file) => findingsOf(file, layout));
|
|
93
91
|
},
|
|
94
92
|
description:
|
|
95
|
-
"A file is named after its main export, with its folders as the prefix; a file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
|
|
93
|
+
"A file is named after its main export, including a single constant, with its folders as the prefix; a file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
|
|
96
94
|
id: "files/named-after-export",
|
|
97
95
|
options: Schema.toStandardSchemaV1(NamedAfterExportOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
96
|
+
validate: validateGlobs,
|
|
98
97
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { Schema } from "effect";
|
|
3
3
|
import ignore, { type Ignore } from "ignore";
|
|
4
|
+
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
4
5
|
import { nativeNames } from "#naming/nativeNames.ts";
|
|
5
6
|
import { CAMEL, KEBAB } from "#naming/words.ts";
|
|
6
7
|
import { defineRule, type Finding } from "#rule.ts";
|
|
@@ -39,8 +40,8 @@ const SNAKE = /^[a-z0-9]+(?:__?[a-z0-9]+)*$/u;
|
|
|
39
40
|
const CODE = /\.[cm]?[jt]sx?$/u;
|
|
40
41
|
|
|
41
42
|
const OtherNamesOptions = Schema.Struct({
|
|
42
|
-
content:
|
|
43
|
-
toolOwned:
|
|
43
|
+
content: GlobDeclarations,
|
|
44
|
+
toolOwned: GlobDeclarations,
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
function stylesheetMessage(path: string, stem: string, importedBy: readonly string[]): string | undefined {
|
|
@@ -88,10 +89,10 @@ function messageFor(path: string, context: Context): string | undefined {
|
|
|
88
89
|
export const otherNames = defineRule({
|
|
89
90
|
check: async ({ files, options, readText, sources }) => {
|
|
90
91
|
const context: Context = {
|
|
91
|
-
content: ignore().add([...options.content]),
|
|
92
|
+
content: ignore().add([...globPatterns(options.content)]),
|
|
92
93
|
native: nativeNames(files),
|
|
93
94
|
stylesheets: await stylesheetImporters({ files, readText, sources }),
|
|
94
|
-
toolOwned: ignore().add([...DEFAULT_TOOL_OWNED, ...options.toolOwned]),
|
|
95
|
+
toolOwned: ignore().add([...DEFAULT_TOOL_OWNED, ...globPatterns(options.toolOwned)]),
|
|
95
96
|
};
|
|
96
97
|
return files.flatMap((path): readonly Finding[] => {
|
|
97
98
|
const message = messageFor(path, context);
|
|
@@ -102,4 +103,5 @@ export const otherNames = defineRule({
|
|
|
102
103
|
"Documents, data, assets and GritQL files are kebab-case, a stylesheet that one component imports is named after it, a Prisma schema is camelCase and content is snake_case.",
|
|
103
104
|
id: "files/other-names",
|
|
104
105
|
options: Schema.toStandardSchemaV1(OtherNamesOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
106
|
+
validate: validateGlobs,
|
|
105
107
|
});
|
package/src/rules/noBarrel.ts
CHANGED
|
@@ -24,6 +24,6 @@ export const noBarrel = defineRule({
|
|
|
24
24
|
return findings;
|
|
25
25
|
}),
|
|
26
26
|
description:
|
|
27
|
-
"Name modules after their purpose; import values from their defining module instead of exporting aliases, facades or unchanged forwarding calls.",
|
|
27
|
+
"Name modules after their purpose; import values from their defining module instead of exporting aliases, facades or unchanged forwarding calls. Wrappers that supply explicit type arguments keep their own meaning.",
|
|
28
28
|
id: "structure/no-barrel",
|
|
29
29
|
});
|
package/src/rules/secondNames.ts
CHANGED
|
@@ -18,7 +18,13 @@ function forwarding(node: ts.FunctionLikeDeclaration, origins: ReadonlyMap<strin
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
const call = returned(node.body);
|
|
21
|
-
if (
|
|
21
|
+
if (
|
|
22
|
+
call === undefined
|
|
23
|
+
|| !ts.isCallExpression(call)
|
|
24
|
+
|| call.questionDotToken !== undefined
|
|
25
|
+
|| call.typeArguments !== undefined
|
|
26
|
+
|| call.arguments.length !== node.parameters.length
|
|
27
|
+
) {
|
|
22
28
|
return undefined;
|
|
23
29
|
}
|
|
24
30
|
const visible = new Map(origins);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matchesGlob } from "node:path";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
2
4
|
import { defineRule } from "#rule.ts";
|
|
3
5
|
import { matchesAny } from "./matchesAny.ts";
|
|
4
6
|
import { sqlTexts } from "./sqlText.ts";
|
|
5
7
|
|
|
6
8
|
const AuthSqlOptions = Schema.Struct({
|
|
7
|
-
owners:
|
|
9
|
+
owners: GlobDeclarations,
|
|
8
10
|
});
|
|
9
11
|
|
|
10
12
|
const TOKENS = /--[^\n]*|\/\*[\s\S]*?\*\/|'(?:''|[^'])*'|"(?:""|[^"])*"|[\w$]+|[.,;()]/gu;
|
|
@@ -126,7 +128,7 @@ function authTableIn(text: string): boolean {
|
|
|
126
128
|
export const authSql = defineRule({
|
|
127
129
|
check: async ({ options, ...inputs }) =>
|
|
128
130
|
(await sqlTexts(inputs))
|
|
129
|
-
.filter((query) => !matchesAny(query.file, options.owners) && authTableIn(query.text))
|
|
131
|
+
.filter((query) => !matchesAny(query.file, globPatterns(options.owners)) && authTableIn(query.text))
|
|
130
132
|
.map((query) => ({
|
|
131
133
|
file: query.file,
|
|
132
134
|
line: query.line,
|
|
@@ -136,4 +138,5 @@ export const authSql = defineRule({
|
|
|
136
138
|
description: "Apps reference user IDs by foreign key and use identity for account data.",
|
|
137
139
|
id: "boundaries/auth-sql",
|
|
138
140
|
options: Schema.toStandardSchemaV1(AuthSqlOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
141
|
+
validate: (context) => validateGlobs(context, matchesGlob),
|
|
139
142
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export type Origin = "factory" | "kit" | "story" | "plain" | "suite" | "vitest" | "stories" | "function" | readonly Origin[] | undefined;
|
|
4
|
+
|
|
5
|
+
export function commonOrigin(values: readonly Origin[]): Origin {
|
|
6
|
+
const first = values[0];
|
|
7
|
+
if (values.length === 0 || values.every((value) => value === first)) {
|
|
8
|
+
return first;
|
|
9
|
+
}
|
|
10
|
+
if (typeof first !== "object" || !values.every((value) => typeof value === "object" && value.length === first.length)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return first.map((_, index) => commonOrigin(values.map((value) => (typeof value === "object" ? value[index] : undefined))));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function iterationOrigin(node: ts.Node, origin: (node: ts.Node) => Origin): Origin {
|
|
17
|
+
const loop = node.parent.parent;
|
|
18
|
+
const values = ts.isForOfStatement(loop) ? origin(loop.expression) : undefined;
|
|
19
|
+
return typeof values === "object" ? commonOrigin(values) : undefined;
|
|
20
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matchesGlob } from "node:path";
|
|
2
|
+
import { Schema } from "effect";
|
|
2
3
|
import ts from "typescript";
|
|
4
|
+
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
3
5
|
import { defineRule } from "#rule.ts";
|
|
4
6
|
import { matchesAny } from "./matchesAny.ts";
|
|
5
7
|
import { memberName, nodesWhere, numericValue, syntaxFindings, unwrapped } from "./syntax.ts";
|
|
@@ -8,7 +10,7 @@ const MESSAGE =
|
|
|
8
10
|
"Branches on an HTTP error status outside the HTTP edge. Handle the typed domain error here and translate it to an HTTP status in the configured edge module.";
|
|
9
11
|
|
|
10
12
|
const HttpStatusOptions = Schema.Struct({
|
|
11
|
-
edge:
|
|
13
|
+
edge: GlobDeclarations,
|
|
12
14
|
});
|
|
13
15
|
|
|
14
16
|
const COMPARISONS = new Set([
|
|
@@ -48,9 +50,10 @@ function statusBranch(node: ts.Node): boolean {
|
|
|
48
50
|
export const httpStatus = defineRule({
|
|
49
51
|
check: ({ sources, options }) =>
|
|
50
52
|
sources
|
|
51
|
-
.filter((file) => !matchesAny(file.path, options.edge))
|
|
53
|
+
.filter((file) => !matchesAny(file.path, globPatterns(options.edge)))
|
|
52
54
|
.flatMap((file) => syntaxFindings(file, (source) => nodesWhere(source, statusBranch), MESSAGE)),
|
|
53
55
|
description: "HTTP status numbers belong at the repository's HTTP edge; domain code handles typed errors.",
|
|
54
56
|
id: "boundaries/http-status",
|
|
55
57
|
options: Schema.toStandardSchemaV1(HttpStatusOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
58
|
+
validate: (context) => validateGlobs(context, matchesGlob),
|
|
56
59
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { defineRule } from "#rule.ts";
|
|
3
|
-
import {
|
|
4
|
+
import { storySources } from "./sources.ts";
|
|
5
|
+
import { memberName, nodesWhere, numericValue, syntaxFindings, unwrapped } from "./syntax.ts";
|
|
4
6
|
|
|
5
7
|
const MESSAGE =
|
|
6
8
|
'Passes a numeric literal or a matcher-only spec-local numeric const to toBe or toHaveLength. Assert the observed items, write the literal where accepted (zero or a process exitCode), or derive the value from the story\'s inputs. For HTTP statuses, import * as HttpStatus from "effect/http/HttpStatus" and use HttpStatus.fromLiteral("NotFound"), for example.';
|
|
@@ -87,10 +89,9 @@ function numericAssertion(node: ts.Node): boolean {
|
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export const namedValues = defineRule({
|
|
90
|
-
check: (
|
|
91
|
-
|
|
92
|
-
.
|
|
93
|
-
.flatMap((file) =>
|
|
92
|
+
check: (inputs) =>
|
|
93
|
+
Effect.map(storySources(inputs), (stories) =>
|
|
94
|
+
stories.flatMap((file) =>
|
|
94
95
|
syntaxFindings(
|
|
95
96
|
file,
|
|
96
97
|
(source) => {
|
|
@@ -100,6 +101,7 @@ export const namedValues = defineRule({
|
|
|
100
101
|
MESSAGE,
|
|
101
102
|
),
|
|
102
103
|
),
|
|
104
|
+
),
|
|
103
105
|
description: "Stories assert observed items or named values instead of bare counts and numbers.",
|
|
104
106
|
id: "tests/named-values",
|
|
105
107
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { defineRule } from "#rule.ts";
|
|
3
|
-
import {
|
|
4
|
+
import { storySources } from "./sources.ts";
|
|
5
|
+
import { memberName, nodesWhere, syntaxFindings, unwrapped } from "./syntax.ts";
|
|
4
6
|
|
|
5
7
|
const MESSAGE =
|
|
6
8
|
"Imports a MAX_* constant from a limits module. Tell a story about the observed behavior instead of asserting a copy of the implementation's cap.";
|
|
@@ -74,7 +76,7 @@ function capImports(source: ts.SourceFile): readonly ts.Node[] {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
export const noLimitImports = defineRule({
|
|
77
|
-
check: (
|
|
79
|
+
check: (inputs) => Effect.map(storySources(inputs), (stories) => stories.flatMap((file) => syntaxFindings(file, capImports, MESSAGE))),
|
|
78
80
|
description: "Stories prove behavior instead of importing implementation caps from limits modules.",
|
|
79
81
|
id: "tests/no-limit-imports",
|
|
80
82
|
});
|