@zgeoff/chex 0.3.12 → 0.3.14
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/README.md +2 -1
- package/lefthook.yml +5 -5
- package/package.json +43 -1
- package/src/{read-branch-base.ts → branch/read-branch-base.ts} +1 -1
- package/src/{read-branch-files.ts → branch/read-branch-files.ts} +2 -2
- package/src/ci-plan/parse-docs-checks.ts +3 -3
- package/src/ci-plan/write-check-plan.ts +2 -2
- package/src/cli.ts +10 -10
- package/src/{read-range-commits.ts → commits/read-range-commits.ts} +1 -1
- package/src/{run-commits-check.ts → commits/run-commits-check.ts} +4 -4
- package/src/dependency-gates/parse-audit-ignore-ids.ts +1 -1
- package/src/dependency-gates/read-dependency-gate-findings.ts +1 -1
- package/src/dependency-gates/run-dependency-gates-check.ts +1 -1
- package/src/docs/check-prose.sh +74 -10
- package/src/docs/check-readmes.sh +12 -7
- package/src/docs/check-skill.sh +2 -1
- package/src/{build-init-plan.ts → init/build-init-plan.ts} +3 -3
- package/src/{pick-merge-blobs-command.ts → local-paths/pick-merge-blobs-command.ts} +1 -1
- package/src/{run-local-paths-check.ts → local-paths/run-local-paths-check.ts} +7 -7
- package/src/{read-pushed-ranges.ts → push/read-pushed-ranges.ts} +3 -3
- package/src/test-layout/collect-folder-faults.ts +12 -0
- package/src/test-layout/collect-import-faults.ts +143 -56
- package/src/test-layout/collect-lane-suffixes.ts +1 -1
- package/src/test-layout/collect-test-preloads.ts +55 -0
- package/src/test-layout/read-workspace-packages.ts +24 -0
- package/src/{run-test-layout-check.ts → test-layout/run-test-layout-check.ts} +37 -21
- package/src/test-layout/types.ts +18 -0
- package/src/{parse-rig-lane-limits.ts → test-timeouts/parse-rig-lane-limits.ts} +1 -1
- package/src/{run-test-timeouts-check.ts → test-timeouts/run-test-timeouts-check.ts} +5 -5
- package/src/{run-uncommitted-check.ts → uncommitted/run-uncommitted-check.ts} +3 -3
- package/src/{collect-command-names.ts → workflows/collect-command-names.ts} +2 -2
- package/src/{read-checks-profile.ts → workflows/read-checks-profile.ts} +1 -1
- package/src/{run-workflows-check.ts → workflows/run-workflows-check.ts} +3 -3
- /package/src/{check-names.ts → cli/check-names.ts} +0 -0
- /package/src/{make-check-runner.ts → cli/make-check-runner.ts} +0 -0
- /package/src/{parse-chex-args.ts → cli/parse-chex-args.ts} +0 -0
- /package/src/{run-chex.ts → cli/run-chex.ts} +0 -0
- /package/src/{format-commit-lines.ts → commits/format-commit-lines.ts} +0 -0
- /package/src/{build-init-package.ts → init/build-init-package.ts} +0 -0
- /package/src/{run-init.ts → init/run-init.ts} +0 -0
- /package/src/{build-lefthook-extends.ts → lefthook/build-lefthook-extends.ts} +0 -0
- /package/src/{build-lefthook-guard.ts → lefthook/build-lefthook-guard.ts} +0 -0
- /package/src/{parse-lefthook-config.ts → lefthook/parse-lefthook-config.ts} +0 -0
- /package/src/{parse-added-lines.ts → local-paths/parse-added-lines.ts} +0 -0
- /package/src/{write-step-outputs.ts → output/write-step-outputs.ts} +0 -0
- /package/src/{write-text-file.ts → output/write-text-file.ts} +0 -0
- /package/src/{run-program.ts → program/run-program.ts} +0 -0
- /package/src/{parse-pushed-refs.ts → push/parse-pushed-refs.ts} +0 -0
- /package/src/{read-pushed-refs-input.ts → push/read-pushed-refs-input.ts} +0 -0
- /package/src/{parse-shell-words.ts → shell/parse-shell-words.ts} +0 -0
- /package/src/{shell-escape-parsers.ts → shell/shell-escape-parsers.ts} +0 -0
- /package/src/{parse-lane-limits.ts → test-timeouts/parse-lane-limits.ts} +0 -0
- /package/src/{make-file-probe.ts → uncommitted/make-file-probe.ts} +0 -0
- /package/src/{collect-concurrency-findings.ts → workflows/collect-concurrency-findings.ts} +0 -0
- /package/src/{collect-expression-references.ts → workflows/collect-expression-references.ts} +0 -0
- /package/src/{find-install-cache-path.ts → workflows/find-install-cache-path.ts} +0 -0
- /package/src/{find-member.ts → workflows/find-member.ts} +0 -0
- /package/src/{get-top-level-line.ts → workflows/get-top-level-line.ts} +0 -0
- /package/src/{pull-request-triggers.ts → workflows/pull-request-triggers.ts} +0 -0
- /package/src/{workflow-context.ts → workflows/workflow-context.ts} +0 -0
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ The repo checks read the branch, the pushed commits and the repo's config:
|
|
|
57
57
|
| `commits` | a pushed commit whose message fails `@zgeoff/commitlint-config` | `--pushed-refs` |
|
|
58
58
|
| `local-paths` | a line a pushed commit adds that holds the home folder or the host name | `--pushed-refs` |
|
|
59
59
|
| `test-timeouts` | a `bun test` timeout above its lane's limit, in a script or a `bunfig.toml` | none |
|
|
60
|
-
| `test-layout` | a test folder, file name or import outside [the test layout](../../docs/guides/test-layout.md)
|
|
60
|
+
| `test-layout` | a test folder, file name or import outside [the test layout](../../docs/guides/test-layout.md); test code includes a relative `[test] preload` file, a `.nix`-only `tests/` folder and a private workspace that only test code imports | none |
|
|
61
61
|
| `workflows` | nothing: it prints each fault of the shared workflow lint, and fails when there is one | the paths |
|
|
62
62
|
| `dependency-gates` | a stale age-gate exclude, an override or an audit ignore that nothing needs, a first-party package with no age-gate exclude, or a pinned release younger than the age gate ([details](../../docs/architecture/dependency-updates.md#the-dependency-gates-check)) | none |
|
|
63
63
|
| `uncommitted` | a file the branch changes that holds a change the push does not send | none |
|
|
@@ -71,6 +71,7 @@ commits since its base.
|
|
|
71
71
|
Some docs checks skip files whether or not you name paths, and a path you name never brings a
|
|
72
72
|
skipped file back:
|
|
73
73
|
|
|
74
|
+
- `prose` needs `perl` and a `git` with PCRE, and fails with exit 2 when it lacks one.
|
|
74
75
|
- `prose` skips the `docs-writing`, `project-docs-writing`, `skill-writing` and `deslop` skills
|
|
75
76
|
under `.agents/skills/`, `.claude/skills/`, `skills/` and `sync/skills/`, which hold the banned
|
|
76
77
|
patterns as examples.
|
package/lefthook.yml
CHANGED
|
@@ -50,7 +50,7 @@ pre-push:
|
|
|
50
50
|
- name: chex-lint
|
|
51
51
|
files:
|
|
52
52
|
unset $(git rev-parse --local-env-vars); bun
|
|
53
|
-
node_modules/@zgeoff/chex/src/read-branch-files.ts
|
|
53
|
+
node_modules/@zgeoff/chex/src/branch/read-branch-files.ts
|
|
54
54
|
glob: '*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}'
|
|
55
55
|
run:
|
|
56
56
|
'{clear-git-env} bun x --no-install diet -- bun x --no-install oxlint
|
|
@@ -62,7 +62,7 @@ pre-push:
|
|
|
62
62
|
- name: chex-shell
|
|
63
63
|
files:
|
|
64
64
|
unset $(git rev-parse --local-env-vars); bun
|
|
65
|
-
node_modules/@zgeoff/chex/src/read-branch-files.ts
|
|
65
|
+
node_modules/@zgeoff/chex/src/branch/read-branch-files.ts
|
|
66
66
|
glob: '*.sh'
|
|
67
67
|
run: |
|
|
68
68
|
{clear-git-env}
|
|
@@ -82,7 +82,7 @@ pre-push:
|
|
|
82
82
|
- name: chex-docs
|
|
83
83
|
files:
|
|
84
84
|
unset $(git rev-parse --local-env-vars); bun
|
|
85
|
-
node_modules/@zgeoff/chex/src/read-branch-files.ts
|
|
85
|
+
node_modules/@zgeoff/chex/src/branch/read-branch-files.ts
|
|
86
86
|
glob: '*.md'
|
|
87
87
|
run: '{clear-git-env} bun x --no-install diet -- bun run --silent check:docs'
|
|
88
88
|
# GitHub runs no workflow from a subfolder of .github/workflows, and
|
|
@@ -94,7 +94,7 @@ pre-push:
|
|
|
94
94
|
- name: chex-workflows
|
|
95
95
|
files:
|
|
96
96
|
unset $(git rev-parse --local-env-vars); bun
|
|
97
|
-
node_modules/@zgeoff/chex/src/read-branch-files.ts
|
|
97
|
+
node_modules/@zgeoff/chex/src/branch/read-branch-files.ts
|
|
98
98
|
glob:
|
|
99
99
|
- '.github/workflows/*.{yml,yaml}'
|
|
100
100
|
- 'sync/src/workflow-callers/*.{yml,yaml}'
|
|
@@ -142,6 +142,6 @@ pre-push:
|
|
|
142
142
|
- name: chex-test
|
|
143
143
|
files:
|
|
144
144
|
unset $(git rev-parse --local-env-vars); bun
|
|
145
|
-
node_modules/@zgeoff/chex/src/read-branch-files.ts
|
|
145
|
+
node_modules/@zgeoff/chex/src/branch/read-branch-files.ts
|
|
146
146
|
glob: '*.{ts,tsx,toml}'
|
|
147
147
|
run: '{clear-git-env} bun x --no-install diet -- bun x --no-install rig related {files}'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/chex",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Run each shared docs and repo check as one subcommand, with the lefthook pre-push baseline that calls them",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"checks",
|
|
@@ -26,6 +26,48 @@
|
|
|
26
26
|
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
28
|
"./test-utils/*": "./src/test-utils/*.ts",
|
|
29
|
+
"./src/build-init-package.ts": "./src/init/build-init-package.ts",
|
|
30
|
+
"./src/build-init-plan.ts": "./src/init/build-init-plan.ts",
|
|
31
|
+
"./src/build-lefthook-extends.ts": "./src/lefthook/build-lefthook-extends.ts",
|
|
32
|
+
"./src/build-lefthook-guard.ts": "./src/lefthook/build-lefthook-guard.ts",
|
|
33
|
+
"./src/check-names.ts": "./src/cli/check-names.ts",
|
|
34
|
+
"./src/collect-command-names.ts": "./src/workflows/collect-command-names.ts",
|
|
35
|
+
"./src/collect-concurrency-findings.ts": "./src/workflows/collect-concurrency-findings.ts",
|
|
36
|
+
"./src/collect-expression-references.ts": "./src/workflows/collect-expression-references.ts",
|
|
37
|
+
"./src/find-install-cache-path.ts": "./src/workflows/find-install-cache-path.ts",
|
|
38
|
+
"./src/find-member.ts": "./src/workflows/find-member.ts",
|
|
39
|
+
"./src/format-commit-lines.ts": "./src/commits/format-commit-lines.ts",
|
|
40
|
+
"./src/get-top-level-line.ts": "./src/workflows/get-top-level-line.ts",
|
|
41
|
+
"./src/make-check-runner.ts": "./src/cli/make-check-runner.ts",
|
|
42
|
+
"./src/make-file-probe.ts": "./src/uncommitted/make-file-probe.ts",
|
|
43
|
+
"./src/parse-added-lines.ts": "./src/local-paths/parse-added-lines.ts",
|
|
44
|
+
"./src/parse-chex-args.ts": "./src/cli/parse-chex-args.ts",
|
|
45
|
+
"./src/parse-lane-limits.ts": "./src/test-timeouts/parse-lane-limits.ts",
|
|
46
|
+
"./src/parse-lefthook-config.ts": "./src/lefthook/parse-lefthook-config.ts",
|
|
47
|
+
"./src/parse-pushed-refs.ts": "./src/push/parse-pushed-refs.ts",
|
|
48
|
+
"./src/parse-rig-lane-limits.ts": "./src/test-timeouts/parse-rig-lane-limits.ts",
|
|
49
|
+
"./src/parse-shell-words.ts": "./src/shell/parse-shell-words.ts",
|
|
50
|
+
"./src/pick-merge-blobs-command.ts": "./src/local-paths/pick-merge-blobs-command.ts",
|
|
51
|
+
"./src/pull-request-triggers.ts": "./src/workflows/pull-request-triggers.ts",
|
|
52
|
+
"./src/read-branch-base.ts": "./src/branch/read-branch-base.ts",
|
|
53
|
+
"./src/read-branch-files.ts": "./src/branch/read-branch-files.ts",
|
|
54
|
+
"./src/read-checks-profile.ts": "./src/workflows/read-checks-profile.ts",
|
|
55
|
+
"./src/read-pushed-ranges.ts": "./src/push/read-pushed-ranges.ts",
|
|
56
|
+
"./src/read-pushed-refs-input.ts": "./src/push/read-pushed-refs-input.ts",
|
|
57
|
+
"./src/read-range-commits.ts": "./src/commits/read-range-commits.ts",
|
|
58
|
+
"./src/run-chex.ts": "./src/cli/run-chex.ts",
|
|
59
|
+
"./src/run-commits-check.ts": "./src/commits/run-commits-check.ts",
|
|
60
|
+
"./src/run-init.ts": "./src/init/run-init.ts",
|
|
61
|
+
"./src/run-local-paths-check.ts": "./src/local-paths/run-local-paths-check.ts",
|
|
62
|
+
"./src/run-program.ts": "./src/program/run-program.ts",
|
|
63
|
+
"./src/run-test-layout-check.ts": "./src/test-layout/run-test-layout-check.ts",
|
|
64
|
+
"./src/run-test-timeouts-check.ts": "./src/test-timeouts/run-test-timeouts-check.ts",
|
|
65
|
+
"./src/run-uncommitted-check.ts": "./src/uncommitted/run-uncommitted-check.ts",
|
|
66
|
+
"./src/run-workflows-check.ts": "./src/workflows/run-workflows-check.ts",
|
|
67
|
+
"./src/shell-escape-parsers.ts": "./src/shell/shell-escape-parsers.ts",
|
|
68
|
+
"./src/workflow-context.ts": "./src/workflows/workflow-context.ts",
|
|
69
|
+
"./src/write-step-outputs.ts": "./src/output/write-step-outputs.ts",
|
|
70
|
+
"./src/write-text-file.ts": "./src/output/write-text-file.ts",
|
|
29
71
|
"./*": "./*"
|
|
30
72
|
},
|
|
31
73
|
"publishConfig": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
2
|
+
import { runProgram } from '../program/run-program.ts';
|
|
1
3
|
import { readBranchBase } from './read-branch-base.ts';
|
|
2
|
-
import type { RunProgram } from './run-program.ts';
|
|
3
|
-
import { runProgram } from './run-program.ts';
|
|
4
4
|
|
|
5
5
|
interface ReadBranchFilesOptions {
|
|
6
6
|
readonly cwd: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { match } from 'ts-pattern';
|
|
2
|
-
import { docsCheckNames } from '../check-names.ts';
|
|
3
|
-
import type { ChexRequest } from '../parse-chex-args.ts';
|
|
4
|
-
import { parseChexArgs } from '../parse-chex-args.ts';
|
|
2
|
+
import { docsCheckNames } from '../cli/check-names.ts';
|
|
3
|
+
import type { ChexRequest } from '../cli/parse-chex-args.ts';
|
|
4
|
+
import { parseChexArgs } from '../cli/parse-chex-args.ts';
|
|
5
5
|
|
|
6
6
|
export type DocsChecks =
|
|
7
7
|
| { readonly kind: 'none' }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { appendFile, readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { match } from 'ts-pattern';
|
|
4
|
-
import type { StepOutputFile } from '../write-step-outputs.ts';
|
|
5
|
-
import { writeStepOutputs } from '../write-step-outputs.ts';
|
|
4
|
+
import type { StepOutputFile } from '../output/write-step-outputs.ts';
|
|
5
|
+
import { writeStepOutputs } from '../output/write-step-outputs.ts';
|
|
6
6
|
import { parseDocsChecks } from './parse-docs-checks.ts';
|
|
7
7
|
import type { CheckPart, CheckPlan } from './plan-check-scripts.ts';
|
|
8
8
|
import { planCheckScripts } from './plan-check-scripts.ts';
|
package/src/cli.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { rename, rm } from 'node:fs/promises';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { readOptionalText } from '@zgeoff/std';
|
|
5
5
|
import { runCIPlanCommand } from './ci-plan/write-check-plan.ts';
|
|
6
|
+
import { makeCheckRunner } from './cli/make-check-runner.ts';
|
|
7
|
+
import { runChex } from './cli/run-chex.ts';
|
|
8
|
+
import { runCommitsCommand } from './commits/run-commits-check.ts';
|
|
6
9
|
import { runDependencyGatesCommand } from './dependency-gates/run-dependency-gates-check.ts';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { runUncommittedCommand } from './run-uncommitted-check.ts';
|
|
15
|
-
import { runWorkflowsCommand } from './run-workflows-check.ts';
|
|
16
|
-
import { writeTextFile } from './write-text-file.ts';
|
|
10
|
+
import { runInit } from './init/run-init.ts';
|
|
11
|
+
import { runLocalPathsCommand } from './local-paths/run-local-paths-check.ts';
|
|
12
|
+
import { writeTextFile } from './output/write-text-file.ts';
|
|
13
|
+
import { runTestLayoutCommand } from './test-layout/run-test-layout-check.ts';
|
|
14
|
+
import { runTestTimeoutsCommand } from './test-timeouts/run-test-timeouts-check.ts';
|
|
15
|
+
import { runUncommittedCommand } from './uncommitted/run-uncommitted-check.ts';
|
|
16
|
+
import { runWorkflowsCommand } from './workflows/run-workflows-check.ts';
|
|
17
17
|
|
|
18
18
|
process.exitCode = await runChex(process.argv.slice(2), {
|
|
19
19
|
runCheck: makeCheckRunner({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { dirname, join } from 'node:path';
|
|
2
|
+
import type { ProgramResult, RunProgram } from '../program/run-program.ts';
|
|
3
|
+
import { runProgram } from '../program/run-program.ts';
|
|
4
|
+
import { readPushedRanges } from '../push/read-pushed-ranges.ts';
|
|
5
|
+
import { readPushedRefsInput } from '../push/read-pushed-refs-input.ts';
|
|
2
6
|
import { formatCommitLines } from './format-commit-lines.ts';
|
|
3
|
-
import { readPushedRanges } from './read-pushed-ranges.ts';
|
|
4
|
-
import { readPushedRefsInput } from './read-pushed-refs-input.ts';
|
|
5
7
|
import type { CommitRange } from './read-range-commits.ts';
|
|
6
8
|
import { readRangeCommits } from './read-range-commits.ts';
|
|
7
|
-
import type { ProgramResult, RunProgram } from './run-program.ts';
|
|
8
|
-
import { runProgram } from './run-program.ts';
|
|
9
9
|
|
|
10
10
|
export interface CommitsCheckOptions {
|
|
11
11
|
readonly cwd: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RunProgram } from '../run-program.ts';
|
|
1
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
2
2
|
import { collectMissingFirstPartyExcludes } from './collect-missing-first-party-excludes.ts';
|
|
3
3
|
import { collectStaleAgeGateExcludes } from './collect-stale-age-gate-excludes.ts';
|
|
4
4
|
import { collectUnneededAuditIgnores } from './collect-unneeded-audit-ignores.ts';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { runProgram } from '../run-program.ts';
|
|
3
|
+
import { runProgram } from '../program/run-program.ts';
|
|
4
4
|
import type { DependencyGateSources } from './read-dependency-gate-findings.ts';
|
|
5
5
|
import { readDependencyGateFindings } from './read-dependency-gate-findings.ts';
|
|
6
6
|
|
package/src/docs/check-prose.sh
CHANGED
|
@@ -45,6 +45,22 @@ for root in .agents/skills .claude/skills skills sync/skills; do
|
|
|
45
45
|
done
|
|
46
46
|
set -- "$@" ':(exclude,attr:linguist-vendored)' ':(exclude,attr:linguist-vendored=true)'
|
|
47
47
|
|
|
48
|
+
if ! perl -e 1 > /dev/null 2>&1; then
|
|
49
|
+
echo "check-prose: perl is required and was not found on the PATH, so no doc was checked" >&2
|
|
50
|
+
exit 2
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
failure_marker=$(mktemp) || exit 2
|
|
54
|
+
rm -f "$failure_marker"
|
|
55
|
+
trap 'rm -f "$failure_marker"' EXIT
|
|
56
|
+
|
|
57
|
+
probe_status=0
|
|
58
|
+
git grep -P -e x -- ':(exclude)*' > /dev/null 2>&1 || probe_status=$?
|
|
59
|
+
if [ "$probe_status" -gt 1 ]; then
|
|
60
|
+
echo "check-prose: git was built without PCRE support, so no doc was checked" >&2
|
|
61
|
+
exit 2
|
|
62
|
+
fi
|
|
63
|
+
|
|
48
64
|
# The greps below read git's file list in pipelines, which drop git's exit status, so a git that
|
|
49
65
|
# cannot list the files fails here once.
|
|
50
66
|
if ! git ls-files --cached --others --exclude-standard -- "$@" > /dev/null; then
|
|
@@ -54,8 +70,51 @@ fi
|
|
|
54
70
|
|
|
55
71
|
# Every grep reads untracked files too, so a new doc is checked before it is staged, and skips
|
|
56
72
|
# binary files.
|
|
73
|
+
# A git grep that fails for any reason but "no match" (status 1) writes the marker file, because the
|
|
74
|
+
# greps run in command substitutions that drop their status. The script then fails instead of
|
|
75
|
+
# printing "clean".
|
|
57
76
|
grep_docs() {
|
|
58
|
-
|
|
77
|
+
local status=0
|
|
78
|
+
git grep --untracked -I "$@" || status=$?
|
|
79
|
+
if [ "$status" -gt 1 ]; then
|
|
80
|
+
echo "check-prose: git grep failed with status $status, so a check did not run" >&2
|
|
81
|
+
: > "$failure_marker"
|
|
82
|
+
fi
|
|
83
|
+
return 0
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# macOS awk dies on a line that is not valid UTF-8 under a UTF-8 locale, so awk runs byte-wise.
|
|
87
|
+
# A failed awk marks the run as incomplete, because the callers read it in command substitutions
|
|
88
|
+
# that drop its status.
|
|
89
|
+
run_awk() {
|
|
90
|
+
LC_ALL=C awk "$@" || : > "$failure_marker"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# Cuts byte-wise, for the same reason.
|
|
94
|
+
run_cut() {
|
|
95
|
+
LC_ALL=C cut "$@" || : > "$failure_marker"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# Runs awk over the NUL-separated paths on stdin.
|
|
99
|
+
xargs_awk() {
|
|
100
|
+
xargs -0 -r env LC_ALL=C awk "$@" || : > "$failure_marker"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Prints the lines of stdin that match the Perl pattern $1 before the unit separator, ignoring case.
|
|
104
|
+
# perl stands in for grep -P, which BSD grep lacks. It matches the line and the pattern decoded as
|
|
105
|
+
# UTF-8, so word boundaries and case folding follow Unicode as GNU grep's do under a UTF-8 locale,
|
|
106
|
+
# and an invalid byte becomes U+FFFD, so the rest of the line still matches. It prints the original bytes.
|
|
107
|
+
grep_before_separator() {
|
|
108
|
+
CHECK_PROSE_PATTERN=$1 perl -MEncode -ne '
|
|
109
|
+
BEGIN {
|
|
110
|
+
my $pattern = $ENV{CHECK_PROSE_PATTERN};
|
|
111
|
+
utf8::decode($pattern);
|
|
112
|
+
$p = qr/^[^\x1f]*(?:$pattern)/iu;
|
|
113
|
+
}
|
|
114
|
+
my $line = $_;
|
|
115
|
+
$line = Encode::decode("UTF-8", $line, Encode::FB_DEFAULT);
|
|
116
|
+
print if $line =~ $p' ||
|
|
117
|
+
: > "$failure_marker"
|
|
59
118
|
}
|
|
60
119
|
|
|
61
120
|
# Prints the Markdown files the paths name, under the directory in $markdown_dir when it is set.
|
|
@@ -126,7 +185,7 @@ banned_words='\bsurfaces?\b|load-bearing|\bseams?\b|\bceilings?\b|(?<!code )\bfe
|
|
|
126
185
|
report 'Banned words:' \
|
|
127
186
|
"$(
|
|
128
187
|
grep_docs -nPi "$banned_words" -- "$@" ':(exclude)*.md' ':(exclude)AGENTS.md' ':(exclude)agents'
|
|
129
|
-
list_markdown "$@" ':(exclude)AGENTS.md' ':(exclude)agents' |
|
|
188
|
+
list_markdown "$@" ':(exclude)AGENTS.md' ':(exclude)agents' | xargs_awk "$fence_awk"'
|
|
130
189
|
# Replaces each code span with a space. As in CommonMark, a span closes at the next backtick run
|
|
131
190
|
# as long as the one that opens it, and a run that nothing closes stays as text.
|
|
132
191
|
function strip_spans(s, out, start, n, rest, r, off, closed) {
|
|
@@ -171,7 +230,7 @@ report 'Banned words:' \
|
|
|
171
230
|
gsub(/\037/, "", text)
|
|
172
231
|
text = strip_spans(text)
|
|
173
232
|
print text "\037" file_name()":"FNR":"$0
|
|
174
|
-
}' |
|
|
233
|
+
}' | grep_before_separator "$banned_words" | run_cut -d $'\037' -f 2-
|
|
175
234
|
)"
|
|
176
235
|
|
|
177
236
|
report 'Filler with no term-of-art use:' \
|
|
@@ -189,7 +248,7 @@ report '"Should succeed" in a procedure — state the expected outcome instead:'
|
|
|
189
248
|
report 'Number joined to its unit ("64KB"; write "64 KB"; code blocks are exempt):' \
|
|
190
249
|
"$(
|
|
191
250
|
grep_docs -nP '\b[0-9]+(KB|MB|GB|TB|KiB|MiB|GiB|ms)\b' -- "$@" ':(exclude)*.md'
|
|
192
|
-
list_markdown "$@" |
|
|
251
|
+
list_markdown "$@" | xargs_awk "$fence_awk"'
|
|
193
252
|
{
|
|
194
253
|
m = fence_marker($0)
|
|
195
254
|
if (m != "") {
|
|
@@ -206,7 +265,7 @@ report 'Number joined to its unit ("64KB"; write "64 KB"; code blocks are exempt
|
|
|
206
265
|
# reader types may hold a value. A bare s, d or h joined to its number is no unit here ("1990s",
|
|
207
266
|
# "2d"); its spaced form is.
|
|
208
267
|
report 'Values with units under docs/architecture (the code owns its values; code blocks are exempt):' \
|
|
209
|
-
"$(markdown_dir=docs/architecture/ list_markdown "$@" |
|
|
268
|
+
"$(markdown_dir=docs/architecture/ list_markdown "$@" | xargs_awk "$fence_awk"'
|
|
210
269
|
{
|
|
211
270
|
m = fence_marker($0)
|
|
212
271
|
if (m != "") {
|
|
@@ -224,11 +283,11 @@ report 'Values with units under docs/architecture (the code owns its values; cod
|
|
|
224
283
|
}')"
|
|
225
284
|
|
|
226
285
|
report 'Horizontal rules outside YAML frontmatter:' \
|
|
227
|
-
"$(list_markdown "$@" |
|
|
286
|
+
"$(list_markdown "$@" | xargs_awk \
|
|
228
287
|
'FNR==1{fm=($0=="---")} fm&&FNR>1&&$0=="---"{fm=0;next} !fm&&$0=="---"{print substr(FILENAME, 3)": "FNR}')"
|
|
229
288
|
|
|
230
289
|
report 'Untagged code fences:' \
|
|
231
|
-
"$(list_markdown "$@" |
|
|
290
|
+
"$(list_markdown "$@" | xargs_awk "$fence_awk"'
|
|
232
291
|
{
|
|
233
292
|
m = fence_marker($0)
|
|
234
293
|
if (m == "") next
|
|
@@ -623,14 +682,14 @@ done < <(list_markdown "$@")
|
|
|
623
682
|
|
|
624
683
|
paragraphs=
|
|
625
684
|
if [ "${#paragraph_files[@]}" -gt 0 ]; then
|
|
626
|
-
paragraphs=$(
|
|
685
|
+
paragraphs=$(run_awk -v warn="$paragraph_warn" "$fence_awk$paragraph_awk" "${paragraph_files[@]}")
|
|
627
686
|
fi
|
|
628
687
|
|
|
629
688
|
report "Paragraphs over $paragraph_fail words in a changed file (split each one; lists, tables and code blocks are exempt):" \
|
|
630
|
-
"$(
|
|
689
|
+
"$(run_awk -F: -v limit="$paragraph_fail" '$NF > limit { print $0" words" }' <<< "$paragraphs")"
|
|
631
690
|
|
|
632
691
|
candidate "Paragraphs over $paragraph_warn words in a changed file (warning; reread each one and split it where it defends a decision):" \
|
|
633
|
-
"$(
|
|
692
|
+
"$(run_awk -F: -v limit="$paragraph_fail" '$NF != "" && $NF <= limit { print $0" words" }' <<< "$paragraphs")"
|
|
634
693
|
|
|
635
694
|
candidate 'Candidates — filler words with term-of-art uses; cull the filler, keep the terms:' \
|
|
636
695
|
"$(grep_docs -nPi '\b(naturally|cleanly|trivially|easy|simple|quick)\b' -- "$@")"
|
|
@@ -650,6 +709,11 @@ candidate 'Candidates — sentence-initial "A x is a" definitions; keep one only
|
|
|
650
709
|
candidate 'Candidates — contrast frames, counted lists and stock openers; state the move, name the items, open with the job:' \
|
|
651
710
|
"$(grep_docs -nPi ', not (a|an|the|its|their|from|for|to|in|on|by|only|just)\b|\brather than\b|\bis not the (job|point)\b|\b(two|three|four|five) (ways|traps|mistakes|things|rules)\b|^(This|The) skill (is|helps|lets|explains|finds|builds|shows)\b' -- "$@")"
|
|
652
711
|
|
|
712
|
+
if [ -e "$failure_marker" ]; then
|
|
713
|
+
echo "check-prose: a check failed to run, so the result above is incomplete" >&2
|
|
714
|
+
exit 2
|
|
715
|
+
fi
|
|
716
|
+
|
|
653
717
|
if [ "$fail" -eq 0 ]; then
|
|
654
718
|
echo 'check-prose: clean (candidates above, if any, need judgment only)'
|
|
655
719
|
fi
|
|
@@ -38,10 +38,15 @@ while IFS= read -r file; do
|
|
|
38
38
|
[ -f "$file" ] && readmes+=("$file")
|
|
39
39
|
done < <(sort -u <<< "$listing")
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
# bash 3.2 has no associative arrays, so membership scans the list. An empty array is unbound under
|
|
42
|
+
# set -u in bash 3.2, so each expansion of it is guarded.
|
|
43
|
+
is_listed() {
|
|
44
|
+
local readme
|
|
45
|
+
for readme in ${readmes[@]+"${readmes[@]}"}; do
|
|
46
|
+
[ "$readme" = "$1" ] && return 0
|
|
47
|
+
done
|
|
48
|
+
return 1
|
|
49
|
+
}
|
|
45
50
|
|
|
46
51
|
# Holds when the first H1 outside a code block starts "Spike: ".
|
|
47
52
|
is_spike() {
|
|
@@ -63,7 +68,7 @@ is_spike() {
|
|
|
63
68
|
# Holds when a README in one of the folder's direct subfolders is a spike README.
|
|
64
69
|
indexes_spikes() {
|
|
65
70
|
local dir=$1 readme
|
|
66
|
-
for readme in "${readmes[@]}"; do
|
|
71
|
+
for readme in ${readmes[@]+"${readmes[@]}"}; do
|
|
67
72
|
if [[ $readme == "$dir"/*/README.md && $readme != "$dir"/*/*/README.md ]] && is_spike "$readme"; then
|
|
68
73
|
return 0
|
|
69
74
|
fi
|
|
@@ -76,7 +81,7 @@ is_design() {
|
|
|
76
81
|
[[ $readme == docs/design/*/README.md && /$readme/ != */spikes/* ]] || return 1
|
|
77
82
|
[[ $readme != docs/design/*/*/README.md ]] && return 0
|
|
78
83
|
parent=$(dirname "$(dirname "$readme")")/README.md
|
|
79
|
-
|
|
84
|
+
is_listed "$parent" && is_design "$parent"
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
manifests=(package.json go.mod Cargo.toml build.gradle.kts build.gradle settings.gradle.kts settings.gradle)
|
|
@@ -96,7 +101,7 @@ is_known() {
|
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
unknown=0
|
|
99
|
-
for readme in "${readmes[@]}"; do
|
|
104
|
+
for readme in ${readmes[@]+"${readmes[@]}"}; do
|
|
100
105
|
if ! is_known "$readme"; then
|
|
101
106
|
unknown=$((unknown + 1))
|
|
102
107
|
echo "$readme: not one of the five kinds of README; move its content into docs/, or into a code comment beside the code it explains"
|
package/src/docs/check-skill.sh
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { match } from 'ts-pattern';
|
|
2
|
+
import type { LefthookOutcome } from '../lefthook/build-lefthook-extends.ts';
|
|
3
|
+
import { baselinePath, buildLefthookExtends } from '../lefthook/build-lefthook-extends.ts';
|
|
4
|
+
import { buildLefthookGuard, guardName, guardedHooks } from '../lefthook/build-lefthook-guard.ts';
|
|
2
5
|
import type { PackageOutcome } from './build-init-package.ts';
|
|
3
6
|
import { buildInitPackage, docsScript } from './build-init-package.ts';
|
|
4
|
-
import type { LefthookOutcome } from './build-lefthook-extends.ts';
|
|
5
|
-
import { baselinePath, buildLefthookExtends } from './build-lefthook-extends.ts';
|
|
6
|
-
import { buildLefthookGuard, guardName, guardedHooks } from './build-lefthook-guard.ts';
|
|
7
7
|
|
|
8
8
|
export interface InitWrite {
|
|
9
9
|
readonly file: 'lefthook.yml' | 'package.json';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { hostname } from 'node:os';
|
|
2
|
-
import { formatCommitLines } from '
|
|
2
|
+
import { formatCommitLines } from '../commits/format-commit-lines.ts';
|
|
3
|
+
import type { CommitRange } from '../commits/read-range-commits.ts';
|
|
4
|
+
import { readRangeCommits } from '../commits/read-range-commits.ts';
|
|
5
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
6
|
+
import { runProgram } from '../program/run-program.ts';
|
|
7
|
+
import { readPushedRanges } from '../push/read-pushed-ranges.ts';
|
|
8
|
+
import { readPushedRefsInput } from '../push/read-pushed-refs-input.ts';
|
|
3
9
|
import { parseAddedLines } from './parse-added-lines.ts';
|
|
4
10
|
import type { MergeBlobsReadings } from './pick-merge-blobs-command.ts';
|
|
5
11
|
import { pickMergeBlobsCommand } from './pick-merge-blobs-command.ts';
|
|
6
|
-
import { readPushedRanges } from './read-pushed-ranges.ts';
|
|
7
|
-
import { readPushedRefsInput } from './read-pushed-refs-input.ts';
|
|
8
|
-
import type { CommitRange } from './read-range-commits.ts';
|
|
9
|
-
import { readRangeCommits } from './read-range-commits.ts';
|
|
10
|
-
import type { RunProgram } from './run-program.ts';
|
|
11
|
-
import { runProgram } from './run-program.ts';
|
|
12
12
|
|
|
13
13
|
export interface LocalPathsCheckOptions {
|
|
14
14
|
readonly cwd: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { ReadBranchBaseOptions } from '../branch/read-branch-base.ts';
|
|
2
|
+
import { readBranchBase, readDefaultBranch } from '../branch/read-branch-base.ts';
|
|
3
|
+
import type { CommitRange } from '../commits/read-range-commits.ts';
|
|
1
4
|
import { parsePushedRefs } from './parse-pushed-refs.ts';
|
|
2
|
-
import type { ReadBranchBaseOptions } from './read-branch-base.ts';
|
|
3
|
-
import { readBranchBase, readDefaultBranch } from './read-branch-base.ts';
|
|
4
|
-
import type { CommitRange } from './read-range-commits.ts';
|
|
5
5
|
|
|
6
6
|
export interface PushedRangesOptions extends ReadBranchBaseOptions {
|
|
7
7
|
// The lines git hands a pre-push hook on stdin, or null outside a push.
|
|
@@ -79,6 +79,7 @@ function collectTestFolderFaults(trackedPaths: readonly string[]): string[] {
|
|
|
79
79
|
return collectFolderPaths(trackedPaths)
|
|
80
80
|
.filter((folder) => testFolderNames.has(posix.basename(folder)))
|
|
81
81
|
.filter((folder) => !isCargoTestsFolder(folder, tracked))
|
|
82
|
+
.filter((folder) => !isNixTestsFolder(folder, trackedPaths))
|
|
82
83
|
.map(
|
|
83
84
|
(folder) =>
|
|
84
85
|
`${folder}/ is a test folder; move its tests beside the modules they test, its end-to-end tests into the package's e2e/, and its helpers into src/test-utils/`,
|
|
@@ -93,6 +94,17 @@ function isCargoTestsFolder(folder: string, tracked: ReadonlySet<string>): boole
|
|
|
93
94
|
);
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
// A tests/ folder of only .nix files holds NixOS checks that a flake imports, not tests that move.
|
|
98
|
+
function isNixTestsFolder(folder: string, trackedPaths: readonly string[]): boolean {
|
|
99
|
+
const files = trackedPaths.filter((path) => path.startsWith(`${folder}/`));
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
posix.basename(folder) === 'tests' &&
|
|
103
|
+
files.length > 0 &&
|
|
104
|
+
files.every((path) => path.endsWith('.nix'))
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
function collectHelperFolderFaults(layout: TestLayout): string[] {
|
|
97
109
|
return layout.workspaces
|
|
98
110
|
.filter((root) => layout.trackedPaths.some((path) => path.startsWith(`${root}/test-utils/`)))
|
|
@@ -5,6 +5,12 @@ import type { SourceFile, TestLayout } from './types.ts';
|
|
|
5
5
|
|
|
6
6
|
const sourcePattern = /\.(?:[cm]?[jt]s|[jt]sx)$/u;
|
|
7
7
|
|
|
8
|
+
interface ParsedImports {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
|
|
11
|
+
readonly specifiers: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
// The faults of imports: a relative import of another workspace's helper, and production code that
|
|
9
15
|
// imports a helper.
|
|
10
16
|
export function collectImportFaults(
|
|
@@ -12,70 +18,80 @@ export function collectImportFaults(
|
|
|
12
18
|
layout: TestLayout,
|
|
13
19
|
sources: readonly SourceFile[],
|
|
14
20
|
): string[] {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const parseFaults: string[] = [];
|
|
22
|
+
const imports: ParsedImports[] = [];
|
|
23
|
+
|
|
24
|
+
for (const source of sources.filter((candidate) => sourcePattern.test(candidate.path))) {
|
|
25
|
+
const parsed = oxc.parseSync(source.path, source.text);
|
|
26
|
+
const [parseError] = parsed.errors;
|
|
27
|
+
|
|
28
|
+
if (parseError === undefined) {
|
|
29
|
+
imports.push({
|
|
30
|
+
path: source.path,
|
|
31
|
+
specifiers: collectImportSpecifiers(oxc, parsed.program),
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
parseFaults.push(
|
|
35
|
+
`${source.path} does not parse, so the layout check cannot read its imports: ${parseError.message}`,
|
|
29
36
|
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const packageHelperPattern = /^@[^/]+\/[^/]+\/test-utils(?:\/|$)/u;
|
|
34
|
-
|
|
35
|
-
function collectSpecifierFaults(layout: TestLayout, importer: string, specifier: string): string[] {
|
|
36
|
-
const isRelative = specifier.startsWith('./') || specifier.startsWith('../');
|
|
37
|
-
const target = isRelative ? normalize(join(dirname(importer), specifier)) : specifier;
|
|
38
|
-
const isHelper = isRelative ? isHelperPath(layout, target) : packageHelperPattern.test(specifier);
|
|
39
|
-
|
|
40
|
-
if (isHelper && isProductionCode(layout, importer)) {
|
|
41
|
-
return [
|
|
42
|
-
`${importer} imports ${target}, a test helper, from production code; import test helpers only from tests and other test helpers`,
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!isRelative || !isHelper) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const targetRoot = getWorkspaceRoot(layout, target);
|
|
51
|
-
|
|
52
|
-
if (targetRoot === getWorkspaceRoot(layout, importer)) {
|
|
53
|
-
return [];
|
|
37
|
+
}
|
|
54
38
|
}
|
|
55
39
|
|
|
56
|
-
const
|
|
57
|
-
? "import it by the package's name, with the package as a workspace:* dev dependency"
|
|
58
|
-
: "copy the helper into the importer's own test-utils/";
|
|
40
|
+
const testOnlyRoots = collectTestOnlyWorkspaces(layout, imports);
|
|
59
41
|
|
|
60
|
-
return [
|
|
42
|
+
return [
|
|
43
|
+
...parseFaults,
|
|
44
|
+
...imports.flatMap((file) =>
|
|
45
|
+
file.specifiers.flatMap((specifier) =>
|
|
46
|
+
collectSpecifierFaults(layout, testOnlyRoots, file.path, specifier),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
];
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
// A private workspace that no production file imports. A root-level source such as cli.ts counts
|
|
53
|
+
// as production here, though it may import helpers itself. The check runs to a fixed point: a workspace that a test-only workspace imports counts as imported
|
|
54
|
+
// by test code.
|
|
55
|
+
function collectTestOnlyWorkspaces(
|
|
56
|
+
layout: TestLayout,
|
|
57
|
+
imports: readonly ParsedImports[],
|
|
58
|
+
): ReadonlySet<string> {
|
|
59
|
+
const candidates = new Map(
|
|
60
|
+
layout.workspacePackages
|
|
61
|
+
.filter((workspace) => workspace.isPrivate && workspace.name !== '')
|
|
62
|
+
.map((workspace) => [workspace.root, workspace.name]),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
let changed = true;
|
|
66
|
+
|
|
67
|
+
while (changed) {
|
|
68
|
+
changed = false;
|
|
69
|
+
|
|
70
|
+
const roots = new Set(candidates.keys());
|
|
71
|
+
|
|
72
|
+
for (const [root, name] of candidates) {
|
|
73
|
+
const importers = imports
|
|
74
|
+
.filter((file) => getWorkspaceRoot(layout, file.path) !== root)
|
|
75
|
+
.filter((file) =>
|
|
76
|
+
file.specifiers.some(
|
|
77
|
+
(specifier) => specifier === name || specifier.startsWith(`${name}/`),
|
|
78
|
+
),
|
|
79
|
+
)
|
|
80
|
+
.map((file) => file.path);
|
|
81
|
+
|
|
82
|
+
const isImportedOnlyByTests = importers.every(
|
|
83
|
+
(path) => !isProductionImporter(layout, roots, path),
|
|
84
|
+
);
|
|
65
85
|
|
|
66
|
-
|
|
67
|
-
|
|
86
|
+
if (!isImportedOnlyByTests) {
|
|
87
|
+
candidates.delete(root);
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (root === '') {
|
|
75
|
-
return layout.isWorkspaceRepo ? 'test-utils' : 'src/test-utils';
|
|
89
|
+
changed = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
return
|
|
94
|
+
return new Set(candidates.keys());
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
// A path belongs to its workspace, to the single package of a repo with no workspaces, or else to
|
|
@@ -98,10 +114,16 @@ function getWorkspaceRoot(layout: TestLayout, path: string): string {
|
|
|
98
114
|
|
|
99
115
|
const packageTestFolders = new Set(['e2e', 'evals', 'bench', 'test-utils']);
|
|
100
116
|
|
|
101
|
-
|
|
117
|
+
// Whether a file's import keeps its target in production. Unlike isProductionCode, a root-level
|
|
118
|
+
// source such as cli.ts counts, because it ships.
|
|
119
|
+
function isProductionImporter(
|
|
120
|
+
layout: TestLayout,
|
|
121
|
+
testOnlyRoots: ReadonlySet<string>,
|
|
122
|
+
path: string,
|
|
123
|
+
): boolean {
|
|
102
124
|
const root = getWorkspaceRoot(layout, path);
|
|
103
125
|
|
|
104
|
-
if ((root
|
|
126
|
+
if (testOnlyRoots.has(root) || layout.testPreloads.includes(path) || isHelperPath(layout, path)) {
|
|
105
127
|
return false;
|
|
106
128
|
}
|
|
107
129
|
|
|
@@ -120,3 +142,68 @@ function isProductionCode(layout: TestLayout, path: string): boolean {
|
|
|
120
142
|
|
|
121
143
|
return !packageTestFolders.has(folder ?? '');
|
|
122
144
|
}
|
|
145
|
+
|
|
146
|
+
function isHelperPath(layout: TestLayout, path: string): boolean {
|
|
147
|
+
const folder = getHelperFolder(layout, getWorkspaceRoot(layout, path));
|
|
148
|
+
|
|
149
|
+
return path === folder || path.startsWith(`${folder}/`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getHelperFolder(layout: TestLayout, root: string): string {
|
|
153
|
+
if (layout.workspaces.includes(root)) {
|
|
154
|
+
return `${root}/src/test-utils`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (root === '') {
|
|
158
|
+
return layout.isWorkspaceRepo ? 'test-utils' : 'src/test-utils';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return `${root}/test-utils`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const packageHelperPattern = /^@[^/]+\/[^/]+\/test-utils(?:\/|$)/u;
|
|
165
|
+
|
|
166
|
+
function collectSpecifierFaults(
|
|
167
|
+
layout: TestLayout,
|
|
168
|
+
testOnlyRoots: ReadonlySet<string>,
|
|
169
|
+
importer: string,
|
|
170
|
+
specifier: string,
|
|
171
|
+
): string[] {
|
|
172
|
+
const isRelative = specifier.startsWith('./') || specifier.startsWith('../');
|
|
173
|
+
const target = isRelative ? normalize(join(dirname(importer), specifier)) : specifier;
|
|
174
|
+
const isHelper = isRelative ? isHelperPath(layout, target) : packageHelperPattern.test(specifier);
|
|
175
|
+
|
|
176
|
+
if (isHelper && isProductionCode(layout, testOnlyRoots, importer)) {
|
|
177
|
+
return [
|
|
178
|
+
`${importer} imports ${target}, a test helper, from production code; import test helpers only from tests and other test helpers`,
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!isRelative || !isHelper) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const targetRoot = getWorkspaceRoot(layout, target);
|
|
187
|
+
|
|
188
|
+
if (targetRoot === getWorkspaceRoot(layout, importer)) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const fix = layout.workspaces.includes(targetRoot)
|
|
193
|
+
? "import it by the package's name, with the package as a workspace:* dev dependency"
|
|
194
|
+
: "copy the helper into the importer's own test-utils/";
|
|
195
|
+
|
|
196
|
+
return [`${importer} imports ${target}, a test helper of ${targetRoot}; ${fix}`];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function isProductionCode(
|
|
200
|
+
layout: TestLayout,
|
|
201
|
+
testOnlyRoots: ReadonlySet<string>,
|
|
202
|
+
path: string,
|
|
203
|
+
): boolean {
|
|
204
|
+
return !isRootLevelSource(layout, path) && isProductionImporter(layout, testOnlyRoots, path);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isRootLevelSource(layout: TestLayout, path: string): boolean {
|
|
208
|
+
return layout.isWorkspaceRepo && getWorkspaceRoot(layout, path) === '';
|
|
209
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseLaneLimits } from '../parse-lane-limits.ts';
|
|
1
|
+
import { parseLaneLimits } from '../test-timeouts/parse-lane-limits.ts';
|
|
2
2
|
|
|
3
3
|
// The suffixes that a test file name may carry before `.test.ts`. A lane of the resolved
|
|
4
4
|
// rig.config.ts has exactly the suffix it gives, and a lane only the oxlint config names has
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import type { SourceFile } from './types.ts';
|
|
3
|
+
|
|
4
|
+
export interface TestPreloads {
|
|
5
|
+
readonly preloads: string[];
|
|
6
|
+
|
|
7
|
+
readonly faults: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Reads the `[test] preload` list of each bunfig.toml. A relative entry names a test file, resolved
|
|
11
|
+
// against the folder of its bunfig.toml; a bare package name is skipped.
|
|
12
|
+
export function collectTestPreloads(bunfigs: readonly SourceFile[]): TestPreloads {
|
|
13
|
+
const preloads: string[] = [];
|
|
14
|
+
const faults: string[] = [];
|
|
15
|
+
|
|
16
|
+
for (const bunfig of bunfigs) {
|
|
17
|
+
let parsed: unknown;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
parsed = Bun.TOML.parse(bunfig.text);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
23
|
+
|
|
24
|
+
faults.push(
|
|
25
|
+
`${bunfig.path} does not parse, so the layout check cannot read its test preloads: ${reason}; fix the TOML`,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const entry of pickPreloadEntries(parsed)) {
|
|
32
|
+
if (entry.startsWith('./') || entry.startsWith('../')) {
|
|
33
|
+
const joined = posix.join(posix.dirname(bunfig.path), entry);
|
|
34
|
+
|
|
35
|
+
preloads.push(posix.normalize(joined));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { preloads, faults };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pickPreloadEntries(parsed: unknown): string[] {
|
|
44
|
+
const section: unknown =
|
|
45
|
+
typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'test') : null;
|
|
46
|
+
|
|
47
|
+
const list: unknown =
|
|
48
|
+
typeof section === 'object' && section !== null ? Reflect.get(section, 'preload') : null;
|
|
49
|
+
|
|
50
|
+
if (typeof list === 'string') {
|
|
51
|
+
return [list];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return Array.isArray(list) ? list.filter((item): item is string => typeof item === 'string') : [];
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WorkspacePackage } from './types.ts';
|
|
2
|
+
|
|
3
|
+
// Reads the name and `private` flag of the package.json of each workspace folder.
|
|
4
|
+
export function readWorkspacePackages(
|
|
5
|
+
roots: readonly string[],
|
|
6
|
+
readText: (path: string) => Promise<string>,
|
|
7
|
+
): Promise<WorkspacePackage[]> {
|
|
8
|
+
return Promise.all(
|
|
9
|
+
roots.map(async (root) => {
|
|
10
|
+
const text = await readText(`${root}/package.json`);
|
|
11
|
+
|
|
12
|
+
const manifest: unknown = JSON.parse(text);
|
|
13
|
+
|
|
14
|
+
const fields: Record<string, unknown> =
|
|
15
|
+
typeof manifest === 'object' && manifest !== null ? { ...manifest } : {};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
root,
|
|
19
|
+
name: typeof fields['name'] === 'string' ? fields['name'] : '',
|
|
20
|
+
isPrivate: fields['private'] === true,
|
|
21
|
+
};
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { runProgram } from '
|
|
3
|
-
import { collectLaneSuffixes } from './
|
|
4
|
-
import { collectTestLayoutFaults } from './
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { join, posix } from 'node:path';
|
|
2
|
+
import { runProgram } from '../program/run-program.ts';
|
|
3
|
+
import { collectLaneSuffixes } from './collect-lane-suffixes.ts';
|
|
4
|
+
import { collectTestLayoutFaults } from './collect-test-layout-faults.ts';
|
|
5
|
+
import { collectTestPreloads } from './collect-test-preloads.ts';
|
|
6
|
+
import { collectWorkspaceRoots } from './collect-workspace-roots.ts';
|
|
7
|
+
import type { OxcParserModule } from './oxc-parser-module.ts';
|
|
8
|
+
import { parseWorkspacePatterns } from './parse-workspace-patterns.ts';
|
|
9
|
+
import { readOxcParser } from './read-oxc-parser.ts';
|
|
10
|
+
import { readWorkspacePackages } from './read-workspace-packages.ts';
|
|
9
11
|
|
|
10
12
|
export interface TestLayoutCheckOptions {
|
|
11
13
|
readonly readTrackedPaths: () => Promise<readonly string[]>;
|
|
@@ -54,21 +56,35 @@ export async function runTestLayoutCheck(options: TestLayoutCheckOptions): Promi
|
|
|
54
56
|
.map(async (path) => ({ path, text: await options.readText(path) })),
|
|
55
57
|
);
|
|
56
58
|
|
|
57
|
-
const
|
|
59
|
+
const workspaceRoots =
|
|
60
|
+
workspaces.kind === 'single' ? [] : collectWorkspaceRoots(trackedPaths, workspaces.patterns);
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
workspaces:
|
|
64
|
-
workspaces.kind === 'single'
|
|
65
|
-
? []
|
|
66
|
-
: collectWorkspaceRoots(trackedPaths, workspaces.patterns),
|
|
67
|
-
isWorkspaceRepo: workspaces.kind === 'workspaces',
|
|
68
|
-
laneSuffixes: collectLaneSuffixes(oxlintConfigText, rigConfig),
|
|
69
|
-
},
|
|
70
|
-
sources,
|
|
62
|
+
const bunfigs = await Promise.all(
|
|
63
|
+
trackedPaths
|
|
64
|
+
.filter((path) => posix.basename(path) === 'bunfig.toml')
|
|
65
|
+
.map(async (path) => ({ path, text: await options.readText(path) })),
|
|
71
66
|
);
|
|
67
|
+
|
|
68
|
+
const testPreloads = collectTestPreloads(bunfigs);
|
|
69
|
+
|
|
70
|
+
const workspacePackages = await readWorkspacePackages(workspaceRoots, options.readText);
|
|
71
|
+
const parser = await options.readParser();
|
|
72
|
+
|
|
73
|
+
faults = [
|
|
74
|
+
...testPreloads.faults,
|
|
75
|
+
...collectTestLayoutFaults(
|
|
76
|
+
parser,
|
|
77
|
+
{
|
|
78
|
+
trackedPaths,
|
|
79
|
+
workspaces: workspaceRoots,
|
|
80
|
+
isWorkspaceRepo: workspaces.kind === 'workspaces',
|
|
81
|
+
laneSuffixes: collectLaneSuffixes(oxlintConfigText, rigConfig),
|
|
82
|
+
testPreloads: testPreloads.preloads,
|
|
83
|
+
workspacePackages,
|
|
84
|
+
},
|
|
85
|
+
sources,
|
|
86
|
+
),
|
|
87
|
+
];
|
|
72
88
|
} catch (error) {
|
|
73
89
|
options.writeError(`test-layout: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
74
90
|
|
package/src/test-layout/types.ts
CHANGED
|
@@ -4,6 +4,17 @@ export interface SourceFile {
|
|
|
4
4
|
readonly text: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
export interface WorkspacePackage {
|
|
8
|
+
// The workspace folder, relative to the repo root.
|
|
9
|
+
readonly root: string;
|
|
10
|
+
|
|
11
|
+
// The `name` of its package.json, or an empty string when it has none.
|
|
12
|
+
readonly name: string;
|
|
13
|
+
|
|
14
|
+
// Whether its package.json has `"private": true`.
|
|
15
|
+
readonly isPrivate: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export interface TestLayout {
|
|
8
19
|
// Every path git tracks.
|
|
9
20
|
readonly trackedPaths: readonly string[];
|
|
@@ -16,4 +27,11 @@ export interface TestLayout {
|
|
|
16
27
|
|
|
17
28
|
// The suffixes that lanes use, each with its dot, such as `.browser`.
|
|
18
29
|
readonly laneSuffixes: readonly string[];
|
|
30
|
+
|
|
31
|
+
// The files that a `[test] preload` entry of a bunfig.toml names by a relative path, relative to
|
|
32
|
+
// the repo root. They are test code.
|
|
33
|
+
readonly testPreloads: readonly string[];
|
|
34
|
+
|
|
35
|
+
// The name and privacy of each workspace's package.json.
|
|
36
|
+
readonly workspacePackages: readonly WorkspacePackage[];
|
|
19
37
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { basename, dirname, join, posix } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
3
|
+
import { runProgram } from '../program/run-program.ts';
|
|
4
|
+
import type { ShellWord } from '../shell/parse-shell-words.ts';
|
|
5
|
+
import { parseShellWords } from '../shell/parse-shell-words.ts';
|
|
6
|
+
import { findMember } from '../workflows/find-member.ts';
|
|
3
7
|
import { parseLaneLimits } from './parse-lane-limits.ts';
|
|
4
8
|
import { parseRigLaneLimits } from './parse-rig-lane-limits.ts';
|
|
5
|
-
import type { ShellWord } from './parse-shell-words.ts';
|
|
6
|
-
import { parseShellWords } from './parse-shell-words.ts';
|
|
7
|
-
import type { RunProgram } from './run-program.ts';
|
|
8
|
-
import { runProgram } from './run-program.ts';
|
|
9
9
|
|
|
10
10
|
export interface TestTimeoutsCheckOptions {
|
|
11
11
|
readonly cwd: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { readBranchFiles } from '../branch/read-branch-files.ts';
|
|
3
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
4
|
+
import { runProgram } from '../program/run-program.ts';
|
|
2
5
|
import { makeFileProbe } from './make-file-probe.ts';
|
|
3
|
-
import { readBranchFiles } from './read-branch-files.ts';
|
|
4
|
-
import type { RunProgram } from './run-program.ts';
|
|
5
|
-
import { runProgram } from './run-program.ts';
|
|
6
6
|
|
|
7
7
|
export interface UncommittedCheckOptions {
|
|
8
8
|
readonly cwd: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ShellWord } from '
|
|
2
|
-
import { parseShellWords } from '
|
|
1
|
+
import type { ShellWord } from '../shell/parse-shell-words.ts';
|
|
2
|
+
import { parseShellWords } from '../shell/parse-shell-words.ts';
|
|
3
3
|
|
|
4
4
|
// Each command contributes the word the shell runs, after any NAME=value assignments, plus the
|
|
5
5
|
// script that bash, sh or bun runs. A command outside the forms read here returns undefined, so the
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
+
import type { RunProgram } from '../program/run-program.ts';
|
|
3
|
+
import { runProgram } from '../program/run-program.ts';
|
|
4
|
+
import { parseShellWords } from '../shell/parse-shell-words.ts';
|
|
2
5
|
import { collectCommandNames } from './collect-command-names.ts';
|
|
3
6
|
import { collectConcurrencyFindings } from './collect-concurrency-findings.ts';
|
|
4
7
|
import { findInstallCachePath } from './find-install-cache-path.ts';
|
|
5
8
|
import { findMember } from './find-member.ts';
|
|
6
9
|
import { getTopLevelLine } from './get-top-level-line.ts';
|
|
7
|
-
import { parseShellWords } from './parse-shell-words.ts';
|
|
8
10
|
import { pullRequestTriggers } from './pull-request-triggers.ts';
|
|
9
11
|
import type { ChecksProfile } from './read-checks-profile.ts';
|
|
10
12
|
import { readChecksProfile } from './read-checks-profile.ts';
|
|
11
|
-
import type { RunProgram } from './run-program.ts';
|
|
12
|
-
import { runProgram } from './run-program.ts';
|
|
13
13
|
import type { Job, WorkflowContext, WorkflowFinding } from './workflow-context.ts';
|
|
14
14
|
|
|
15
15
|
export type { WorkflowFinding } from './workflow-context.ts';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/{collect-expression-references.ts → workflows/collect-expression-references.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|