@shivaedev/quality 0.41.0 → 0.41.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.41.1 - 2026-10-26
4
+
5
+ ### Changed
6
+
7
+ - Treat `test`, `tests` and `spec` as test folders only when their directly contained checked files are all tests or test support, allowing colocated specs in product folders that also contain source. `__tests__` remains a test folder everywhere.
8
+
3
9
  ## 0.41.0 - 2026-10-26
4
10
 
5
11
  ### Added
package/README.md CHANGED
@@ -219,7 +219,7 @@ Git calls `quality baseline merge <ancestor> <current> <other>`. Entries are key
219
219
  - **Suppressions:** the `suppressions/*` rules reject inline lint and compiler directives, casts through `unknown`, `any` or `never`, Biome settings that weaken a check, recommended Biome rules the preset leaves below `error`, and `ignoreDeprecations`. None of them takes exceptions. A type test (`*.typecheck.test.ts`) may use `@ts-expect-error`; a test that must pass a rejected value at run time calls the API through `Reflect.apply`.
220
220
  - **Imports:** cycles, unresolvable imports, workspace imports missing from the manifest, relative imports that leave their folder, production imports of test code, runtime folders and fences, as described above.
221
221
  - **Names and files:** the Biome preset's naming rules and plugins, and the `files/*` rules, which name a file after its main export with its folders as the prefix. No naming rule renames anything; the author picks the name. A name an outside system owns, such as a query parameter or an environment variable, is written as a quoted key, which the naming rules skip. A `Schema.Struct` field stays camelCase even when quoted and maps to the outside name with `Schema.encodeKeys`. Biome's naming messages print only a pattern: spell acronyms as words (`HttpClient`, `userId`, `parseUrl`) rather than turning off `strictCase` as its hint suggests, give a type no `I` prefix, and name a type parameter `T`, `T` plus a PascalCase name (`TItem`), or Effect's `A`, `E` and `R`. No rule checks these, so review does: a boolean reads as a question (`isOpen`, `canRetry`) unless the DOM or React names it (`open`, `disabled`); a schema shares its name with its type (`type Item = typeof Item.Type`); an unused parameter is removed rather than renamed with the `_` prefix TypeScript accepts. The naming rules take repository facts: `toolOwned` lists `.gitignore` patterns whose names a tool fixes, and a configured list extends the rule's defaults, so list only repository-specific additions; `content` lists snake_case content folders and files; `tests/follow` and `tests/colocated` take `suites` for test folders with their own layout, such as a Playwright suite.
222
- - **Tests:** `tests/follow` and `tests/colocated` keep a test beside the code it covers, named `<file>[.<modifier>].test.ts` or `<behaviour>[.<modifier>].spec.ts` with at most one modifier of `dom`, `slow`, `typecheck` and `unit`; a unit test runs without the DOM, so `.unit.dom` is rejected. The story rules above keep setup in the kit.
222
+ - **Tests:** `tests/follow` and `tests/colocated` keep a test beside the code it covers, named `<file>[.<modifier>].test.ts` or `<behaviour>[.<modifier>].spec.ts` with at most one modifier of `dom`, `slow`, `typecheck` and `unit`; a unit test runs without the DOM, so `.unit.dom` is rejected. `tests/colocated` always treats `__tests__/` as a test folder. It treats `test/`, `tests/` and `spec/` as test folders only when their directly contained checked files are all tests or test support; a product folder with source beside its specs is an ordinary source folder. Declared `suites` keep their own layout. Shared test support belongs in `test-support/`, the sanctioned test-only folder. A test covering a whole module may sit at its root or directly beside its folder. The story rules above keep setup in the kit.
223
223
  - **Manifests:** `manifests/sorted` keeps every `package.json` in sort-package-json order, and `manifests/source-first` puts the `source` condition first in `exports` and `imports`. `manifests/exports-shape` checks the package root and workspace members with exports. They use one file-preserving TypeScript wildcard: for example, `./*.ts` maps to `./src/*.ts`, `./dist/*.d.ts` and `./dist/*.js` under `source`, `types` and `default`. A subtree pattern such as `./server/*.ts` keeps that same subtree in its targets. An optional root entry, exact-path non-code assets such as JSON presets, `./package.json` and `null` blocks are allowed. Import each module at its path under `src/`; named aliases, flattened paths, per-file module lists and additional non-null wildcards fail.
224
224
  - **Biome:** the `biome` rule reports Biome's error findings as `biome/<category>`. A Biome run that fails without an error finding, such as one whose config leaves no file to check, fails lint and fix with Biome's message. The preset leaves out the `.worktrees` folder at the root, so a checkout does not lint its linked worktrees, while a worktree inside it lints all of its own files. The preset's plugins ban ambient time, randomness, `console` and `process.env` in favour of Effect's services.
225
225
 
@@ -1 +1 @@
1
- {"version":3,"file":"colocated.d.ts","sourceRoot":"","sources":["../../../src/rules/test-names/colocated.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,cAAc;;EAQzB,CAAC"}
1
+ {"version":3,"file":"colocated.d.ts","sourceRoot":"","sources":["../../../src/rules/test-names/colocated.ts"],"names":[],"mappings":"AA+BA,eAAO,MAAM,cAAc;;EAUzB,CAAC"}
@@ -1,14 +1,17 @@
1
+ import { posix } from "node:path";
1
2
  import { Effect, Schema } from "effect";
2
3
  import ignore from "ignore";
3
- import { testName } from "#naming/testName.ts";
4
+ import { isTestCode, testName } from "#naming/testName.ts";
4
5
  import { defineRule } from "#rule.ts";
5
6
  const MIRROR_FOLDERS = new Set(["__tests__", "spec", "test", "tests"]);
6
7
  const TestsColocatedOptions = Schema.Struct({
7
8
  suites: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
8
9
  });
9
- function findingOf(path) {
10
+ function findingOf(path, sourceFolders) {
10
11
  const name = testName(path);
11
- const mirror = name?.folder.split("/").find((folder) => MIRROR_FOLDERS.has(folder));
12
+ const mirror = name?.folder
13
+ .split("/")
14
+ .find((folder, index, folders) => MIRROR_FOLDERS.has(folder) && (folder === "__tests__" || !sourceFolders.has(folders.slice(0, index + 1).join("/"))));
12
15
  if (name === undefined || mirror === undefined) {
13
16
  return [];
14
17
  }
@@ -16,16 +19,17 @@ function findingOf(path) {
16
19
  return [
17
20
  {
18
21
  file: path,
19
- message: `Sits in the test folder "${mirror}/". A test sits beside the file it covers, as ${name.stem}${modifiers}.test${name.extension} beside ${name.stem}.ts, or as a <behaviour>${modifiers}.spec${name.extension} in the folder it covers. A folder of tests that cover several packages is a suite in the "suites" option.`,
22
+ message: `Sits in the test folder "${mirror}/". A test, tests or spec folder is test-only when its directly contained checked files are all tests or test support; __tests__ is always a test folder. A test sits beside the file it covers, as ${name.stem}${modifiers}.test${name.extension} beside ${name.stem}.ts, or as a <behaviour>${modifiers}.spec${name.extension} at the module root or directly beside the module folder. Shared test support belongs in test-support/. A folder of tests that cover several packages is a suite in the "suites" option.`,
20
23
  },
21
24
  ];
22
25
  }
23
26
  export const testsColocated = defineRule({
24
27
  check: ({ files, options }) => {
25
28
  const suites = ignore().add([...options.suites]);
26
- return files.filter((path) => !suites.ignores(path)).flatMap(findingOf);
29
+ const sourceFolders = new Set(files.filter((path) => !isTestCode(path)).map((path) => posix.dirname(path)));
30
+ return files.filter((path) => !suites.ignores(path)).flatMap((path) => findingOf(path, sourceFolders));
27
31
  },
28
- description: "A test sits beside the code it covers, not in a test, tests, __tests__ or spec folder, unless that folder is a declared suite.",
32
+ description: "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/.",
29
33
  id: "tests/colocated",
30
34
  options: Schema.toStandardSchemaV1(TestsColocatedOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
31
35
  });
@@ -1 +1 @@
1
- {"version":3,"file":"colocated.js","sourceRoot":"","sources":["../../../src/rules/test-names/colocated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAgB,MAAM,UAAU,CAAC;AAEpD,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5F,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;CAC3F,C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AE,iBAAiB;IACrB,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC;CACzH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/quality",
3
- "version": "0.41.0",
3
+ "version": "0.41.1",
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,6 +1,7 @@
1
+ import { posix } from "node:path";
1
2
  import { Effect, Schema } from "effect";
2
3
  import ignore from "ignore";
3
- import { testName } from "#naming/testName.ts";
4
+ import { isTestCode, testName } from "#naming/testName.ts";
4
5
  import { defineRule, type Finding } from "#rule.ts";
5
6
 
6
7
  const MIRROR_FOLDERS: ReadonlySet<string> = new Set(["__tests__", "spec", "test", "tests"]);
@@ -9,9 +10,13 @@ const TestsColocatedOptions = Schema.Struct({
9
10
  suites: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
10
11
  });
11
12
 
12
- function findingOf(path: string): readonly Finding[] {
13
+ function findingOf(path: string, sourceFolders: ReadonlySet<string>): readonly Finding[] {
13
14
  const name = testName(path);
14
- const mirror = name?.folder.split("/").find((folder) => MIRROR_FOLDERS.has(folder));
15
+ const mirror = name?.folder
16
+ .split("/")
17
+ .find(
18
+ (folder, index, folders) => MIRROR_FOLDERS.has(folder) && (folder === "__tests__" || !sourceFolders.has(folders.slice(0, index + 1).join("/"))),
19
+ );
15
20
  if (name === undefined || mirror === undefined) {
16
21
  return [];
17
22
  }
@@ -19,7 +24,7 @@ function findingOf(path: string): readonly Finding[] {
19
24
  return [
20
25
  {
21
26
  file: path,
22
- message: `Sits in the test folder "${mirror}/". A test sits beside the file it covers, as ${name.stem}${modifiers}.test${name.extension} beside ${name.stem}.ts, or as a <behaviour>${modifiers}.spec${name.extension} in the folder it covers. A folder of tests that cover several packages is a suite in the "suites" option.`,
27
+ message: `Sits in the test folder "${mirror}/". A test, tests or spec folder is test-only when its directly contained checked files are all tests or test support; __tests__ is always a test folder. A test sits beside the file it covers, as ${name.stem}${modifiers}.test${name.extension} beside ${name.stem}.ts, or as a <behaviour>${modifiers}.spec${name.extension} at the module root or directly beside the module folder. Shared test support belongs in test-support/. A folder of tests that cover several packages is a suite in the "suites" option.`,
23
28
  },
24
29
  ];
25
30
  }
@@ -27,9 +32,11 @@ function findingOf(path: string): readonly Finding[] {
27
32
  export const testsColocated = defineRule({
28
33
  check: ({ files, options }) => {
29
34
  const suites = ignore().add([...options.suites]);
30
- return files.filter((path) => !suites.ignores(path)).flatMap(findingOf);
35
+ const sourceFolders = new Set(files.filter((path) => !isTestCode(path)).map((path) => posix.dirname(path)));
36
+ return files.filter((path) => !suites.ignores(path)).flatMap((path) => findingOf(path, sourceFolders));
31
37
  },
32
- description: "A test sits beside the code it covers, not in a test, tests, __tests__ or spec folder, unless that folder is a declared suite.",
38
+ description:
39
+ "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/.",
33
40
  id: "tests/colocated",
34
41
  options: Schema.toStandardSchemaV1(TestsColocatedOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
35
42
  });