@shivaedev/quality 0.52.0 → 0.53.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/CHANGELOG.md +31 -0
- package/README.md +19 -9
- package/biome/declarations.json +0 -5
- package/biome/preset.json +1 -1
- package/dist/baseline/cleanupMergeFiles.d.ts +4 -0
- package/dist/baseline/cleanupMergeFiles.d.ts.map +1 -0
- package/dist/baseline/cleanupMergeFiles.js +23 -0
- package/dist/baseline/cleanupMergeFiles.js.map +1 -0
- 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/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +2 -0
- package/dist/cli/program.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/departures.d.ts.map +1 -1
- package/dist/imports/departures.js +13 -0
- package/dist/imports/departures.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/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 +10 -8
- 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/imports/aliased.js +1 -1
- package/dist/rules/imports/aliased.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/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/package.json +3 -2
- package/src/baseline/cleanupMergeFiles.ts +27 -0
- package/src/cli/lint.ts +33 -27
- package/src/cli/program.ts +2 -0
- package/src/config/globs.ts +31 -0
- package/src/engine/runRules.ts +7 -2
- package/src/engine/session.ts +10 -5
- package/src/imports/departures.ts +16 -0
- package/src/rule.ts +12 -2
- package/src/rules/files/folderNames.ts +7 -5
- package/src/rules/files/namedAfterExport.ts +10 -8
- package/src/rules/files/otherNames.ts +7 -5
- package/src/rules/imports/aliased.ts +1 -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/test-names/colocated.ts +5 -3
- package/src/rules/test-names/follow.ts +5 -3
|
@@ -1,33 +1,14 @@
|
|
|
1
|
-
import { posix } from "node:path";
|
|
2
1
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
2
|
import type { WorkspacePackage } from "#imports/workspace.ts";
|
|
4
3
|
import type { RuleInputs } from "#rule.ts";
|
|
5
4
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
function object(value: unknown): value is Record<string, unknown> {
|
|
9
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
-
}
|
|
5
|
+
const PREREQUISITES = new Set(["@shivaedev/test-story", "@shivaedev/test", "@shivaedev/types"]);
|
|
11
6
|
|
|
12
7
|
export async function storyPrerequisites(inputs: RuleInputs, packages: readonly WorkspacePackage[]): Promise<ReadonlySet<string>> {
|
|
13
|
-
const root =
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const directories = new Set<string>();
|
|
18
|
-
while (pending.length > 0) {
|
|
19
|
-
const current = byName.get(pending.pop() ?? "");
|
|
20
|
-
if (current === undefined || directories.has(current.directory)) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
directories.add(current.directory);
|
|
24
|
-
const value = (await readPackageManifest(inputs.readText, posix.join(current.directory, "package.json"))) ?? {};
|
|
25
|
-
for (const key of DEPENDENCIES) {
|
|
26
|
-
const dependencies = value[key];
|
|
27
|
-
if (object(dependencies)) {
|
|
28
|
-
pending.push(...Object.keys(dependencies).filter((name) => byName.has(name)));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
8
|
+
const root = await readPackageManifest(inputs.readText, "package.json");
|
|
9
|
+
const directories = packages.filter((member) => PREREQUISITES.has(member.name)).map((member) => member.directory);
|
|
10
|
+
if (typeof root?.name === "string" && PREREQUISITES.has(root.name)) {
|
|
11
|
+
directories.push("");
|
|
31
12
|
}
|
|
32
|
-
return directories;
|
|
13
|
+
return new Set(directories);
|
|
33
14
|
}
|
|
@@ -3,7 +3,13 @@ import ts from "typescript";
|
|
|
3
3
|
import type { ImportGraph } from "#imports/graph.ts";
|
|
4
4
|
import type { RuleInputs } from "#rule.ts";
|
|
5
5
|
|
|
6
|
+
const programs = new WeakMap<RuleInputs["sources"], ts.Program>();
|
|
7
|
+
|
|
6
8
|
export function storyProgram(inputs: RuleInputs, graph: ImportGraph): ts.Program {
|
|
9
|
+
const known = programs.get(inputs.sources);
|
|
10
|
+
if (known !== undefined) {
|
|
11
|
+
return known;
|
|
12
|
+
}
|
|
7
13
|
const sources = new Map(inputs.sources.map((file) => [join(inputs.root, file.path), file.text]));
|
|
8
14
|
const targets = new Map(
|
|
9
15
|
graph.edges.flatMap((edge) =>
|
|
@@ -25,5 +31,7 @@ export function storyProgram(inputs: RuleInputs, graph: ImportGraph): ts.Program
|
|
|
25
31
|
return path === undefined ? undefined : { extension: ts.Extension.Ts, resolvedFileName: path };
|
|
26
32
|
}),
|
|
27
33
|
};
|
|
28
|
-
|
|
34
|
+
const program = ts.createProgram([...sources.keys()], options, host);
|
|
35
|
+
programs.set(inputs.sources, program);
|
|
36
|
+
return program;
|
|
29
37
|
}
|
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
4
|
+
import { packageOf } from "#imports/workspace.ts";
|
|
3
5
|
import { isTestSupport, testName } from "#naming/testName.ts";
|
|
4
6
|
import type { RuleInputs } from "#rule.ts";
|
|
7
|
+
import { storyOrigins } from "./origins.ts";
|
|
5
8
|
import { storyPrerequisites } from "./prerequisites.ts";
|
|
6
9
|
|
|
7
10
|
export const storySources = Effect.fn("Stories.storySources")(function* (inputs: RuleInputs) {
|
|
8
|
-
const
|
|
11
|
+
const graph = yield* Effect.promise(() => importGraph(inputs));
|
|
12
|
+
const packages = graph.packages;
|
|
13
|
+
const origins = storyOrigins(inputs, graph);
|
|
9
14
|
const exempt = yield* Effect.promise(() => storyPrerequisites(inputs, packages));
|
|
15
|
+
function hasStory(node: ts.Node): boolean {
|
|
16
|
+
return (ts.isCallExpression(node) && origins.origin(node.expression) === "story") || ts.forEachChild(node, hasStory) === true;
|
|
17
|
+
}
|
|
10
18
|
return inputs.sources.filter((file) => {
|
|
11
19
|
const modifiers = testName(file.path)?.modifiers;
|
|
12
|
-
|
|
13
|
-
modifiers
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
20
|
+
if (
|
|
21
|
+
modifiers === undefined
|
|
22
|
+
|| isTestSupport(file.path)
|
|
23
|
+
|| modifiers.includes("typecheck")
|
|
24
|
+
|| modifiers.includes("unit")
|
|
25
|
+
|| exempt.has(packageOf(packages, file.path)?.directory ?? "")
|
|
26
|
+
) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const source = origins.source(file.path);
|
|
30
|
+
return source !== undefined && hasStory(source);
|
|
19
31
|
});
|
|
20
32
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import { defineRule } from "#rule.ts";
|
|
2
|
-
import {
|
|
3
|
+
import { storySources } from "./sources.ts";
|
|
4
|
+
import { syntaxFindings, topLevelHelpers } from "./syntax.ts";
|
|
3
5
|
|
|
4
6
|
const MESSAGE = "Declares a top-level helper in a spec. Move the action into the story kit's verbs or the setup into its traits in test-support/.";
|
|
5
7
|
|
|
6
8
|
export const specHelpers = defineRule({
|
|
7
|
-
check: (
|
|
9
|
+
check: (inputs) => Effect.map(storySources(inputs), (stories) => stories.flatMap((file) => syntaxFindings(file, topLevelHelpers, MESSAGE))),
|
|
8
10
|
description: "Specs state expectations; story-kit traits and verbs in test-support own helpers.",
|
|
9
11
|
id: "tests/spec-helpers",
|
|
10
12
|
});
|
|
@@ -95,6 +95,6 @@ export const storySpecs = defineRule({
|
|
|
95
95
|
});
|
|
96
96
|
},
|
|
97
97
|
description:
|
|
98
|
-
"Every package tests its real engine through its own test-story kit, and a plain test lives only in a .unit file that reaches no engine and mocks nothing. Typecheck tests and test-story
|
|
98
|
+
"Every package tests its real engine through its own test-story kit, and a plain test lives only in a .unit file that reaches no engine and mocks nothing. Typecheck tests and the test-story, test and types packages need no kit.",
|
|
99
99
|
id: "tests/story-specs",
|
|
100
100
|
});
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
import { isTestSupport, testName } from "#naming/testName.ts";
|
|
3
2
|
import type { Finding, SourceFile } from "#rule.ts";
|
|
4
3
|
import { parse } from "#rules/parse.ts";
|
|
5
4
|
|
|
6
|
-
export function isSpec(path: string): boolean {
|
|
7
|
-
return testName(path)?.kind === "spec" && !isTestSupport(path);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
export function unwrapped(node: ts.Expression): ts.Expression {
|
|
11
6
|
return ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node)
|
|
12
7
|
? unwrapped(node.expression)
|
|
@@ -1,13 +1,14 @@
|
|
|
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 { isTestCode, testName } from "#naming/testName.ts";
|
|
5
6
|
import { defineRule, type Finding } from "#rule.ts";
|
|
6
7
|
|
|
7
8
|
const MIRROR_FOLDERS: ReadonlySet<string> = new Set(["__tests__", "spec", "test", "tests"]);
|
|
8
9
|
|
|
9
10
|
const TestsColocatedOptions = Schema.Struct({
|
|
10
|
-
suites:
|
|
11
|
+
suites: GlobDeclarations,
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
function findingOf(path: string, sourceFolders: ReadonlySet<string>): readonly Finding[] {
|
|
@@ -31,7 +32,7 @@ function findingOf(path: string, sourceFolders: ReadonlySet<string>): readonly F
|
|
|
31
32
|
|
|
32
33
|
export const testsColocated = defineRule({
|
|
33
34
|
check: ({ files, options }) => {
|
|
34
|
-
const suites = ignore().add([...options.suites]);
|
|
35
|
+
const suites = ignore().add([...globPatterns(options.suites)]);
|
|
35
36
|
const sourceFolders = new Set(files.filter((path) => !isTestCode(path)).map((path) => posix.dirname(path)));
|
|
36
37
|
return files.filter((path) => !suites.ignores(path)).flatMap((path) => findingOf(path, sourceFolders));
|
|
37
38
|
},
|
|
@@ -39,4 +40,5 @@ export const testsColocated = defineRule({
|
|
|
39
40
|
"A test sits beside the code it covers, at its module root or directly beside its module folder. Outside declared suites, __tests__ is always a test folder; test, tests and spec are test folders only when their directly contained checked files are all tests or test support. Shared test support belongs in test-support/.",
|
|
40
41
|
id: "tests/colocated",
|
|
41
42
|
options: Schema.toStandardSchemaV1(TestsColocatedOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
43
|
+
validate: validateGlobs,
|
|
42
44
|
});
|
|
@@ -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 { ENVIRONMENTS, type TestName, testName } from "#naming/testName.ts";
|
|
5
6
|
import { CAMEL } from "#naming/words.ts";
|
|
6
7
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
@@ -16,7 +17,7 @@ const GRAMMAR =
|
|
|
16
17
|
"A test file is <file>[.<modifier>].test.ts beside its file or <behaviour>[.<modifier>].spec.ts in the folder it covers, with at most one modifier of dom, slow, typecheck and unit.";
|
|
17
18
|
|
|
18
19
|
const TestsFollowOptions = Schema.Struct({
|
|
19
|
-
suites:
|
|
20
|
+
suites: GlobDeclarations,
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
function siblingsIn(files: readonly string[]): ReadonlySet<string> {
|
|
@@ -78,7 +79,7 @@ function findingsOf(source: SourceFile, siblings: ReadonlySet<string>): readonly
|
|
|
78
79
|
|
|
79
80
|
export const testsFollow = defineRule({
|
|
80
81
|
check: ({ files, options, sources }) => {
|
|
81
|
-
const suites = ignore().add([...options.suites]);
|
|
82
|
+
const suites = ignore().add([...globPatterns(options.suites)]);
|
|
82
83
|
const siblings = siblingsIn(files);
|
|
83
84
|
return sources.filter((source) => !suites.ignores(source.path)).flatMap((source) => findingsOf(source, siblings));
|
|
84
85
|
},
|
|
@@ -86,4 +87,5 @@ export const testsFollow = defineRule({
|
|
|
86
87
|
"A .test file follows the file beside it, a .spec names a behaviour of its folder, the only suffix is one modifier of dom, slow, typecheck and unit, and a test that uses the DOM is a .dom test.",
|
|
87
88
|
id: "tests/follow",
|
|
88
89
|
options: Schema.toStandardSchemaV1(TestsFollowOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
90
|
+
validate: validateGlobs,
|
|
89
91
|
});
|