@shivaedev/quality 0.73.2 → 0.74.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 +16 -0
- package/README.md +8 -0
- package/dist/adapters/buildEntryPaths.d.ts +1 -1
- package/dist/adapters/buildEntryPaths.d.ts.map +1 -1
- package/dist/adapters/buildEntryPaths.js +9 -6
- package/dist/adapters/buildEntryPaths.js.map +1 -1
- package/dist/adapters/bundlerEntries.d.ts.map +1 -1
- package/dist/adapters/bundlerEntries.js +6 -6
- package/dist/adapters/bundlerEntries.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts +2 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +29 -4
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +8 -3
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/spawnedEntries.d.ts.map +1 -1
- package/dist/adapters/spawnedEntries.js +4 -5
- package/dist/adapters/spawnedEntries.js.map +1 -1
- package/dist/config/decode.d.ts +1 -0
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +1 -0
- package/dist/config/decode.js.map +1 -1
- package/dist/config/load.d.ts +1 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +1 -0
- package/dist/config/load.js.map +1 -1
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/engine/runRules.js +1 -1
- package/dist/engine/runRules.js.map +1 -1
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +1 -0
- package/dist/engine/session.js.map +1 -1
- package/dist/rule.d.ts +1 -0
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js.map +1 -1
- package/dist/rules/effect/program.d.ts +4 -1
- package/dist/rules/effect/program.d.ts.map +1 -1
- package/dist/rules/effect/program.js +13 -3
- package/dist/rules/effect/program.js.map +1 -1
- package/dist/rules/effect/serviceParameters.d.ts.map +1 -1
- package/dist/rules/effect/serviceParameters.js +8 -5
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/testing/ruleChecks.d.ts +16 -0
- package/dist/testing/ruleChecks.d.ts.map +1 -0
- package/dist/testing/ruleChecks.js +42 -0
- package/dist/testing/ruleChecks.js.map +1 -0
- package/dist/testing/ruleStory.d.ts +7 -11
- package/dist/testing/ruleStory.d.ts.map +1 -1
- package/dist/testing/ruleStory.js +3 -19
- package/dist/testing/ruleStory.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/buildEntryPaths.ts +10 -6
- package/src/adapters/bundlerEntries.ts +6 -10
- package/src/adapters/knip/configuration.ts +35 -4
- package/src/adapters/knip/run.ts +8 -3
- package/src/adapters/spawnedEntries.ts +4 -5
- package/src/config/decode.ts +1 -0
- package/src/config/load.ts +2 -0
- package/src/config.ts +1 -0
- package/src/engine/runRules.ts +1 -1
- package/src/engine/session.ts +1 -0
- package/src/rule.ts +1 -0
- package/src/rules/effect/program.ts +14 -4
- package/src/rules/effect/serviceParameters.ts +9 -6
- package/src/testing/ruleChecks.ts +57 -0
- package/src/testing/ruleStory.ts +4 -26
package/src/config/load.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { Declaration } from "#rules/suppressions/biome/declarations.ts";
|
|
|
14
14
|
export interface ResolvedConfig extends ResolvedRules, InventoryScope {
|
|
15
15
|
readonly baseline: string;
|
|
16
16
|
readonly biomeDeclarations: readonly Declaration[];
|
|
17
|
+
readonly entries: readonly string[];
|
|
17
18
|
readonly exceptions: readonly ExceptionDeclaration[];
|
|
18
19
|
readonly file: string;
|
|
19
20
|
readonly nonEffectFolders: readonly string[];
|
|
@@ -33,6 +34,7 @@ function resolved(root: string, file: string, config: ConfigInput, rules: Resolv
|
|
|
33
34
|
...rules,
|
|
34
35
|
baseline: config.baseline ?? "quality-baseline.jsonl",
|
|
35
36
|
biomeDeclarations: biomeDeclarations(config),
|
|
37
|
+
entries: config.entries ?? [],
|
|
36
38
|
exceptions: config.exceptions ?? [],
|
|
37
39
|
exclude: [],
|
|
38
40
|
extensions: config.extensions ?? DEFAULT_EXTENSIONS,
|
package/src/config.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type BuiltInRules = typeof builtInRules;
|
|
|
16
16
|
|
|
17
17
|
export interface QualityConfig<TLocal extends readonly RegisteredRule<unknown>[] = readonly RegisteredRule<unknown>[]> {
|
|
18
18
|
readonly baseline?: string;
|
|
19
|
+
readonly entries?: readonly string[];
|
|
19
20
|
readonly exceptions?: readonly ExceptionDeclaration[];
|
|
20
21
|
readonly extensions?: readonly string[];
|
|
21
22
|
readonly local?: TLocal;
|
package/src/engine/runRules.ts
CHANGED
|
@@ -104,7 +104,7 @@ export const runRules = Effect.fn("Engine.runRules")(function* (rules: readonly
|
|
|
104
104
|
const results = yield* Effect.forEach(
|
|
105
105
|
rules.filter((rule) => rule !== validation),
|
|
106
106
|
(rule) => runRule(rule, inputs, inputs.configFile ?? "quality.config.ts"),
|
|
107
|
-
{ concurrency:
|
|
107
|
+
{ concurrency: 2 },
|
|
108
108
|
);
|
|
109
109
|
const seen = new Set<string>();
|
|
110
110
|
return results.flat().filter((finding) => {
|
package/src/engine/session.ts
CHANGED
|
@@ -38,6 +38,7 @@ export const scan = Effect.fn("Engine.scan")(function* (
|
|
|
38
38
|
setManifestFiles(readText, inventory.manifestFiles);
|
|
39
39
|
const inputs = {
|
|
40
40
|
configFile: relative(config.root, config.file),
|
|
41
|
+
entries: config.entries,
|
|
41
42
|
exceptions: config.exceptions,
|
|
42
43
|
files: inventory.files,
|
|
43
44
|
nonEffectFolders: config.nonEffectFolders,
|
package/src/rule.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface SourceFile {
|
|
|
24
24
|
|
|
25
25
|
export interface RuleInputs {
|
|
26
26
|
readonly configFile?: string;
|
|
27
|
+
readonly entries?: readonly string[];
|
|
27
28
|
readonly exceptions?: readonly ExceptionDeclaration[];
|
|
28
29
|
readonly files: readonly string[];
|
|
29
30
|
readonly nonEffectFolders?: readonly string[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
1
|
+
import { join, relative, sep } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { projectsFor } from "#adapters/imports/projects.ts";
|
|
4
4
|
import type { RuleInputs } from "#rule.ts";
|
|
5
5
|
|
|
6
6
|
export function effectProgram(inputs: RuleInputs, externalTypes = true, roots: readonly string[] = []): ts.Program {
|
|
7
|
-
return effectPrograms(inputs, externalTypes, roots)(inputs.sources);
|
|
7
|
+
return effectPrograms(inputs, externalTypes, roots).create(inputs.sources);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function effectPrograms(inputs: RuleInputs, externalTypes = true, roots: readonly string[] = []) {
|
|
@@ -42,6 +42,16 @@ export function effectPrograms(inputs: RuleInputs, externalTypes = true, roots:
|
|
|
42
42
|
}
|
|
43
43
|
return source;
|
|
44
44
|
};
|
|
45
|
-
return
|
|
46
|
-
|
|
45
|
+
return {
|
|
46
|
+
create: (sources: RuleInputs["sources"]): ts.Program =>
|
|
47
|
+
ts.createProgram([...sources.map((source) => join(inputs.root, source.path)), ...roots], options, host),
|
|
48
|
+
release: () => {
|
|
49
|
+
for (const file of sourceFiles.keys()) {
|
|
50
|
+
const path = relative(inputs.root, file);
|
|
51
|
+
if (!path.split(sep).includes("node_modules")) {
|
|
52
|
+
sourceFiles.delete(file);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
47
57
|
}
|
|
@@ -2,7 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
4
4
|
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
5
|
-
import { defineRule, type RuleInputs } from "#rule.ts";
|
|
5
|
+
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
6
6
|
import { effectPrograms } from "#rules/effect/program.ts";
|
|
7
7
|
import { serviceCatalog } from "#rules/effect/serviceCatalog.ts";
|
|
8
8
|
import { serviceFindings } from "#rules/effect/serviceFindings.ts";
|
|
@@ -22,16 +22,19 @@ export const serviceParameters = defineRule({
|
|
|
22
22
|
files.push(source);
|
|
23
23
|
groups.set(group, files);
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const programs = effectPrograms(inputs);
|
|
26
|
+
const findings: Finding[] = [];
|
|
27
|
+
for (const files of groups.values()) {
|
|
28
|
+
const program = programs.create(files);
|
|
28
29
|
const checker = program.getTypeChecker();
|
|
29
30
|
const sources = files.flatMap((file) => {
|
|
30
31
|
const source = program.getSourceFile(join(inputs.root, file.path));
|
|
31
32
|
return source === undefined ? [] : [source];
|
|
32
33
|
});
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
findings.push(...serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker, names)));
|
|
35
|
+
programs.release();
|
|
36
|
+
}
|
|
37
|
+
return findings;
|
|
35
38
|
}),
|
|
36
39
|
description:
|
|
37
40
|
"Exported and local functions and public methods take services from Effect's environment, including aliases, constraints, inferred/destructured parameters and factory returns. Service keys/classes, non-empty Contexts and implementation shapes are services; Effect/Stream requirements are computations. Service implementation methods, framework callbacks, module-level React components and their props, owned initializer state, foreign host callbacks in object literals and classes, owned foreign adapter resources and Layer constructors are accepted. Within Effect code, test-support/ folders are exempt. The fixed adapters/ convention bridges outside libraries to Effect values; adapters still follow this rule and ambient runtime bans. No config exceptions or inline suppressions; baseline existing debt.",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Cause, Effect, Path } from "effect";
|
|
2
|
+
import { configureRegistered } from "#adapters/rule.ts";
|
|
3
|
+
import type { Findings, RegisteredRule, Rule, RuleInputs } from "#rule.ts";
|
|
4
|
+
import type { Run } from "#testing/adapters/cli.ts";
|
|
5
|
+
import { scanned } from "#testing/adapters/imports.ts";
|
|
6
|
+
|
|
7
|
+
export interface RuleEngine {
|
|
8
|
+
answer: Run | undefined;
|
|
9
|
+
failure: string | undefined;
|
|
10
|
+
findings: Findings | undefined;
|
|
11
|
+
readonly root: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ruleChecks(engine: RuleEngine, tell: (line: string) => void) {
|
|
15
|
+
return {
|
|
16
|
+
check: Effect.fn("RuleStory.check")(function* <TInput>(
|
|
17
|
+
rule: Rule<string, TInput>,
|
|
18
|
+
options?: TInput,
|
|
19
|
+
directory = ".",
|
|
20
|
+
entries?: readonly string[],
|
|
21
|
+
) {
|
|
22
|
+
tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
23
|
+
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
24
|
+
if (configured._tag === "Invalid") {
|
|
25
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
26
|
+
}
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const scannedInputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
29
|
+
const inputs: RuleInputs = entries === undefined ? scannedInputs : { ...scannedInputs, entries };
|
|
30
|
+
engine.findings = yield* configured.check(inputs);
|
|
31
|
+
return engine.findings;
|
|
32
|
+
}),
|
|
33
|
+
checkOutcome: Effect.fn("RuleStory.checkOutcome")(function* <TInput>(rule: Rule<string, TInput>, entries: readonly string[]) {
|
|
34
|
+
tell(`quality checks ${rule.id} with declared entries`);
|
|
35
|
+
const configured = yield* Effect.promise(() => rule.configure(undefined));
|
|
36
|
+
if (configured._tag === "Invalid") {
|
|
37
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
38
|
+
}
|
|
39
|
+
const inputs = yield* Effect.promise(() => scanned(engine.root));
|
|
40
|
+
const result = yield* Effect.exit(configured.check({ ...inputs, entries }));
|
|
41
|
+
if (result._tag === "Failure") {
|
|
42
|
+
engine.failure = Cause.pretty(result.cause);
|
|
43
|
+
return "failed";
|
|
44
|
+
}
|
|
45
|
+
engine.failure = undefined;
|
|
46
|
+
engine.findings = result.value;
|
|
47
|
+
return "passed";
|
|
48
|
+
}),
|
|
49
|
+
failureMessage: () =>
|
|
50
|
+
engine.failure === undefined ? Effect.die(new Error("Run a failed check before reading its failure message")) : Effect.succeed(engine.failure),
|
|
51
|
+
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {
|
|
52
|
+
tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
53
|
+
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
54
|
+
return configured._tag === "Invalid" ? configured.issues : [];
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
package/src/testing/ruleStory.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
2
|
import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
|
|
3
|
-
import { configureRegistered } from "#adapters/rule.ts";
|
|
4
3
|
import { services } from "#cli/runMain.ts";
|
|
5
|
-
import type { Finding
|
|
4
|
+
import type { Finding } from "#rule.ts";
|
|
6
5
|
import { type Run, runQuality } from "#testing/adapters/cli.ts";
|
|
7
|
-
import { scanned } from "#testing/adapters/imports.ts";
|
|
8
6
|
import { packageRoot, type SeedFile } from "#testing/adapters/tree.ts";
|
|
9
|
-
|
|
10
|
-
interface RuleEngine {
|
|
11
|
-
answer: Run | undefined;
|
|
12
|
-
findings: Findings | undefined;
|
|
13
|
-
readonly root: string;
|
|
14
|
-
}
|
|
7
|
+
import { type RuleEngine, ruleChecks } from "#testing/ruleChecks.ts";
|
|
15
8
|
|
|
16
9
|
const writeAll = Effect.fn("RuleStory.writeAll")(function* (root: string, files: readonly SeedFile[]) {
|
|
17
10
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -64,7 +57,7 @@ export function makeRuleStory() {
|
|
|
64
57
|
Effect.gen(function* () {
|
|
65
58
|
const fs = yield* FileSystem.FileSystem;
|
|
66
59
|
const root = yield* fs.makeTempDirectoryScoped({ prefix: "quality-rule-" });
|
|
67
|
-
const engine: RuleEngine = { answer: undefined, findings: undefined, root };
|
|
60
|
+
const engine: RuleEngine = { answer: undefined, failure: undefined, findings: undefined, root };
|
|
68
61
|
return engine;
|
|
69
62
|
}),
|
|
70
63
|
inspect: ({ findings }) => ({ findings }),
|
|
@@ -72,17 +65,7 @@ export function makeRuleStory() {
|
|
|
72
65
|
name: "Quality rule",
|
|
73
66
|
stages: ["repository"],
|
|
74
67
|
verbs: (engine, story) => ({
|
|
75
|
-
|
|
76
|
-
story.tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
77
|
-
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
78
|
-
if (configured._tag === "Invalid") {
|
|
79
|
-
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
80
|
-
}
|
|
81
|
-
const path = yield* Path.Path;
|
|
82
|
-
const inputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
83
|
-
engine.findings = yield* configured.check(inputs);
|
|
84
|
-
return engine.findings;
|
|
85
|
-
}),
|
|
68
|
+
...ruleChecks(engine, story.tell),
|
|
86
69
|
findings: () => checked(engine),
|
|
87
70
|
gate: Effect.fn("RuleStory.gate")(function* () {
|
|
88
71
|
story.tell("quality runs the repository gate");
|
|
@@ -99,11 +82,6 @@ export function makeRuleStory() {
|
|
|
99
82
|
),
|
|
100
83
|
locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
|
|
101
84
|
messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
|
|
102
|
-
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {
|
|
103
|
-
story.tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
104
|
-
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
105
|
-
return configured._tag === "Invalid" ? configured.issues : [];
|
|
106
|
-
}),
|
|
107
85
|
removes: Effect.fn("RuleStory.removes")(function* (path: string) {
|
|
108
86
|
story.tell(`the author removes ${path}`);
|
|
109
87
|
const fs = yield* FileSystem.FileSystem;
|