@shivaedev/quality 0.12.0 → 0.13.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 +8 -0
- package/README.md +7 -3
- package/dist/imports/fences/evaluate.js +2 -2
- package/dist/imports/fences/evaluate.js.map +1 -1
- package/dist/naming/testName.d.ts +1 -0
- package/dist/naming/testName.d.ts.map +1 -1
- package/dist/naming/testName.js +4 -0
- package/dist/naming/testName.js.map +1 -1
- package/dist/rules/max-lines.js +4 -4
- package/dist/rules/max-lines.js.map +1 -1
- package/package.json +1 -1
- package/src/imports/fences/evaluate.ts +2 -2
- package/src/naming/testName.ts +6 -0
- package/src/rules/max-lines.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.0 - 2026-10-05
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Test code has one definition: a test file, as the `tests/*` rules read the name, or any file under a `test-support/` folder. `test-support/` is the one folder name for test helpers, and every rule that checks shipped code skips it. `tests/follow` and `tests/colocated` still read only test files.
|
|
8
|
+
- `imports/fences` skips files under `test-support/` too, beside test and spec files, so a harness may import what the tests need.
|
|
9
|
+
- `structure/max-lines` gives test code the test limit without configuration. `testFiles` now adds further folders, such as a Playwright suite in `e2e/`, and is empty by default: `*.test.*` and `*.spec.*` count without it, and a helper in a `test/`, `tests/` or `__tests__/` folder is source until it moves to `test-support/` or the option names its folder. A config that listed the old defaults keeps working.
|
|
10
|
+
|
|
3
11
|
## 0.12.0 - 2026-10-05
|
|
4
12
|
|
|
5
13
|
### Changed
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ The config is typed: an unknown rule id, a misspelled option or an option of the
|
|
|
56
56
|
|
|
57
57
|
## Rules
|
|
58
58
|
|
|
59
|
-
`structure/max-lines` keeps each module to one job: a source file may have 150 lines and
|
|
59
|
+
`structure/max-lines` keeps each module to one job: a source file may have 150 lines and [test code](#test-code) 300, counted the way an editor numbers them. Declaration files are exempt. Its options are `source` and `test` (the limits) and `testFiles`, `.gitignore` patterns of further folders whose files count as tests, such as a Playwright suite in `e2e/` (none by default). A file over its limit counts one violation for each line above it: 168 lines under a limit of 150 count 18.
|
|
60
60
|
|
|
61
61
|
### Comments
|
|
62
62
|
|
|
@@ -217,7 +217,7 @@ Each import resolves the way the compiler resolves it, with the options of the n
|
|
|
217
217
|
- A module that resolves into `node_modules` or outside the root is external, and its package is the one it resolves into, whatever alias the import uses. A `@types` package counts as the package it describes: `@types/hast` is `hast`, `@types/scope__name` is `@scope/name`.
|
|
218
218
|
|
|
219
219
|
```ts
|
|
220
|
-
"imports/resolvable": { options: { generated: ["packages/db/test/generated"] } },
|
|
220
|
+
"imports/resolvable": { options: { generated: ["packages/db/src/test-support/generated"] } },
|
|
221
221
|
```
|
|
222
222
|
|
|
223
223
|
`imports/cycles` reports each group of modules that import each other at run time once, at the alphabetically first of them, with one loop through the group. Its count is the number of modules in the group. `import type`, `export type`, type references and imports in declaration files are left out; `import { type X }` stays a runtime import. Dynamic `import()` and `require()` count; `require.resolve()` does not. It takes no registry exceptions. Each finding of `imports/resolvable` has the import as its subject.
|
|
@@ -274,7 +274,7 @@ Targets are `packages(...)` (workspace packages by name, with or without their s
|
|
|
274
274
|
|
|
275
275
|
The config does not compile without `demonstratedBy`, and the rule checks the examples against the policy: each is a chain of imports from a file of the repository, which may end in `external(name)`. The illegal example must cross this fence and no other; the legal example must cross none. Every name a fence uses must exist: a package, a folder that holds checked files, a checked file, a subject of the unit. Two fences may not share a name, and each needs a reason. A policy that breaks any of this stops the run. Fences count type imports too.
|
|
276
276
|
|
|
277
|
-
Fences guard shipped code, and
|
|
277
|
+
Fences guard shipped code, and [test code](#test-code) ships nowhere, so a fence never holds it: a test file or a file under `test-support/` may import across every fence. There is no option to check them.
|
|
278
278
|
|
|
279
279
|
A finding has its fence's name as its subject, so a registry entry with that subject excuses one file from one fence.
|
|
280
280
|
|
|
@@ -511,6 +511,10 @@ A test sits beside the code it covers, and its name says what it covers and wher
|
|
|
511
511
|
|
|
512
512
|
Both rules take a `suites` option, `.gitignore` patterns of folders that hold tests with their own layout, such as tests across several packages or a Playwright suite, whose `.spec.ts` files mean something else. The rules skip those folders.
|
|
513
513
|
|
|
514
|
+
### Test code
|
|
515
|
+
|
|
516
|
+
Test code is a test file, as `tests/follow` reads the name (`*.test.ts` or `*.spec.ts`, with any environment), or any file under a folder named `test-support/`. `test-support/` is the one folder name for the fixtures, harnesses and generated clients that tests share. Test code ships nowhere, so the rules that check shipped code skip it: `imports/fences` never holds it, and `structure/max-lines` gives it the test limit. The test rules still read only test files: a file under `test-support/` is not a test, so `tests/follow` and `tests/colocated` leave it alone.
|
|
517
|
+
|
|
514
518
|
## Vitest projects
|
|
515
519
|
|
|
516
520
|
`@shivaedev/quality/vitest.ts` sets up the tests of a package by file name, so no test file sets its environment with a pragma. It needs `vitest`, and `happy-dom` for DOM tests.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
2
2
|
import { compile } from "./match.js";
|
|
3
3
|
import { labelOf, outgoing, reachedFrom } from "./reach.js";
|
|
4
4
|
import { compileVocabulary } from "./vocabulary.js";
|
|
@@ -44,7 +44,7 @@ export function compileFence(compiler, fence) {
|
|
|
44
44
|
const where = `fence "${fence.name}"`;
|
|
45
45
|
const from = compile(compiler, fence.from, `${where}.from`);
|
|
46
46
|
function importer(path) {
|
|
47
|
-
return
|
|
47
|
+
return !isTestCode(path) && from({ kind: "file", path });
|
|
48
48
|
}
|
|
49
49
|
const prohibition = fence.prohibition;
|
|
50
50
|
if (prohibition.kind === "vocabulary") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/imports/fences/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
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AAK,CAAC,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AACtI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testName.d.ts","sourceRoot":"","sources":["../../src/naming/testName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,uCAAwC,CAAC;AAElE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAQ3D"}
|
|
1
|
+
{"version":3,"file":"testName.d.ts","sourceRoot":"","sources":["../../src/naming/testName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,uCAAwC,CAAC;AAElE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAQ3D;AAID,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD"}
|
package/dist/naming/testName.js
CHANGED
|
@@ -10,4 +10,8 @@ export function testName(path) {
|
|
|
10
10
|
const [stem = "", ...modifiers] = groups.base.split(".");
|
|
11
11
|
return { extension: groups.extension, folder: posix.dirname(path), kind, modifiers, stem };
|
|
12
12
|
}
|
|
13
|
+
const TEST_SUPPORT = "test-support";
|
|
14
|
+
export function isTestCode(path) {
|
|
15
|
+
return testName(path) !== undefined || posix.dirname(path).split("/").includes(TEST_SUPPORT);
|
|
16
|
+
}
|
|
13
17
|
//# sourceMappingURL=testName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testName.js","sourceRoot":"","sources":["../../src/naming/testName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAU,CAAC;AAYlE,MAAM,SAAS,GAAG,gEAAgE,CAAC;AAEnF,MAAM,UAAU,QAAQ,CAAC,IAAY;IACpC,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC;IAC5D,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,CAAC;IAC1B,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,CAAC,EAAE,CAAC;QAC1G,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,CAAC,IAAI,GAAG,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,CAAC,IAAY;IACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC9F,CAAC"}
|
package/dist/rules/max-lines.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import ignore from "ignore";
|
|
3
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
3
4
|
import { defineRule } from "#rule.ts";
|
|
4
|
-
const DEFAULT_TEST_FILES = ["*.test.*", "*.spec.*", "test/", "tests/", "__tests__/"];
|
|
5
5
|
const DECLARATION = /\.d\.[cm]?ts$/u;
|
|
6
6
|
const Limit = Schema.Int.check(Schema.isGreaterThan(0));
|
|
7
7
|
const MaxLinesOptions = Schema.Struct({
|
|
8
8
|
source: Limit.pipe(Schema.withDecodingDefaultKey(Effect.succeed(150))),
|
|
9
9
|
test: Limit.pipe(Schema.withDecodingDefaultKey(Effect.succeed(300))),
|
|
10
|
-
testFiles: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed(
|
|
10
|
+
testFiles: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
11
11
|
});
|
|
12
12
|
const oversized = (file, limit) => file.lines.length <= limit
|
|
13
13
|
? []
|
|
@@ -21,10 +21,10 @@ const oversized = (file, limit) => file.lines.length <= limit
|
|
|
21
21
|
];
|
|
22
22
|
export const maxLines = defineRule({
|
|
23
23
|
check: ({ options, sources }) => {
|
|
24
|
-
const
|
|
24
|
+
const suites = ignore().add([...options.testFiles]);
|
|
25
25
|
return sources
|
|
26
26
|
.filter((file) => !DECLARATION.test(file.path))
|
|
27
|
-
.flatMap((file) => oversized(file,
|
|
27
|
+
.flatMap((file) => oversized(file, isTestCode(file.path) || suites.ignores(file.path) ? options.test : options.source));
|
|
28
28
|
},
|
|
29
29
|
description: "Keep each module to one job. Split a long file along its responsibilities; never golf it under the limit.",
|
|
30
30
|
id: "structure/max-lines",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-lines.js","sourceRoot":"","sources":["../../src/rules/max-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"max-lines.js","sourceRoot":"","sources":["../../src/rules/max-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAiC,MAAM,UAAU,CAAC;AAErE,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAExD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACtE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;CAC9F,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,CAAC,I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name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ImportEdge, ImportGraph } from "#imports/graph.ts";
|
|
2
|
-
import {
|
|
2
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
3
3
|
import type { Finding } from "#rule.ts";
|
|
4
4
|
import { type Compiler, compile, type Matcher } from "./match.ts";
|
|
5
5
|
import type { Fence } from "./model.ts";
|
|
@@ -65,7 +65,7 @@ export function compileFence(compiler: Compiler, fence: Fence): CompiledFence {
|
|
|
65
65
|
const where = `fence "${fence.name}"`;
|
|
66
66
|
const from = compile(compiler, fence.from, `${where}.from`);
|
|
67
67
|
function importer(path: string): boolean {
|
|
68
|
-
return
|
|
68
|
+
return !isTestCode(path) && from({ kind: "file", path });
|
|
69
69
|
}
|
|
70
70
|
const prohibition = fence.prohibition;
|
|
71
71
|
if (prohibition.kind === "vocabulary") {
|
package/src/naming/testName.ts
CHANGED
|
@@ -23,3 +23,9 @@ export function testName(path: string): TestName | undefined {
|
|
|
23
23
|
const [stem = "", ...modifiers] = groups.base.split(".");
|
|
24
24
|
return { extension: groups.extension, folder: posix.dirname(path), kind, modifiers, stem };
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
const TEST_SUPPORT = "test-support";
|
|
28
|
+
|
|
29
|
+
export function isTestCode(path: string): boolean {
|
|
30
|
+
return testName(path) !== undefined || posix.dirname(path).split("/").includes(TEST_SUPPORT);
|
|
31
|
+
}
|
package/src/rules/max-lines.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import ignore from "ignore";
|
|
3
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
3
4
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
4
5
|
|
|
5
|
-
const DEFAULT_TEST_FILES: readonly string[] = ["*.test.*", "*.spec.*", "test/", "tests/", "__tests__/"];
|
|
6
6
|
const DECLARATION = /\.d\.[cm]?ts$/u;
|
|
7
7
|
|
|
8
8
|
const Limit = Schema.Int.check(Schema.isGreaterThan(0));
|
|
@@ -10,7 +10,7 @@ const Limit = Schema.Int.check(Schema.isGreaterThan(0));
|
|
|
10
10
|
const MaxLinesOptions = Schema.Struct({
|
|
11
11
|
source: Limit.pipe(Schema.withDecodingDefaultKey(Effect.succeed(150))),
|
|
12
12
|
test: Limit.pipe(Schema.withDecodingDefaultKey(Effect.succeed(300))),
|
|
13
|
-
testFiles: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed(
|
|
13
|
+
testFiles: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const oversized = (file: SourceFile, limit: number): readonly Finding[] =>
|
|
@@ -27,10 +27,10 @@ const oversized = (file: SourceFile, limit: number): readonly Finding[] =>
|
|
|
27
27
|
|
|
28
28
|
export const maxLines = defineRule({
|
|
29
29
|
check: ({ options, sources }) => {
|
|
30
|
-
const
|
|
30
|
+
const suites = ignore().add([...options.testFiles]);
|
|
31
31
|
return sources
|
|
32
32
|
.filter((file) => !DECLARATION.test(file.path))
|
|
33
|
-
.flatMap((file) => oversized(file,
|
|
33
|
+
.flatMap((file) => oversized(file, isTestCode(file.path) || suites.ignores(file.path) ? options.test : options.source));
|
|
34
34
|
},
|
|
35
35
|
description: "Keep each module to one job. Split a long file along its responsibilities; never golf it under the limit.",
|
|
36
36
|
id: "structure/max-lines",
|