@syntopica/quality-config 0.13.2 → 0.15.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/README.md +31 -1
- package/jscpd.json +17 -2
- package/package.json +7 -3
- package/src/FRAMEWORK_RUNTIME_PACKAGES.ts +14 -0
- package/src/PRODUCTION_PROJECT_EXCLUSIONS.ts +12 -0
- package/src/dependency-cruiser.ts +7 -0
- package/src/existingEntries.ts +9 -5
- package/src/knip-framework.ts +31 -20
- package/src/knip.ts +30 -36
- package/src/matchedPresetPatterns.ts +13 -0
- package/src/moduleBoundaryRules.ts +22 -0
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ files/exports/dependencies (knip), module boundaries and dependency cycles
|
|
|
19
19
|
## Install
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
pnpm add -D @syntopica/quality-config
|
|
22
|
+
pnpm add -D @syntopica/quality-config typescript
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Add `knip` and/or `dependency-cruiser` for the gates you use.
|
|
@@ -34,6 +34,36 @@ Add `knip` and/or `dependency-cruiser` for the gates you use.
|
|
|
34
34
|
| `@syntopica/quality-config/type-coverage` | Minimum non-`any` type coverage threshold |
|
|
35
35
|
| `@syntopica/quality-config/lefthook` | Shared git hook pipeline |
|
|
36
36
|
|
|
37
|
+
### `knip --production`
|
|
38
|
+
|
|
39
|
+
Every preset marks its runtime entries and source globs with knip's production
|
|
40
|
+
suffix (`!`) and leaves configuration files unmarked, and tests, mocks and
|
|
41
|
+
stories are excluded in production mode only. `knip --production` then starts
|
|
42
|
+
from the code that ships: a dependency only a test imports, or a build plugin in
|
|
43
|
+
`dependencies`, is reported there, while the default run is unchanged. A
|
|
44
|
+
`project` or `entry` glob you pass that holds runtime code needs the `!` too
|
|
45
|
+
(`'components/**/*.tsx!'`); unmarked, it is left out of the production run.
|
|
46
|
+
|
|
47
|
+
Preset entry files that do not exist and preset patterns matching no files are
|
|
48
|
+
omitted. A tooling package with only `scripts/` therefore does not inherit
|
|
49
|
+
unmatched `src/` patterns. Pass its actual roots through `entry` and `project`;
|
|
50
|
+
caller patterns are preserved so Knip can report mistakes in them. Paths resolve
|
|
51
|
+
against `cwd`, which defaults to the process working directory.
|
|
52
|
+
|
|
53
|
+
ESLint compatibility exemptions apply only when the project declares
|
|
54
|
+
`@syntopica/eslint-config`. Projects with their own ESLint configuration retain
|
|
55
|
+
unused-dependency checking for those packages and can add explicit
|
|
56
|
+
`ignoreDependencies` entries when needed.
|
|
57
|
+
|
|
58
|
+
### Module boundaries on the resolved graph
|
|
59
|
+
|
|
60
|
+
`createDepCruiserConfig({ moduleRoots: ['src/features'] })` treats each child of
|
|
61
|
+
`src/features` as a module and fails any file in one module that reaches a file
|
|
62
|
+
of another module other than its `index`. It runs on resolved paths, so an
|
|
63
|
+
alias, a re-export or a relative `../../` are all caught the same way, which
|
|
64
|
+
code-policy's `public-api-imports` and `no-cross-module-deep-imports` cannot do
|
|
65
|
+
from the import string. Off unless roots are named.
|
|
66
|
+
|
|
37
67
|
### `baseline-env-init`
|
|
38
68
|
|
|
39
69
|
Seeds a gitignored `.env` from the committed `.env.example`, so a freshly cloned
|
package/jscpd.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"minTokens": 70,
|
|
3
3
|
"threshold": 1,
|
|
4
|
-
"format": [
|
|
4
|
+
"format": [
|
|
5
|
+
"typescript",
|
|
6
|
+
"tsx",
|
|
7
|
+
"javascript",
|
|
8
|
+
"jsx",
|
|
9
|
+
"vue",
|
|
10
|
+
"astro",
|
|
11
|
+
"rust",
|
|
12
|
+
"dart",
|
|
13
|
+
"swift"
|
|
14
|
+
],
|
|
5
15
|
"gitignore": true,
|
|
6
16
|
"ignore": [
|
|
7
17
|
"**/node_modules/**",
|
|
@@ -9,7 +19,12 @@
|
|
|
9
19
|
"**/.next/**",
|
|
10
20
|
"**/.output/**",
|
|
11
21
|
"**/target/**",
|
|
12
|
-
"**/coverage/**"
|
|
22
|
+
"**/coverage/**",
|
|
23
|
+
"**/*.g.dart",
|
|
24
|
+
"**/*.freezed.dart",
|
|
25
|
+
"**/.build/**",
|
|
26
|
+
"**/build/**",
|
|
27
|
+
"**/.dart_tool/**"
|
|
13
28
|
],
|
|
14
29
|
"reporters": ["console"]
|
|
15
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syntopica/quality-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Shared configuration for cross-file quality gates: knip, dependency-cruiser, type-coverage, jscpd, lefthook",
|
|
@@ -73,8 +73,9 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
76
|
-
"@syntopica/eslint-config": "0.
|
|
76
|
+
"@syntopica/eslint-config": "0.10.0",
|
|
77
77
|
"@types/node": "^26.6.5",
|
|
78
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
78
79
|
"dependency-cruiser": "^18.5.0",
|
|
79
80
|
"eslint": "^10.12.0",
|
|
80
81
|
"eslint-plugin-regexp": "^3.3.1",
|
|
@@ -83,6 +84,9 @@
|
|
|
83
84
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
84
85
|
"vitest": "^5.0.3"
|
|
85
86
|
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"tinyglobby": "^0.2.17"
|
|
89
|
+
},
|
|
86
90
|
"scripts": {
|
|
87
91
|
"fix": "pnpm run lint:fix",
|
|
88
92
|
"lint": "eslint src bin tests --max-warnings 0",
|
|
@@ -90,7 +94,7 @@
|
|
|
90
94
|
"lint:suppress": "eslint src bin tests --suppress-all",
|
|
91
95
|
"lint:prune": "eslint src bin tests --prune-suppressions",
|
|
92
96
|
"test": "vitest run",
|
|
93
|
-
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
97
|
+
"type-check": "node node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.json",
|
|
94
98
|
"publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
|
|
95
99
|
}
|
|
96
100
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KnipFramework } from './knip-framework'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Framework packages that serve the app but are imported only by its config
|
|
5
|
+
* file. `knip --production` drops config files, so it reports `astro` and
|
|
6
|
+
* `nuxt` as unused; both are runtime dependencies. The trailing `!` makes the
|
|
7
|
+
* ignore apply to production mode only, so the default run still checks them.
|
|
8
|
+
*/
|
|
9
|
+
export const FRAMEWORK_RUNTIME_PACKAGES: Partial<
|
|
10
|
+
Record<KnipFramework, string[]>
|
|
11
|
+
> = {
|
|
12
|
+
astro: ['astro!'],
|
|
13
|
+
nuxt: ['nuxt!'],
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project files that never ship, excluded from `knip --production` only: the
|
|
3
|
+
* leading `!` negates, the trailing `!` limits the negation to production mode,
|
|
4
|
+
* so the default run still analyses tests and stories. Without it a test file
|
|
5
|
+
* matched by a production project glob counts as runtime code, and a
|
|
6
|
+
* dependency only the tests import would pass for a production one.
|
|
7
|
+
*/
|
|
8
|
+
export const PRODUCTION_PROJECT_EXCLUSIONS = [
|
|
9
|
+
'!**/*.{test,spec}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}!',
|
|
10
|
+
'!**/{__tests__,__mocks__,test,tests}/**!',
|
|
11
|
+
'!**/*.stories.{ts,tsx,js,jsx,mdx}!',
|
|
12
|
+
]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { IConfiguration, IForbiddenRuleType } from 'dependency-cruiser'
|
|
2
2
|
|
|
3
|
+
import { moduleBoundaryRules } from './moduleBoundaryRules'
|
|
4
|
+
|
|
3
5
|
// Next.js App Router file conventions. Next loads each of these by filename at
|
|
4
6
|
// build or request time, so nothing imports them and having no importer is
|
|
5
7
|
// their normal state rather than a defect.
|
|
@@ -109,12 +111,16 @@ const REPO_SCOPE_RULES: IForbiddenRuleType[] = [
|
|
|
109
111
|
* the framework-convention ones built in here. Use it for directories a
|
|
110
112
|
* repo-wide run cannot judge - typically a workspace whose path aliases only
|
|
111
113
|
* resolve under its own tsconfig, cruised separately at `scope: 'workspace'`.
|
|
114
|
+
*
|
|
115
|
+
* `moduleRoots` (opt-in) names directories whose children are modules, such
|
|
116
|
+
* as `src/features`: a module may reach another only through its `index`.
|
|
112
117
|
*/
|
|
113
118
|
export const createDepCruiserConfig = (
|
|
114
119
|
options: {
|
|
115
120
|
tsConfigPath?: string
|
|
116
121
|
scope?: 'repo' | 'workspace'
|
|
117
122
|
orphanExemptions?: string[]
|
|
123
|
+
moduleRoots?: string[]
|
|
118
124
|
} = {},
|
|
119
125
|
): IConfiguration => ({
|
|
120
126
|
forbidden: [
|
|
@@ -130,6 +136,7 @@ export const createDepCruiserConfig = (
|
|
|
130
136
|
to: {},
|
|
131
137
|
},
|
|
132
138
|
...(options.scope === 'workspace' ? [] : REPO_SCOPE_RULES),
|
|
139
|
+
...moduleBoundaryRules(options.moduleRoots ?? []),
|
|
133
140
|
],
|
|
134
141
|
options: {
|
|
135
142
|
doNotFollow: { path: 'node_modules' },
|
package/src/existingEntries.ts
CHANGED
|
@@ -11,9 +11,13 @@ const GLOB_CHARACTERS = /[*?{}[\]!]/u
|
|
|
11
11
|
* pattern (no matches)" hint the caller cannot silence.
|
|
12
12
|
*/
|
|
13
13
|
export const existingEntries = (entries: string[], cwd: string): string[] =>
|
|
14
|
-
entries.filter(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
entries.filter((entry) => {
|
|
15
|
+
// A trailing `!` marks a production entry, not a glob: `src/index.ts!` is
|
|
16
|
+
// still the literal `src/index.ts`.
|
|
17
|
+
const path = entry.replace(/!$/u, '')
|
|
18
|
+
return (
|
|
19
|
+
GLOB_CHARACTERS.test(path) ||
|
|
17
20
|
// eslint-disable-next-line security/detect-non-literal-fs-filename -- the entry is the preset's own literal, resolved against the project root
|
|
18
|
-
existsSync(join(cwd,
|
|
19
|
-
|
|
21
|
+
existsSync(join(cwd, path))
|
|
22
|
+
)
|
|
23
|
+
})
|
package/src/knip-framework.ts
CHANGED
|
@@ -10,6 +10,17 @@
|
|
|
10
10
|
* imports it by design. knip 6.35 started applying `includeEntryExports` to
|
|
11
11
|
* the files its own plugins register, so a blanket `true` failed the gate in
|
|
12
12
|
* six of the eight templates with exports no project can remove.
|
|
13
|
+
*
|
|
14
|
+
* A trailing `!` marks a pattern as production code for `knip --production`,
|
|
15
|
+
* which keeps only marked entries and marked project files: the runtime roots
|
|
16
|
+
* and sources carry it, framework and build configuration does not. Without
|
|
17
|
+
* the mark, production mode treated every source file as outside the project
|
|
18
|
+
* and reported runtime dependencies - `vue`, `zod`, `@nestjs/core` - as unused.
|
|
19
|
+
* Tests sitting beside the sources are excluded from production through
|
|
20
|
+
* PRODUCTION_PROJECT_EXCLUSIONS. Configuration stays unmarked - knip drops a
|
|
21
|
+
* plugin's config files from production whatever their mark - so a Vite plugin
|
|
22
|
+
* imported only by `vite.config.*` and declared in `dependencies` is reported
|
|
23
|
+
* there, rightly: it is a build tool.
|
|
13
24
|
*/
|
|
14
25
|
export type KnipFramework =
|
|
15
26
|
| 'astro'
|
|
@@ -27,13 +38,13 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
27
38
|
{ entry: string[]; project: string[]; includeEntryExports: boolean }
|
|
28
39
|
> = {
|
|
29
40
|
astro: {
|
|
30
|
-
entry: ['src/pages/**/*.{astro,ts,tsx}', 'astro.config.*'],
|
|
31
|
-
project: ['src/**/*.{astro,ts,tsx}'],
|
|
41
|
+
entry: ['src/pages/**/*.{astro,ts,tsx}!', 'astro.config.*'],
|
|
42
|
+
project: ['src/**/*.{astro,ts,tsx}!'],
|
|
32
43
|
includeEntryExports: false,
|
|
33
44
|
},
|
|
34
45
|
nestjs: {
|
|
35
|
-
entry: ['src/main.ts', 'src/**/*.module.ts'],
|
|
36
|
-
project: ['src/**/*.ts'],
|
|
46
|
+
entry: ['src/main.ts!', 'src/**/*.module.ts!'],
|
|
47
|
+
project: ['src/**/*.ts!'],
|
|
37
48
|
includeEntryExports: true,
|
|
38
49
|
},
|
|
39
50
|
// The App Router lives at either `app/` or `src/app/`, and the proxy follows
|
|
@@ -51,15 +62,15 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
51
62
|
// "Refine entry pattern (no matches)" hint in a project that has neither.
|
|
52
63
|
nextjs: {
|
|
53
64
|
entry: [
|
|
54
|
-
'{,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}',
|
|
65
|
+
'{,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}!',
|
|
55
66
|
'next.config.*',
|
|
56
67
|
],
|
|
57
|
-
project: ['{,src/}app/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
|
|
68
|
+
project: ['{,src/}app/**/*.{ts,tsx}!', 'src/**/*.{ts,tsx}!'],
|
|
58
69
|
includeEntryExports: false,
|
|
59
70
|
},
|
|
60
71
|
nuxt: {
|
|
61
|
-
entry: ['app/**/*.vue', 'server/**/*.ts', 'nuxt.config.*'],
|
|
62
|
-
project: ['app/**/*.{ts,vue}', 'server/**/*.ts'],
|
|
72
|
+
entry: ['app/**/*.vue!', 'server/**/*.ts!', 'nuxt.config.*'],
|
|
73
|
+
project: ['app/**/*.{ts,vue}!', 'server/**/*.ts!'],
|
|
63
74
|
includeEntryExports: false,
|
|
64
75
|
},
|
|
65
76
|
// TanStack Start has no index.html and no src/main.tsx: the router is the
|
|
@@ -70,37 +81,37 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
70
81
|
// becoming "Refine entry pattern" hints.
|
|
71
82
|
'tanstack-start': {
|
|
72
83
|
entry: [
|
|
73
|
-
'src/router.{ts,tsx}',
|
|
74
|
-
'src/routes/**/*.{ts,tsx}',
|
|
75
|
-
'src/{server,start,client}.{ts,tsx}',
|
|
84
|
+
'src/router.{ts,tsx}!',
|
|
85
|
+
'src/routes/**/*.{ts,tsx}!',
|
|
86
|
+
'src/{server,start,client}.{ts,tsx}!',
|
|
76
87
|
'vite.config.*',
|
|
77
88
|
],
|
|
78
|
-
project: ['src/**/*.{ts,tsx}'],
|
|
89
|
+
project: ['src/**/*.{ts,tsx}!'],
|
|
79
90
|
includeEntryExports: false,
|
|
80
91
|
},
|
|
81
92
|
tauri: {
|
|
82
93
|
// The scaffolded tauri-app frontend is React, so its entry is
|
|
83
94
|
// src/main.tsx, not src/main.ts; keep both extensions so a plain-TS
|
|
84
95
|
// Tauri frontend also matches.
|
|
85
|
-
entry: ['src/main.{ts,tsx}', 'vite.config.*'],
|
|
86
|
-
project: ['src/**/*.{ts,tsx}'],
|
|
96
|
+
entry: ['src/main.{ts,tsx}!', 'vite.config.*'],
|
|
97
|
+
project: ['src/**/*.{ts,tsx}!'],
|
|
87
98
|
includeEntryExports: false,
|
|
88
99
|
},
|
|
89
100
|
'ts-package': {
|
|
90
|
-
entry: ['src/index.ts'],
|
|
91
|
-
project: ['src/**/*.ts'],
|
|
101
|
+
entry: ['src/index.ts!'],
|
|
102
|
+
project: ['src/**/*.ts!'],
|
|
92
103
|
includeEntryExports: true,
|
|
93
104
|
},
|
|
94
105
|
// `src/main.*` is reached through index.html's module script; listing it as
|
|
95
106
|
// well was a "Remove redundant entry pattern" hint in both Vite templates.
|
|
96
107
|
'vite-react': {
|
|
97
|
-
entry: ['index.html', 'vite.config.*'],
|
|
98
|
-
project: ['src/**/*.{ts,tsx}'],
|
|
108
|
+
entry: ['index.html!', 'vite.config.*'],
|
|
109
|
+
project: ['src/**/*.{ts,tsx}!'],
|
|
99
110
|
includeEntryExports: false,
|
|
100
111
|
},
|
|
101
112
|
'vite-vue': {
|
|
102
|
-
entry: ['index.html', 'vite.config.*'],
|
|
103
|
-
project: ['src/**/*.{ts,vue}'],
|
|
113
|
+
entry: ['index.html!', 'vite.config.*'],
|
|
114
|
+
project: ['src/**/*.{ts,vue}!'],
|
|
104
115
|
includeEntryExports: false,
|
|
105
116
|
},
|
|
106
117
|
}
|
package/src/knip.ts
CHANGED
|
@@ -5,37 +5,19 @@
|
|
|
5
5
|
// config without casting it first.
|
|
6
6
|
import type { KnipConfiguration } from 'knip'
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { FRAMEWORK_RUNTIME_PACKAGES } from './FRAMEWORK_RUNTIME_PACKAGES'
|
|
9
9
|
import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
10
|
+
import { matchedPresetPatterns } from './matchedPresetPatterns'
|
|
10
11
|
import { peersOfListedDependencies } from './peersOfListedDependencies'
|
|
12
|
+
import { PRODUCTION_PROJECT_EXCLUSIONS } from './PRODUCTION_PROJECT_EXCLUSIONS'
|
|
13
|
+
import { readListedDependencies } from './readListedDependencies'
|
|
11
14
|
import { runnerDependenciesToIgnore } from './runnerDependenciesToIgnore'
|
|
12
15
|
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
// '@syntopica/eslint-config/*'), so knip can't see the real caller and
|
|
19
|
-
// reports them as unused. Mirrors the same list and rationale in the
|
|
20
|
-
// repo-root knip.config.ts for the `templates/*` workspace.
|
|
21
|
-
//
|
|
22
|
-
// Two packages that used to sit here - `@vitest/eslint-plugin` and
|
|
23
|
-
// `eslint-plugin-testing-library` - were removed on 2026-08-24: knip resolved
|
|
24
|
-
// the real caller in all eight templates, so the entries were redundant
|
|
25
|
-
// everywhere and produced a hint no consumer could silence. The rest stay:
|
|
26
|
-
// `eslint-config-prettier` is redundant in four of the eight and load-bearing
|
|
27
|
-
// in the other four, which is exactly the case the list exists for. A consumer
|
|
28
|
-
// whose layout hides a caller can add its own entries through
|
|
29
|
-
// `ignoreDependencies`, which merges with this list rather than replacing it.
|
|
30
|
-
//
|
|
31
|
-
// Where an entry here IS redundant, knip says so:
|
|
32
|
-
// `<package> knip.config.ts Remove from ignoreDependencies`. That is a hint,
|
|
33
|
-
// not a gate failure. Do not filter the list consumer-side to silence it: the
|
|
34
|
-
// filter would drift the moment this list changes, and the cost of being wrong
|
|
35
|
-
// is a dependency that silently stops being checked. The one filter applied
|
|
36
|
-
// here mirrors knip's own rule: a package another installed dependency
|
|
37
|
-
// declares as a peer (`eslint-plugin-astro` hosts `typescript-eslint`) is
|
|
38
|
-
// counted as used by knip, so it is not ignored.
|
|
16
|
+
// Older shared ESLint configs require these packages as consumer-provided
|
|
17
|
+
// peers. Their imports can be hidden from Knip. Apply that compatibility list
|
|
18
|
+
// only to consumers declaring @syntopica/eslint-config; custom ESLint configs
|
|
19
|
+
// have their own imports and must not inherit these dependency exemptions.
|
|
20
|
+
// A peer of another installed dependency is already counted as used by Knip.
|
|
39
21
|
const ESLINT_PEER_DEPENDENCIES = [
|
|
40
22
|
'@eslint/js',
|
|
41
23
|
'eslint-config-prettier',
|
|
@@ -83,16 +65,22 @@ export const createKnipConfig = (options: {
|
|
|
83
65
|
* `app/`. An app whose code sits at the repo root (`components/`, `hooks/`,
|
|
84
66
|
* `services/`, ...) is invisible to knip under that preset, and every
|
|
85
67
|
* dependency reached only from there reports as unused. This is a merge, not
|
|
86
|
-
* a replacement:
|
|
68
|
+
* a replacement: matching preset globs stay, so a project cannot silently opt
|
|
87
69
|
* out of scanning the directories the framework does own.
|
|
70
|
+
*
|
|
71
|
+
* Add a trailing `!` to a glob that holds runtime code
|
|
72
|
+
* (`'components/**\/*.tsx!'`): `knip --production` analyses only marked
|
|
73
|
+
* globs, so an unmarked one drops out of that run.
|
|
88
74
|
*/
|
|
89
75
|
project?: string[]
|
|
90
76
|
/**
|
|
91
77
|
* Extra entry globs, merged with the framework preset's `entry`. Same
|
|
92
78
|
* reasoning as `project`, for a root nobody's plugin registers - a worker,
|
|
93
|
-
* a CLI, a script the app spawns.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
79
|
+
* a CLI, a script the app spawns. Missing preset files and unmatched preset
|
|
80
|
+
* patterns are omitted. Caller patterns stay unchanged so a misspelled
|
|
81
|
+
* custom path still produces a Knip hint.
|
|
82
|
+
* Mark a runtime root with a trailing `!` (`'src/cli/main.ts!'`) so
|
|
83
|
+
* `knip --production` starts from it too; leave scripts and tooling unmarked.
|
|
96
84
|
*/
|
|
97
85
|
entry?: string[]
|
|
98
86
|
/**
|
|
@@ -115,14 +103,19 @@ export const createKnipConfig = (options: {
|
|
|
115
103
|
}): KnipConfiguration => {
|
|
116
104
|
const cwd = options.cwd ?? process.cwd()
|
|
117
105
|
const hostedPeers = peersOfListedDependencies(cwd)
|
|
106
|
+
const usesSharedEslint = readListedDependencies(cwd).includes(
|
|
107
|
+
'@syntopica/eslint-config',
|
|
108
|
+
)
|
|
118
109
|
const { entry, project, includeEntryExports } =
|
|
119
110
|
FRAMEWORK_ENTRIES[options.framework]
|
|
120
111
|
|
|
121
112
|
return {
|
|
122
|
-
entry: options.entry
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
entry: [...matchedPresetPatterns(entry, cwd), ...(options.entry ?? [])],
|
|
114
|
+
project: [
|
|
115
|
+
...matchedPresetPatterns(project, cwd),
|
|
116
|
+
...(options.project ?? []),
|
|
117
|
+
...PRODUCTION_PROJECT_EXCLUSIONS,
|
|
118
|
+
],
|
|
126
119
|
...(options.ignore ? { ignore: options.ignore } : {}),
|
|
127
120
|
...(options.drizzle === false ? { drizzle: false } : {}),
|
|
128
121
|
// Without this, exports of entry files are never checked, so a dead export
|
|
@@ -146,8 +139,9 @@ export const createKnipConfig = (options: {
|
|
|
146
139
|
ignoreBinaries: ['gitleaks', ...(options.ignoreBinaries ?? [])],
|
|
147
140
|
ignoreDependencies: [
|
|
148
141
|
...runnerDependenciesToIgnore(cwd),
|
|
142
|
+
...(FRAMEWORK_RUNTIME_PACKAGES[options.framework] ?? []),
|
|
149
143
|
...ESLINT_PEER_DEPENDENCIES.filter(
|
|
150
|
-
(dependency) => !hostedPeers.has(dependency),
|
|
144
|
+
(dependency) => usesSharedEslint && !hostedPeers.has(dependency),
|
|
151
145
|
),
|
|
152
146
|
...(options.ignoreDependencies ?? []),
|
|
153
147
|
],
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { globSync } from 'tinyglobby'
|
|
2
|
+
|
|
3
|
+
import { existingEntries } from './existingEntries'
|
|
4
|
+
|
|
5
|
+
/** Omit unmatched preset patterns; caller patterns are never passed here. */
|
|
6
|
+
export const matchedPresetPatterns = (
|
|
7
|
+
patterns: string[],
|
|
8
|
+
cwd: string,
|
|
9
|
+
): string[] =>
|
|
10
|
+
existingEntries(patterns, cwd).filter((pattern) => {
|
|
11
|
+
const path = pattern.replace(/!$/u, '')
|
|
12
|
+
return globSync(path, { cwd, dot: true }).length > 0
|
|
13
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IForbiddenRuleType } from 'dependency-cruiser'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One rule per module root (`src/features`, say): a file in one module may
|
|
5
|
+
* import another module only through that module's `index`. Matched on the
|
|
6
|
+
* resolved path, so an alias, a re-export or a relative `../` all count, which
|
|
7
|
+
* the ESLint import rules cannot see from the specifier string alone.
|
|
8
|
+
*/
|
|
9
|
+
export const moduleBoundaryRules = (roots: string[]): IForbiddenRuleType[] =>
|
|
10
|
+
roots.map((root) => {
|
|
11
|
+
const prefix = `^${root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/`
|
|
12
|
+
return {
|
|
13
|
+
name: 'no-deep-cross-module-import',
|
|
14
|
+
severity: 'error',
|
|
15
|
+
comment: `Import another module under ${root}/ through its index, not its internal files.`,
|
|
16
|
+
from: { path: `${prefix}([^/]+)/` },
|
|
17
|
+
to: {
|
|
18
|
+
path: `${prefix}[^/]+/`,
|
|
19
|
+
pathNot: [`${prefix}$1/`, `${prefix}[^/]+/index\\.[cm]?[jt]sx?$`],
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
})
|