@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.
- package/LICENSE +21 -0
- package/PUBLIC_API.md +93 -0
- package/README.md +102 -0
- package/bin/baseline-audit.mjs +145 -0
- package/bin/baseline-deps-graph.mjs +102 -0
- package/bin/baseline-dupes.mjs +121 -0
- package/bin/baseline-env-init.mjs +38 -0
- package/bin/baseline-licenses.mjs +186 -0
- package/bin/baseline-type-coverage.mjs +253 -0
- package/jscpd.json +15 -0
- package/oxlintrc.json +19 -0
- package/package.json +93 -0
- package/src/commitlint.ts +49 -0
- package/src/dependency-cruiser.ts +146 -0
- package/src/index.ts +5 -0
- package/src/knip-framework.ts +84 -0
- package/src/knip.ts +162 -0
- package/src/lefthook.ts +53 -0
- package/src/type-coverage.ts +2 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { IConfiguration, IForbiddenRuleType } from 'dependency-cruiser'
|
|
2
|
+
|
|
3
|
+
// Next.js App Router file conventions. Next loads each of these by filename at
|
|
4
|
+
// build or request time, so nothing imports them and having no importer is
|
|
5
|
+
// their normal state rather than a defect.
|
|
6
|
+
const NEXT_FILE_CONVENTIONS =
|
|
7
|
+
'page|layout|loading|error|global-error|not-found|template|default|route|sitemap|robots|manifest|icon|apple-icon|opengraph-image|twitter-image'
|
|
8
|
+
|
|
9
|
+
// Orphan exemptions that hold at either scope. Every pattern is anchored on a
|
|
10
|
+
// path segment rather than the repo root, so it matches whether the cruise runs
|
|
11
|
+
// from the repo root or from inside a single workspace.
|
|
12
|
+
//
|
|
13
|
+
// **Every pattern here goes through safe-regex, and a single rejection disables
|
|
14
|
+
// the whole rule.** dependency-cruiser reports
|
|
15
|
+
// `rule ... has an unsafe regular expression. Bailing out.` and stops checking
|
|
16
|
+
// orphans altogether - it does not skip the offending pattern and keep the
|
|
17
|
+
// rest, so a careless addition turns the gate off while still exiting 0 on a
|
|
18
|
+
// clean tree. Nested quantifiers are what trip it: `(^|/)app/(.*/)?(page)\.tsx$`
|
|
19
|
+
// is rejected for the `(.*/)?` group, which is why the two Next patterns below
|
|
20
|
+
// are split into a direct-child form and a nested form instead of using one
|
|
21
|
+
// optional-directory group.
|
|
22
|
+
const ORPHAN_EXEMPTIONS = [
|
|
23
|
+
'(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$',
|
|
24
|
+
'\\.d\\.ts$',
|
|
25
|
+
'(^|/)tsconfig\\.json$',
|
|
26
|
+
// Framework/tooling config files: loaded directly by that tool's own
|
|
27
|
+
// runtime, never imported by application code. Being an orphan in the module
|
|
28
|
+
// graph is their normal state, not a defect.
|
|
29
|
+
'(^|/)(babel|webpack|vite|vitest|eslint|knip|prettier|tsup|astro|next|nuxt|commitlint|stryker|lighthouse)\\.config\\.(js|cjs|mjs|ts)$',
|
|
30
|
+
// Next.js App Router file conventions, in two forms: directly under `app/`,
|
|
31
|
+
// and nested at any depth below it. The nested one requires the trailing
|
|
32
|
+
// slash so that `app/blog/mypage.tsx` is not read as a `page.tsx`.
|
|
33
|
+
`(^|/)app/(${NEXT_FILE_CONVENTIONS})\\.tsx?$`,
|
|
34
|
+
`(^|/)app/.*/(${NEXT_FILE_CONVENTIONS})\\.tsx?$`,
|
|
35
|
+
// Next 16 renamed `middleware.ts` to `proxy.ts`; both are loaded by the same
|
|
36
|
+
// filename convention, and a project has one or the other. The `(^|/)` prefix
|
|
37
|
+
// covers `src/proxy.ts` as well as a root-level one.
|
|
38
|
+
'(^|/)(middleware|proxy)\\.ts$',
|
|
39
|
+
// Nuxt file-convention entry points: app.vue is the framework's root
|
|
40
|
+
// component and everything under pages/ is resolved by Nuxt's file-based
|
|
41
|
+
// router. Both are loaded directly by Nuxt's build/runtime, not by any
|
|
42
|
+
// application import (verified with `depcruise --output-type json`: zero
|
|
43
|
+
// dependencies AND zero dependents), so having no importer is their normal
|
|
44
|
+
// state.
|
|
45
|
+
'(^|/)app/(app\\.vue$|pages/)',
|
|
46
|
+
// ESLint rule test fixtures: read from disk by filename in RuleTester cases,
|
|
47
|
+
// never imported as real modules. Being unreferenced in the graph is their
|
|
48
|
+
// intended state.
|
|
49
|
+
'(^|/)tests/fixtures/',
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
// Rules that need the whole resolved graph and cannot be split per workspace:
|
|
53
|
+
// a cycle or a packages -> templates edge can span two workspaces, and
|
|
54
|
+
// `no-dev-dep-in-production-code` matches on a repo-relative path prefix.
|
|
55
|
+
const REPO_SCOPE_RULES: IForbiddenRuleType[] = [
|
|
56
|
+
{
|
|
57
|
+
name: 'no-circular',
|
|
58
|
+
severity: 'error',
|
|
59
|
+
comment:
|
|
60
|
+
'Cycles make modules impossible to reason about or test in isolation.',
|
|
61
|
+
from: {},
|
|
62
|
+
to: { circular: true },
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'packages-must-not-depend-on-templates',
|
|
66
|
+
severity: 'error',
|
|
67
|
+
comment:
|
|
68
|
+
'Templates are scaffolding output. A shared package reaching into one inverts the dependency.',
|
|
69
|
+
from: { path: '^packages/' },
|
|
70
|
+
to: { path: '^templates/' },
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'no-dev-dep-in-production-code',
|
|
74
|
+
severity: 'warn',
|
|
75
|
+
comment:
|
|
76
|
+
'A devDependency imported by shipped code will be missing at runtime for consumers.',
|
|
77
|
+
from: { path: '^packages/[^/]+/src/', pathNot: '\\.(test|spec)\\.ts$' },
|
|
78
|
+
to: { dependencyTypes: ['npm-dev'] },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'no-deprecated-core',
|
|
82
|
+
severity: 'error',
|
|
83
|
+
comment: 'Deprecated Node core modules are removed in future majors.',
|
|
84
|
+
from: {},
|
|
85
|
+
to: { dependencyTypes: ['core'], path: '^(punycode|domain|sys)$' },
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Graph-level architecture rules. Complements ESLint: `import/no-cycle` runs
|
|
91
|
+
* per file and cannot resolve across package boundaries, while this runs over
|
|
92
|
+
* the whole resolved module graph.
|
|
93
|
+
*
|
|
94
|
+
* `scope: 'repo'` (the default) cruises the whole repository and owns every
|
|
95
|
+
* rule that needs the full graph. `scope: 'workspace'` cruises one workspace
|
|
96
|
+
* and owns only the orphan check, the one rule whose correctness depends on
|
|
97
|
+
* alias resolution.
|
|
98
|
+
*
|
|
99
|
+
* A workspace-scoped cruise needs a `--ts-config` whose `paths` are written
|
|
100
|
+
* relative to the workspace root: dependency-cruiser resolves them against the
|
|
101
|
+
* current working directory rather than against the config file that declares
|
|
102
|
+
* them, so a config that lives one directory down (a framework-generated one,
|
|
103
|
+
* for instance) mis-resolves every alias.
|
|
104
|
+
*
|
|
105
|
+
* `orphanExemptions` adds project-specific `no-orphans` exemptions on top of
|
|
106
|
+
* the framework-convention ones built in here. Use it for directories a
|
|
107
|
+
* repo-wide run cannot judge - typically a workspace whose path aliases only
|
|
108
|
+
* resolve under its own tsconfig, cruised separately at `scope: 'workspace'`.
|
|
109
|
+
*/
|
|
110
|
+
export const createDepCruiserConfig = (
|
|
111
|
+
options: {
|
|
112
|
+
tsConfigPath?: string
|
|
113
|
+
scope?: 'repo' | 'workspace'
|
|
114
|
+
orphanExemptions?: string[]
|
|
115
|
+
} = {},
|
|
116
|
+
): IConfiguration => ({
|
|
117
|
+
forbidden: [
|
|
118
|
+
{
|
|
119
|
+
name: 'no-orphans',
|
|
120
|
+
severity: 'error',
|
|
121
|
+
comment:
|
|
122
|
+
'A module nothing imports and that is not an entry point is dead weight.',
|
|
123
|
+
from: {
|
|
124
|
+
orphan: true,
|
|
125
|
+
pathNot: [...ORPHAN_EXEMPTIONS, ...(options.orphanExemptions ?? [])],
|
|
126
|
+
},
|
|
127
|
+
to: {},
|
|
128
|
+
},
|
|
129
|
+
...(options.scope === 'workspace' ? [] : REPO_SCOPE_RULES),
|
|
130
|
+
],
|
|
131
|
+
options: {
|
|
132
|
+
doNotFollow: { path: 'node_modules' },
|
|
133
|
+
exclude: {
|
|
134
|
+
path: '(^|/)(dist|coverage|\\.next|\\.nuxt|\\.output|\\.astro|target)/',
|
|
135
|
+
},
|
|
136
|
+
tsPreCompilationDeps: true,
|
|
137
|
+
tsConfig: options.tsConfigPath
|
|
138
|
+
? { fileName: options.tsConfigPath }
|
|
139
|
+
: undefined,
|
|
140
|
+
enhancedResolveOptions: {
|
|
141
|
+
exportsFields: ['exports'],
|
|
142
|
+
conditionNames: ['import', 'require', 'node', 'default', 'types'],
|
|
143
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.vue'],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
})
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createCommitlintConfig } from './commitlint'
|
|
2
|
+
export { createDepCruiserConfig } from './dependency-cruiser'
|
|
3
|
+
export { createKnipConfig } from './knip'
|
|
4
|
+
export { createLefthookConfig } from './lefthook'
|
|
5
|
+
export { TYPE_COVERAGE_THRESHOLD } from './type-coverage'
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Entry and project globs per template framework, consumed by createKnipConfig. */
|
|
2
|
+
export type KnipFramework =
|
|
3
|
+
| 'astro'
|
|
4
|
+
| 'nestjs'
|
|
5
|
+
| 'nextjs'
|
|
6
|
+
| 'nuxt'
|
|
7
|
+
| 'tanstack-start'
|
|
8
|
+
| 'tauri'
|
|
9
|
+
| 'ts-package'
|
|
10
|
+
| 'vite-react'
|
|
11
|
+
| 'vite-vue'
|
|
12
|
+
|
|
13
|
+
export const FRAMEWORK_ENTRIES: Record<
|
|
14
|
+
KnipFramework,
|
|
15
|
+
{ entry: string[]; project: string[] }
|
|
16
|
+
> = {
|
|
17
|
+
astro: {
|
|
18
|
+
entry: ['src/pages/**/*.{astro,ts,tsx}', 'astro.config.*'],
|
|
19
|
+
project: ['src/**/*.{astro,ts,tsx}'],
|
|
20
|
+
},
|
|
21
|
+
nestjs: {
|
|
22
|
+
entry: ['src/main.ts', 'src/**/*.module.ts'],
|
|
23
|
+
project: ['src/**/*.ts'],
|
|
24
|
+
},
|
|
25
|
+
// The App Router lives at either `app/` or `src/app/`, and the proxy follows
|
|
26
|
+
// it. `{,src/}` matches both in one pattern, so neither layout produces a
|
|
27
|
+
// "Refine entry pattern (no matches)" hint. Root-only entries silently
|
|
28
|
+
// misread a `src/app` project: every route file falls outside the entry set
|
|
29
|
+
// and knip reports the whole app as unused files while never checking a
|
|
30
|
+
// single export. `next.config.*` stays root-only - Next.js requires it there.
|
|
31
|
+
//
|
|
32
|
+
// Every file convention belongs in the one brace alternation rather than in a
|
|
33
|
+
// pattern of its own, including the metadata routes (`sitemap`, `robots`,
|
|
34
|
+
// `manifest`, the image generators): a pattern matching nothing is a hint, and
|
|
35
|
+
// no project uses all of them. `middleware` and `proxy` share a pattern for
|
|
36
|
+
// the same reason - Next 16 renamed the file, and a project has one or the
|
|
37
|
+
// other, never both.
|
|
38
|
+
nextjs: {
|
|
39
|
+
entry: [
|
|
40
|
+
'{,src/}app/**/{page,layout,loading,error,global-error,not-found,route,template,default,sitemap,robots,manifest,icon,apple-icon,opengraph-image,twitter-image}.{ts,tsx}',
|
|
41
|
+
'next.config.*',
|
|
42
|
+
'{,src/}{middleware,proxy}.ts',
|
|
43
|
+
],
|
|
44
|
+
project: ['{,src/}app/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
|
|
45
|
+
},
|
|
46
|
+
nuxt: {
|
|
47
|
+
entry: ['app/**/*.vue', 'server/**/*.ts', 'nuxt.config.*'],
|
|
48
|
+
project: ['app/**/*.{ts,vue}', 'server/**/*.ts'],
|
|
49
|
+
},
|
|
50
|
+
// TanStack Start has no index.html and no src/main.tsx: the router is the
|
|
51
|
+
// root of the graph and the framework generates routeTree.gen.ts from the
|
|
52
|
+
// file-based routes. `src/{server,start,client}.{ts,tsx}` covers the
|
|
53
|
+
// server entry across the versions that renamed it - a project has one or
|
|
54
|
+
// two of them, and the brace alternation keeps the ones it lacks from
|
|
55
|
+
// becoming "Refine entry pattern" hints.
|
|
56
|
+
'tanstack-start': {
|
|
57
|
+
entry: [
|
|
58
|
+
'src/router.{ts,tsx}',
|
|
59
|
+
'src/routes/**/*.{ts,tsx}',
|
|
60
|
+
'src/{server,start,client}.{ts,tsx}',
|
|
61
|
+
'vite.config.*',
|
|
62
|
+
],
|
|
63
|
+
project: ['src/**/*.{ts,tsx}'],
|
|
64
|
+
},
|
|
65
|
+
tauri: {
|
|
66
|
+
// The scaffolded tauri-app frontend is React, so its entry is
|
|
67
|
+
// src/main.tsx, not src/main.ts; keep both extensions so a plain-TS
|
|
68
|
+
// Tauri frontend also matches.
|
|
69
|
+
entry: ['src/main.{ts,tsx}', 'vite.config.*'],
|
|
70
|
+
project: ['src/**/*.{ts,tsx}'],
|
|
71
|
+
},
|
|
72
|
+
'ts-package': {
|
|
73
|
+
entry: ['src/index.ts'],
|
|
74
|
+
project: ['src/**/*.ts'],
|
|
75
|
+
},
|
|
76
|
+
'vite-react': {
|
|
77
|
+
entry: ['src/main.tsx', 'index.html', 'vite.config.*'],
|
|
78
|
+
project: ['src/**/*.{ts,tsx}'],
|
|
79
|
+
},
|
|
80
|
+
'vite-vue': {
|
|
81
|
+
entry: ['src/main.ts', 'index.html', 'vite.config.*'],
|
|
82
|
+
project: ['src/**/*.{ts,vue}'],
|
|
83
|
+
},
|
|
84
|
+
}
|
package/src/knip.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// `KnipConfiguration`, not `KnipConfig`: the latter is a union that also
|
|
2
|
+
// admits a function, so a consumer spreading this factory's result to override
|
|
3
|
+
// one rule gets "Property 'rules' does not exist on type
|
|
4
|
+
// 'RawConfigurationOrFn'". Returning the object shape lets a project extend the
|
|
5
|
+
// config without casting it first.
|
|
6
|
+
import type { KnipConfiguration } from 'knip'
|
|
7
|
+
|
|
8
|
+
import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
9
|
+
|
|
10
|
+
// Every template installs these as peer dependencies of
|
|
11
|
+
// @syntopica/eslint-config: the config factories (base.ts and friends)
|
|
12
|
+
// `import` them by bare specifier, and pnpm's isolated node_modules needs
|
|
13
|
+
// each consumer to declare them directly for that import to resolve. No
|
|
14
|
+
// template file ever imports these packages itself (they only import from
|
|
15
|
+
// '@syntopica/eslint-config/*'), so knip can't see the real caller and
|
|
16
|
+
// reports them as unused. Mirrors the same list and rationale in the
|
|
17
|
+
// repo-root knip.config.ts for the `templates/*` workspace.
|
|
18
|
+
//
|
|
19
|
+
// Two packages that used to sit here - `@vitest/eslint-plugin` and
|
|
20
|
+
// `eslint-plugin-testing-library` - were removed on 2026-08-24: knip resolved
|
|
21
|
+
// the real caller in all eight templates, so the entries were redundant
|
|
22
|
+
// everywhere and produced a hint no consumer could silence. The rest stay:
|
|
23
|
+
// `eslint-config-prettier` is redundant in four of the eight and load-bearing
|
|
24
|
+
// in the other four, which is exactly the case the list exists for. A consumer
|
|
25
|
+
// whose layout hides a caller can add its own entries through
|
|
26
|
+
// `ignoreDependencies`, which merges with this list rather than replacing it.
|
|
27
|
+
//
|
|
28
|
+
// Where an entry here IS redundant, knip says so:
|
|
29
|
+
// `<package> knip.config.ts Remove from ignoreDependencies`. That is a hint,
|
|
30
|
+
// not a gate failure. Do not filter the list consumer-side to silence it: the
|
|
31
|
+
// filter would drift the moment this list changes, and the cost of being wrong
|
|
32
|
+
// is a dependency that silently stops being checked.
|
|
33
|
+
// The tools this package's own runners spawn through `pnpm exec`:
|
|
34
|
+
// `baseline-dupes` spawns `jscpd`, `baseline-type-coverage` spawns
|
|
35
|
+
// `type-coverage`, `baseline-deps-graph` spawns `depcruise`. A project that
|
|
36
|
+
// wires the runner into its scripts never names the underlying tool anywhere
|
|
37
|
+
// knip can see, so knip reports a real dependency as unused. Found in
|
|
38
|
+
// busirocket the moment its `type-coverage` script became
|
|
39
|
+
// `baseline-type-coverage`.
|
|
40
|
+
//
|
|
41
|
+
// `dependency-cruiser` is on the list even though a project calling
|
|
42
|
+
// `depcruise` directly resolves it fine: there knip emits a `Remove from
|
|
43
|
+
// ignoreDependencies` hint, which is a hint and not a gate failure, and the
|
|
44
|
+
// cost of leaving it off is a real dependency silently reported as dead.
|
|
45
|
+
const BASELINE_RUNNER_DEPENDENCIES = [
|
|
46
|
+
'jscpd',
|
|
47
|
+
'type-coverage',
|
|
48
|
+
'dependency-cruiser',
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
const ESLINT_PEER_DEPENDENCIES = [
|
|
52
|
+
'@eslint/js',
|
|
53
|
+
'eslint-config-prettier',
|
|
54
|
+
'eslint-plugin-promise',
|
|
55
|
+
'eslint-plugin-security',
|
|
56
|
+
'eslint-plugin-unused-imports',
|
|
57
|
+
'typescript-eslint',
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Knip configuration for a baseline template.
|
|
62
|
+
*
|
|
63
|
+
* Rules that block: unused files, unused exports and exported types, declared
|
|
64
|
+
* dependencies nobody imports, and imports of undeclared dependencies. Those
|
|
65
|
+
* are the four findings a reviewer cannot see in a diff.
|
|
66
|
+
*
|
|
67
|
+
* `binaries` and `unresolved` stay non-blocking: pnpm script indirection and
|
|
68
|
+
* Turbo produce false positives on both.
|
|
69
|
+
*/
|
|
70
|
+
export const createKnipConfig = (options: {
|
|
71
|
+
framework: KnipFramework
|
|
72
|
+
/**
|
|
73
|
+
* Binaries knip cannot resolve. Nothing is ignored by default: an entry for
|
|
74
|
+
* a binary knip *can* resolve becomes a permanent `Remove from
|
|
75
|
+
* ignoreBinaries` hint the consumer has no way to silence.
|
|
76
|
+
*/
|
|
77
|
+
ignoreBinaries?: string[]
|
|
78
|
+
/** Merged with the built-in lists, never replacing them. */
|
|
79
|
+
ignoreDependencies?: string[]
|
|
80
|
+
/**
|
|
81
|
+
* Files knip must not analyse at all. The standing case is a drizzle schema
|
|
82
|
+
* aggregator: `drizzle.config.ts` names one file as THE schema, so every
|
|
83
|
+
* table it exports is live even though no TypeScript file imports it, and
|
|
84
|
+
* acting on the resulting "unused export" report makes the next generated
|
|
85
|
+
* migration emit `DROP TABLE`.
|
|
86
|
+
*/
|
|
87
|
+
ignore?: string[]
|
|
88
|
+
/**
|
|
89
|
+
* Extra source globs, merged with the framework preset's `project`.
|
|
90
|
+
*
|
|
91
|
+
* Every preset assumes the framework's own layout - for Next.js, `src/` and
|
|
92
|
+
* `app/`. An app whose code sits at the repo root (`components/`, `hooks/`,
|
|
93
|
+
* `services/`, ...) is invisible to knip under that preset, and every
|
|
94
|
+
* dependency reached only from there reports as unused. This is a merge, not
|
|
95
|
+
* a replacement: the preset's globs stay, so a project cannot silently opt
|
|
96
|
+
* out of scanning the directories the framework does own.
|
|
97
|
+
*/
|
|
98
|
+
project?: string[]
|
|
99
|
+
/**
|
|
100
|
+
* Extra entry globs, merged with the framework preset's `entry`. Same
|
|
101
|
+
* reasoning as `project`, for a root nobody's plugin registers - a worker,
|
|
102
|
+
* a CLI, a script the app spawns.
|
|
103
|
+
*/
|
|
104
|
+
entry?: string[]
|
|
105
|
+
/**
|
|
106
|
+
* Set `false` for a package that is finished but not wired up yet. With the
|
|
107
|
+
* default `true` its entire public API reports as unused exports, and the
|
|
108
|
+
* obvious reading of that report is "delete this package".
|
|
109
|
+
*/
|
|
110
|
+
includeEntryExports?: boolean
|
|
111
|
+
/**
|
|
112
|
+
* Set `false` to stop knip loading `drizzle.config.ts`. That file throws by
|
|
113
|
+
* design when `DATABASE_URL` is unset, so the gate otherwise needs a live
|
|
114
|
+
* database in CI. Adding the file to `ignore` does not stop the plugin -
|
|
115
|
+
* only this does.
|
|
116
|
+
*/
|
|
117
|
+
drizzle?: false
|
|
118
|
+
}): KnipConfiguration => {
|
|
119
|
+
const { entry, project } = FRAMEWORK_ENTRIES[options.framework]
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
entry: [...entry, ...(options.entry ?? [])],
|
|
123
|
+
project: [...project, ...(options.project ?? [])],
|
|
124
|
+
...(options.ignore ? { ignore: options.ignore } : {}),
|
|
125
|
+
...(options.drizzle === false ? { drizzle: false } : {}),
|
|
126
|
+
// Without this, exports of entry files are never checked, so a dead export
|
|
127
|
+
// added to main.ts / index.ts would pass the gate. Coverage is real but
|
|
128
|
+
// partial: verified with a probe export that it now fails `nestjs-app`
|
|
129
|
+
// (src/main.ts) and `ts-package` (src/index.ts), and that it still does not
|
|
130
|
+
// fail `nextjs-app` (app/page.tsx), `vite-react-app` (src/main.tsx) or
|
|
131
|
+
// `vue-app` (src/main.ts) - files a knip framework plugin registers as an
|
|
132
|
+
// entry of its own, which the option does not reach.
|
|
133
|
+
includeEntryExports: options.includeEntryExports ?? true,
|
|
134
|
+
// The Primary Unit Rule (code-policy/no-hidden-top-level-declarations)
|
|
135
|
+
// forbids a hidden top-level declaration, so a helper an entry file uses
|
|
136
|
+
// only itself still has to be exported - NestJS's `bootstrap`, called by
|
|
137
|
+
// `void bootstrap()` one line below its own definition, is the standing
|
|
138
|
+
// example. The per-type form (`{ function, variable, ... }`) does not
|
|
139
|
+
// exempt it - knip classifies `export const bootstrap = async () => {}`
|
|
140
|
+
// under none of the seven keys the schema accepts - so this is the global
|
|
141
|
+
// boolean. It only hides an export that its own file already uses: an
|
|
142
|
+
// export nothing references at all still fails the gate.
|
|
143
|
+
ignoreExportsUsedInFile: true,
|
|
144
|
+
ignoreBinaries: options.ignoreBinaries ?? [],
|
|
145
|
+
ignoreDependencies: [
|
|
146
|
+
...BASELINE_RUNNER_DEPENDENCIES,
|
|
147
|
+
...ESLINT_PEER_DEPENDENCIES,
|
|
148
|
+
...(options.ignoreDependencies ?? []),
|
|
149
|
+
],
|
|
150
|
+
rules: {
|
|
151
|
+
files: 'error',
|
|
152
|
+
dependencies: 'error',
|
|
153
|
+
devDependencies: 'error',
|
|
154
|
+
unlisted: 'error',
|
|
155
|
+
exports: 'error',
|
|
156
|
+
types: 'error',
|
|
157
|
+
duplicates: 'error',
|
|
158
|
+
binaries: 'warn',
|
|
159
|
+
unresolved: 'warn',
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/lefthook.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Shape of a lefthook.yml configuration document. */
|
|
2
|
+
type LefthookConfig = Record<string, unknown>
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Git hook configuration.
|
|
6
|
+
*
|
|
7
|
+
* pre-commit is limited to staged files and skips type-check and tests
|
|
8
|
+
* deliberately: CI already covers both, and a hook that takes 40 seconds gets
|
|
9
|
+
* disabled within a week.
|
|
10
|
+
*
|
|
11
|
+
* lefthook reads YAML, not TypeScript, so this factory is not consumed
|
|
12
|
+
* directly by lefthook itself. It mirrors the root and per-template
|
|
13
|
+
* `lefthook.yml` files by hand — see the comment at the top of those files —
|
|
14
|
+
* and is what create-baseline uses to generate `lefthook.yml` for new
|
|
15
|
+
* projects it scaffolds.
|
|
16
|
+
*/
|
|
17
|
+
export const createLefthookConfig = (): LefthookConfig => ({
|
|
18
|
+
'pre-commit': {
|
|
19
|
+
parallel: true,
|
|
20
|
+
commands: {
|
|
21
|
+
'lint:fast': {
|
|
22
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
|
|
23
|
+
run: 'pnpm exec oxlint --deny-warnings {staged_files}',
|
|
24
|
+
},
|
|
25
|
+
lint: {
|
|
26
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
|
|
27
|
+
run: 'pnpm exec eslint --max-warnings 0 --no-warn-ignored {staged_files}',
|
|
28
|
+
},
|
|
29
|
+
format: {
|
|
30
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}',
|
|
31
|
+
run: 'pnpm exec prettier --check {staged_files}',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// The release tooling reads the commit type to pick the semver bump and to
|
|
36
|
+
// build the changelog, so a mistyped subject is a silent release defect.
|
|
37
|
+
// This is the only place it can be caught: by the time the tag is cut the
|
|
38
|
+
// message is already history.
|
|
39
|
+
'commit-msg': {
|
|
40
|
+
commands: {
|
|
41
|
+
commitlint: {
|
|
42
|
+
run: 'pnpm exec commitlint --edit {1}',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
'pre-push': {
|
|
47
|
+
commands: {
|
|
48
|
+
secrets: {
|
|
49
|
+
run: 'gitleaks detect --no-banner --redact',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024"],
|
|
5
|
+
"strict": true,
|
|
6
|
+
"noEmit": true,
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"types": ["node"],
|
|
14
|
+
"allowImportingTsExtensions": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts", "eslint.config.ts"]
|
|
17
|
+
}
|