@syntopica/quality-config 0.11.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.
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ // The licences a package would ship, checked against an allowlist.
3
+ //
4
+ // Usage:
5
+ // baseline-licenses [dir]
6
+ //
7
+ // Scoped to one package's *production* closure - its `dependencies`, and
8
+ // theirs, transitively. Development dependencies are excluded on purpose: a
9
+ // copyleft test runner is not distributed and is not a licence question, while
10
+ // a copyleft transitive runtime dependency of an MIT package is.
11
+ //
12
+ // `pnpm licenses list` is not the data source. Inside a workspace it reports
13
+ // the whole store - 986 packages for a config package with eight direct
14
+ // dependencies - so it cannot answer the only question that matters here.
15
+ // Walking the closure from the manifest can.
16
+ //
17
+ // Six packages in this repository publish to npm under MIT. Nothing verified
18
+ // that a transitive dependency had not introduced a copyleft licence into that
19
+ // tree. It had not, today: the four copyleft packages in the workspace
20
+ // (sharp-libvips, axe-core, lightningcss, node-forge) are all reached through
21
+ // templates and dev tooling. Nothing would have noticed if that changed.
22
+ import { readFile, realpath } from 'node:fs/promises'
23
+ import { dirname, resolve } from 'node:path'
24
+ import { argv, cwd, exit } from 'node:process'
25
+
26
+ // SPDX identifiers that permit redistribution inside an MIT-licensed package
27
+ // without imposing terms on the consumer. Anything outside this set is not
28
+ // automatically wrong - it is a decision, and it has to be recorded as one.
29
+ const PERMISSIVE = new Set([
30
+ '0BSD',
31
+ 'Apache-2.0',
32
+ 'BlueOak-1.0.0',
33
+ 'BSD-2-Clause',
34
+ 'BSD-3-Clause',
35
+ 'CC0-1.0',
36
+ 'ISC',
37
+ 'MIT',
38
+ 'MIT-0',
39
+ 'Python-2.0',
40
+ 'Unlicense',
41
+ 'WTFPL',
42
+ 'Zlib',
43
+ ])
44
+
45
+ const ALLOWLIST_FILE = '.baseline-licenses.json'
46
+ const root = resolve(cwd(), argv[2] ?? '.')
47
+ const today = new Date().toISOString().slice(0, 10)
48
+
49
+ const allowlist = await readAllowlist(resolve(root, ALLOWLIST_FILE))
50
+ const seen = new Map()
51
+ await walk(root, true)
52
+
53
+ const findings = []
54
+ const waived = []
55
+ const stale = []
56
+
57
+ for (const [name, info] of seen) {
58
+ if (isPermissive(info.license)) continue
59
+ const entry = allowlist[name]
60
+ if (!entry) findings.push({ name, ...info })
61
+ else if (entry.expires < today) stale.push({ name, ...info, entry })
62
+ else waived.push({ name, ...info, entry })
63
+ }
64
+
65
+ for (const item of waived) {
66
+ console.log(
67
+ `waived ${item.license} ${item.name} (expires ${item.entry.expires})\n` +
68
+ ` ${item.entry.reason}`,
69
+ )
70
+ }
71
+ for (const item of stale) {
72
+ console.error(
73
+ `EXPIRED ${item.license} ${item.name} (expired ${item.entry.expires})\n` +
74
+ ` ${item.entry.reason}\n Re-check it, then renew or remove it.`,
75
+ )
76
+ }
77
+ for (const item of findings) {
78
+ console.error(
79
+ `FAIL ${item.license} ${item.name}\n` +
80
+ ` reached via ${item.via}\n` +
81
+ ` Not a permissive licence. Replace the dependency, or record ` +
82
+ `the decision in ${ALLOWLIST_FILE} with a reason and an expiry.`,
83
+ )
84
+ }
85
+
86
+ console.log(
87
+ `\nbaseline-licenses: ${seen.size} production dependencies, ` +
88
+ `${findings.length} unreviewed, ${stale.length} expired, ${waived.length} waived.`,
89
+ )
90
+ if (findings.length + stale.length) exit(1)
91
+
92
+ // An SPDX expression, not just an identifier: `MIT OR Apache-2.0` is
93
+ // permissive because one of its options is, and `(BSD-3-Clause OR GPL-2.0)`
94
+ // is too - the consumer picks. `AND` is the opposite: every term binds.
95
+ function isPermissive(license) {
96
+ if (!license) return false
97
+ const expression = license.replace(/[()]/g, '').trim()
98
+ if (/\bAND\b/i.test(expression)) {
99
+ return expression
100
+ .split(/\s+AND\s+/i)
101
+ .every((term) => isPermissive(term.trim()))
102
+ }
103
+ if (/\bOR\b/i.test(expression)) {
104
+ return expression
105
+ .split(/\s+OR\s+/i)
106
+ .some((term) => isPermissive(term.trim()))
107
+ }
108
+ return PERMISSIVE.has(expression.replace(/\+$/, ''))
109
+ }
110
+
111
+ async function walk(dir, isRoot, via = '') {
112
+ let manifest
113
+ try {
114
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
115
+ manifest = JSON.parse(await readFile(resolve(dir, 'package.json'), 'utf8'))
116
+ } catch {
117
+ return
118
+ }
119
+
120
+ if (!isRoot) {
121
+ if (seen.has(manifest.name)) return
122
+ seen.set(manifest.name, { license: licenseOf(manifest), via })
123
+ }
124
+
125
+ for (const name of Object.keys(manifest.dependencies ?? {})) {
126
+ const target = await resolvePackage(dir, name)
127
+ if (!target) continue
128
+ await walk(target, false, isRoot ? name : `${via} > ${name}`)
129
+ }
130
+ }
131
+
132
+ function licenseOf(manifest) {
133
+ if (typeof manifest.license === 'string') return manifest.license
134
+ if (typeof manifest.license?.type === 'string') return manifest.license.type
135
+ if (Array.isArray(manifest.licenses)) {
136
+ return manifest.licenses.map((l) => l.type ?? l).join(' OR ')
137
+ }
138
+ return undefined
139
+ }
140
+
141
+ // Node's own resolution order, walked by hand: `require.resolve` refuses
142
+ // packages whose `exports` map has no `./package.json` entry, which is most of
143
+ // them, and would report a package that is installed and working as missing.
144
+ async function resolvePackage(from, name) {
145
+ let dir = from
146
+ for (;;) {
147
+ const candidate = resolve(dir, 'node_modules', name)
148
+ try {
149
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
150
+ await readFile(resolve(candidate, 'package.json'), 'utf8')
151
+ // Resolved through the symlink, not to it. Under pnpm's isolated layout
152
+ // every installed package is a link into `.pnpm/<hash>/node_modules/`,
153
+ // and its own dependencies are siblings *there*. Climbing from the link
154
+ // path instead walks back out to the workspace root and finds none of
155
+ // them - which is why this reported eight dependencies for a package
156
+ // whose real closure is in the hundreds.
157
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
158
+ return await realpath(candidate)
159
+ } catch {
160
+ /* keep climbing */
161
+ }
162
+ const parent = dirname(dir)
163
+ if (parent === dir) return null
164
+ dir = parent
165
+ }
166
+ }
167
+
168
+ async function readAllowlist(path) {
169
+ let raw
170
+ try {
171
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
172
+ raw = await readFile(path, 'utf8')
173
+ } catch {
174
+ return {}
175
+ }
176
+ const parsed = JSON.parse(raw)
177
+ for (const [name, entry] of Object.entries(parsed)) {
178
+ if (!entry?.reason || !entry?.expires) {
179
+ console.error(
180
+ `baseline-licenses: allowlist entry ${name} needs both \`reason\` and \`expires\`.`,
181
+ )
182
+ exit(2)
183
+ }
184
+ }
185
+ return parsed
186
+ }
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env node
2
+ // Runs `type-coverage` in every workspace that has its own tsconfig.json.
3
+ //
4
+ // The threshold lives in one place - `TYPE_COVERAGE_THRESHOLD` in
5
+ // src/type-coverage.ts - and is read from there rather than restated here, so
6
+ // the published constant and the gate that enforces it cannot drift. The file
7
+ // is a single exported number by design; if that ever stops being true this
8
+ // exits rather than guessing.
9
+ //
10
+ // Two categories of file are excluded, and only these two: framework build
11
+ // output, whose `any`s belong to the generator, and tests, where casting a mock
12
+ // to `any` is the point. `--strict` is on, so an `any` reached through a
13
+ // generic argument counts as uncovered.
14
+ //
15
+ // `--at-least <n>` lowers the bar for one repo. It exists for adoption: a
16
+ // codebase below the shared threshold cannot wire this gate at all otherwise,
17
+ // so the choice is an unenforced gate or none. Freezing at the measured value
18
+ // makes coverage a ratchet - it cannot fall - and the number in package.json
19
+ // is the debt, visible in every diff that changes it. Raise it as the `any`s
20
+ // go; never lower it to get green.
21
+ //
22
+ // `--ignore-files <glob>` adds to the two exclusions above. Repeatable. It is
23
+ // for generated or vendored code the project already excludes elsewhere -
24
+ // a migrations directory is the standing case - not for hiding `any`s.
25
+ //
26
+ // Usage:
27
+ // baseline-type-coverage # every workspace under the cwd
28
+ // baseline-type-coverage packages apps # only under these directories
29
+ // baseline-type-coverage --at-least 97 # freeze below the shared bar
30
+ // baseline-type-coverage --ignore-files 'migrations/**'
31
+ import { spawnSync } from 'node:child_process'
32
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
33
+ import { dirname, relative, resolve } from 'node:path'
34
+ import { argv, cwd, exit } from 'node:process'
35
+ import { fileURLToPath } from 'node:url'
36
+
37
+ const IGNORED_FILES = ['.next/**', '.nuxt/**', 'tests/**', '**/*.test.*']
38
+ const SKIPPED_DIRECTORIES = new Set([
39
+ 'node_modules',
40
+ 'dist',
41
+ 'build',
42
+ 'coverage',
43
+ 'target',
44
+ '.git',
45
+ '.next',
46
+ '.nuxt',
47
+ '.output',
48
+ '.astro',
49
+ ])
50
+ const MAX_DEPTH = 3
51
+
52
+ // This package's own source, resolved from this file's URL.
53
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
54
+ const thresholdSource = readFileSync(
55
+ fileURLToPath(new URL('../src/type-coverage.ts', import.meta.url)),
56
+ 'utf8',
57
+ )
58
+ const declared = /TYPE_COVERAGE_THRESHOLD\s*=\s*(\d+)/.exec(thresholdSource)
59
+ if (!declared?.[1]) {
60
+ console.error(
61
+ 'baseline-type-coverage: could not read TYPE_COVERAGE_THRESHOLD from ' +
62
+ 'src/type-coverage.ts. The constant moved or changed shape; this bin ' +
63
+ 'reads it from there so the two cannot drift.',
64
+ )
65
+ exit(1)
66
+ }
67
+ // A repo-local floor, when the project is still climbing toward the shared one.
68
+ const atLeastIndex = argv.indexOf('--at-least')
69
+ const override = atLeastIndex === -1 ? undefined : argv[atLeastIndex + 1]
70
+ if (atLeastIndex !== -1 && !/^\d+(?:\.\d+)?$/.test(override ?? '')) {
71
+ console.error(
72
+ 'baseline-type-coverage: --at-least needs a number, e.g. `--at-least 97`.',
73
+ )
74
+ exit(1)
75
+ }
76
+ if (override !== undefined && Number(override) > Number(declared[1])) {
77
+ console.error(
78
+ `baseline-type-coverage: --at-least ${override} is above the shared ` +
79
+ `threshold of ${declared[1]}. Drop the flag rather than restating it.`,
80
+ )
81
+ exit(1)
82
+ }
83
+ const threshold = override ?? declared[1]
84
+
85
+ // Extra exclusions for generated or vendored code the project already excludes
86
+ // elsewhere. Merged with the two built-in categories, never replacing them.
87
+ const extraIgnores = argv.reduce(
88
+ (globs, argument, index) =>
89
+ argv[index - 1] === '--ignore-files' ? [...globs, argument] : globs,
90
+ [],
91
+ )
92
+ if (argv.includes('--ignore-files') && !extraIgnores.length) {
93
+ console.error(
94
+ "baseline-type-coverage: --ignore-files needs a glob, e.g. `--ignore-files 'migrations/**'`.",
95
+ )
96
+ exit(1)
97
+ }
98
+
99
+ // A directory the repository's own .gitignore excludes is not this gate's to
100
+ // measure: it is generated or vendored, and the project already said so. Asked
101
+ // once for the whole candidate list rather than per directory. A repo without
102
+ // git, or a git that errors, simply excludes nothing.
103
+ function gitIgnored(directories) {
104
+ if (!directories.length) return new Set()
105
+ const result = spawnSync('git', ['check-ignore', '--stdin'], {
106
+ cwd: cwd(),
107
+ input: directories.join('\n'),
108
+ encoding: 'utf8',
109
+ })
110
+ if (result.error || result.status > 1) return new Set()
111
+ return new Set(
112
+ (result.stdout ?? '')
113
+ .split('\n')
114
+ .map((line) => line.trim())
115
+ .filter(Boolean),
116
+ )
117
+ }
118
+
119
+ // A solution-style tsconfig - `{"files": [], "references": [...]}` - contains
120
+ // no source of its own. type-coverage run against it measures 0 identifiers and
121
+ // exits 0, which reads as a passing gate over an entire repository. Follow the
122
+ // references instead, the way `tsc -b` does.
123
+ //
124
+ // Parsed with the comments and trailing commas tsconfig permits stripped out.
125
+ // A file this cannot parse is treated as an ordinary workspace rather than
126
+ // guessed at.
127
+ function referencedProjects(configPath) {
128
+ let parsed
129
+ try {
130
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
131
+ const raw = readFileSync(configPath, 'utf8')
132
+ .replaceAll(/\/\*[\s\S]*?\*\//g, '')
133
+ .replaceAll(/(^|[^:])\/\/.*$/gm, '$1')
134
+ .replaceAll(/,(\s*[}\]])/g, '$1')
135
+ parsed = JSON.parse(raw)
136
+ } catch {
137
+ return []
138
+ }
139
+ const declaresNoFiles =
140
+ Array.isArray(parsed.files) &&
141
+ parsed.files.length === 0 &&
142
+ parsed.include === undefined
143
+ if (!declaresNoFiles || !Array.isArray(parsed.references)) return []
144
+ return parsed.references
145
+ .map((reference) => reference?.path)
146
+ .filter((path) => typeof path === 'string')
147
+ .map((path) => resolve(dirname(configPath), path))
148
+ }
149
+
150
+ // A workspace is the directory type-coverage runs in plus, when the project is
151
+ // a referenced tsconfig rather than a directory's default one, the `-p` that
152
+ // aims it at that file. `tsc -b` resolves a reference to either a directory
153
+ // holding a tsconfig.json or the config file itself; both shapes appear.
154
+ function toWorkspace(referencePath) {
155
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
156
+ const isDirectory = existsSync(resolve(referencePath, 'tsconfig.json'))
157
+ return isDirectory
158
+ ? { directory: referencePath }
159
+ : { directory: dirname(referencePath), project: referencePath }
160
+ }
161
+
162
+ // Every path below is derived from the invoking project's own tree, which is
163
+ // the point of this tool - not untrusted input.
164
+ /* eslint-disable security/detect-non-literal-fs-filename */
165
+ function findWorkspaces(root, depth = 0) {
166
+ const found = []
167
+ const configPath = resolve(root, 'tsconfig.json')
168
+ if (existsSync(configPath)) {
169
+ const referenced = referencedProjects(configPath)
170
+ // A solution tsconfig contributes its referenced projects, not itself.
171
+ if (referenced.length) found.push(...referenced.map(toWorkspace))
172
+ else found.push({ directory: root })
173
+ }
174
+ if (depth >= MAX_DEPTH) return found
175
+
176
+ const children = readdirSync(root, { withFileTypes: true })
177
+ .filter(
178
+ (entry) => entry.isDirectory() && !SKIPPED_DIRECTORIES.has(entry.name),
179
+ )
180
+ .map((entry) => resolve(root, entry.name))
181
+ const ignored = gitIgnored(children.map((child) => relative(cwd(), child)))
182
+ for (const child of children) {
183
+ if (ignored.has(relative(cwd(), child))) continue
184
+ found.push(...findWorkspaces(child, depth + 1))
185
+ }
186
+ return found
187
+ }
188
+ /* eslint-enable security/detect-non-literal-fs-filename */
189
+
190
+ const roots = argv
191
+ .slice(2)
192
+ .filter((argument, index, all) => {
193
+ if (argument === '--at-least' || argument === '--ignore-files') return false
194
+ const previous = all[index - 1]
195
+ return previous !== '--at-least' && previous !== '--ignore-files'
196
+ })
197
+ .map((argument) => resolve(cwd(), argument))
198
+ const workspaces = (roots.length ? roots : [cwd()]).flatMap((root) =>
199
+ findWorkspaces(root),
200
+ )
201
+
202
+ if (!workspaces.length) {
203
+ console.error(
204
+ 'baseline-type-coverage: no workspace with a tsconfig.json found. Pass the ' +
205
+ 'directories to search, e.g. `baseline-type-coverage packages apps`.',
206
+ )
207
+ exit(1)
208
+ }
209
+
210
+ let failed = false
211
+ for (const workspace of workspaces) {
212
+ const label = relative(cwd(), workspace.project ?? workspace.directory) || '.'
213
+ const result = spawnSync(
214
+ 'pnpm',
215
+ [
216
+ 'exec',
217
+ 'type-coverage',
218
+ '--strict',
219
+ '--at-least',
220
+ threshold,
221
+ ...(workspace.project ? ['-p', workspace.project] : []),
222
+ ...[...IGNORED_FILES, ...extraIgnores].flatMap((glob) => [
223
+ '--ignore-files',
224
+ glob,
225
+ ]),
226
+ ],
227
+ { cwd: workspace.directory, encoding: 'utf8' },
228
+ )
229
+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim()
230
+ if (result.status === 0) {
231
+ console.log(
232
+ `type-coverage: ok ${label} ${output.split('\n').at(-2) ?? output}`,
233
+ )
234
+ continue
235
+ }
236
+ failed = true
237
+ console.error(`type-coverage: FAIL ${label}`)
238
+ console.error(output)
239
+ }
240
+
241
+ if (failed) {
242
+ console.error(
243
+ `\nEvery workspace must reach ${threshold}% non-\`any\` coverage` +
244
+ (override === undefined
245
+ ? '.\n'
246
+ : ` (this project's own floor; the shared bar is ${declared[1]}%).\n`) +
247
+ 'Run `pnpm exec type-coverage --strict --detail` in the failing workspace to see where.',
248
+ )
249
+ exit(1)
250
+ }
251
+ console.log(
252
+ `type-coverage: every workspace is at or above ${threshold}% (${workspaces.length} checked).`,
253
+ )
package/jscpd.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "minTokens": 70,
3
+ "threshold": 1,
4
+ "format": ["typescript", "tsx", "javascript", "jsx", "vue", "astro", "rust"],
5
+ "gitignore": true,
6
+ "ignore": [
7
+ "**/node_modules/**",
8
+ "**/dist/**",
9
+ "**/.next/**",
10
+ "**/.output/**",
11
+ "**/target/**",
12
+ "**/coverage/**"
13
+ ],
14
+ "reporters": ["console"]
15
+ }
package/oxlintrc.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
3
+ "categories": {
4
+ "correctness": "deny"
5
+ },
6
+ "ignorePatterns": [
7
+ "**/node_modules/**",
8
+ "**/dist/**",
9
+ "**/build/**",
10
+ "**/coverage/**",
11
+ "**/.next/**",
12
+ "**/.astro/**",
13
+ "**/.nuxt/**",
14
+ "**/.output/**",
15
+ "**/out/**",
16
+ "**/.stryker-tmp/**",
17
+ "**/reports/**"
18
+ ]
19
+ }
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@syntopica/quality-config",
3
+ "version": "0.11.0",
4
+ "private": false,
5
+ "packageManager": "pnpm@11.25.0",
6
+ "license": "MIT",
7
+ "description": "Shared configuration for cross-file quality gates: knip, dependency-cruiser, type-coverage, jscpd, lefthook",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/BusiRocket/baseline.git",
11
+ "directory": "packages/quality-config"
12
+ },
13
+ "homepage": "https://github.com/BusiRocket/baseline/tree/main/packages/quality-config#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/BusiRocket/baseline/issues"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "type": "module",
21
+ "engines": {
22
+ "node": ">=22"
23
+ },
24
+ "bin": {
25
+ "baseline-audit": "bin/baseline-audit.mjs",
26
+ "baseline-deps-graph": "bin/baseline-deps-graph.mjs",
27
+ "baseline-dupes": "bin/baseline-dupes.mjs",
28
+ "baseline-env-init": "bin/baseline-env-init.mjs",
29
+ "baseline-licenses": "bin/baseline-licenses.mjs",
30
+ "baseline-type-coverage": "bin/baseline-type-coverage.mjs"
31
+ },
32
+ "files": [
33
+ "LICENSE",
34
+ "PUBLIC_API.md",
35
+ "README.md",
36
+ "bin",
37
+ "jscpd.json",
38
+ "oxlintrc.json",
39
+ "src",
40
+ "tsconfig.json"
41
+ ],
42
+ "exports": {
43
+ ".": "./src/index.ts",
44
+ "./knip": "./src/knip.ts",
45
+ "./dependency-cruiser": "./src/dependency-cruiser.ts",
46
+ "./type-coverage": "./src/type-coverage.ts",
47
+ "./lefthook": "./src/lefthook.ts",
48
+ "./jscpd": "./jscpd.json",
49
+ "./commitlint": "./src/commitlint.ts",
50
+ "./oxlint": "./oxlintrc.json"
51
+ },
52
+ "scripts": {
53
+ "fix": "pnpm run lint:fix",
54
+ "lint": "eslint src bin --max-warnings 0",
55
+ "lint:fix": "eslint src bin --fix",
56
+ "lint:suppress": "eslint src bin --suppress-all",
57
+ "lint:prune": "eslint src bin --prune-suppressions",
58
+ "type-check": "tsc --noEmit -p tsconfig.json",
59
+ "publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
60
+ },
61
+ "peerDependencies": {
62
+ "@commitlint/config-conventional": ">=21.0.0",
63
+ "dependency-cruiser": ">=18.0.0",
64
+ "knip": ">=6.0.0",
65
+ "oxlint": ">=1.0.0",
66
+ "typescript": ">=5.4.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "dependency-cruiser": {
70
+ "optional": true
71
+ },
72
+ "knip": {
73
+ "optional": true
74
+ },
75
+ "@commitlint/config-conventional": {
76
+ "optional": true
77
+ },
78
+ "oxlint": {
79
+ "optional": true
80
+ }
81
+ },
82
+ "devDependencies": {
83
+ "@arethetypeswrong/cli": "^0.18.5",
84
+ "@syntopica/eslint-config": "workspace:*",
85
+ "@types/node": "^26.4.0",
86
+ "dependency-cruiser": "^18.2.0",
87
+ "eslint": "^10.9.1",
88
+ "eslint-plugin-regexp": "^3.2.0",
89
+ "knip": "^6.33.0",
90
+ "publint": "^0.3.24",
91
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
92
+ }
93
+ }
@@ -0,0 +1,49 @@
1
+ /** Shape of a commitlint configuration document. */
2
+ type CommitlintConfig = Record<string, unknown>
3
+
4
+ /**
5
+ * Conventional-commit rules for the `commit-msg` hook.
6
+ *
7
+ * The release process already depends on this convention: `brp-release`
8
+ * derives the semver bump and the changelog from the commit subjects, so a
9
+ * subject typed `feature:` instead of `feat:` silently drops a change out of
10
+ * the release notes and can flip a minor into a patch. Nothing verified it -
11
+ * the convention was upheld by hand, in the one place where a typo is
12
+ * invisible until the release is already cut.
13
+ *
14
+ * Deliberately not the full `config-conventional` preset. Two of its rules
15
+ * fight the way commits are actually written here:
16
+ *
17
+ * - `body-max-line-length` at 100 rejects a pasted stack trace or a URL,
18
+ * which is exactly the context worth keeping in a commit body.
19
+ * - `subject-case` forbids a subject starting with an identifier that is
20
+ * capitalised in the code (`TypeScript`, `ESLint`, `GitHub`).
21
+ *
22
+ * `type-enum` is the load-bearing rule and it is an error: it is the field the
23
+ * release tooling reads.
24
+ */
25
+ export const createCommitlintConfig = (): CommitlintConfig => ({
26
+ extends: ['@commitlint/config-conventional'],
27
+ rules: {
28
+ 'type-enum': [
29
+ 2,
30
+ 'always',
31
+ [
32
+ 'feat',
33
+ 'fix',
34
+ 'docs',
35
+ 'style',
36
+ 'refactor',
37
+ 'perf',
38
+ 'test',
39
+ 'build',
40
+ 'ci',
41
+ 'chore',
42
+ 'revert',
43
+ ],
44
+ ],
45
+ 'subject-case': [0],
46
+ 'body-max-line-length': [0],
47
+ 'footer-max-line-length': [0],
48
+ },
49
+ })