@syntopica/quality-config 0.14.0 → 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 +11 -0
- package/jscpd.json +17 -2
- package/package.json +6 -2
- package/src/knip.ts +17 -36
- package/src/matchedPresetPatterns.ts +13 -0
package/README.md
CHANGED
|
@@ -44,6 +44,17 @@ from the code that ships: a dependency only a test imports, or a build plugin in
|
|
|
44
44
|
`project` or `entry` glob you pass that holds runtime code needs the `!` too
|
|
45
45
|
(`'components/**/*.tsx!'`); unmarked, it is left out of the production run.
|
|
46
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
|
+
|
|
47
58
|
### Module boundaries on the resolved graph
|
|
48
59
|
|
|
49
60
|
`createDepCruiserConfig({ moduleRoots: ['src/features'] })` treats each child of
|
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",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
76
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
|
}
|
package/src/knip.ts
CHANGED
|
@@ -5,39 +5,19 @@
|
|
|
5
5
|
// config without casting it first.
|
|
6
6
|
import type { KnipConfiguration } from 'knip'
|
|
7
7
|
|
|
8
|
-
import { existingEntries } from './existingEntries'
|
|
9
8
|
import { FRAMEWORK_RUNTIME_PACKAGES } from './FRAMEWORK_RUNTIME_PACKAGES'
|
|
10
9
|
import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
10
|
+
import { matchedPresetPatterns } from './matchedPresetPatterns'
|
|
11
11
|
import { peersOfListedDependencies } from './peersOfListedDependencies'
|
|
12
12
|
import { PRODUCTION_PROJECT_EXCLUSIONS } from './PRODUCTION_PROJECT_EXCLUSIONS'
|
|
13
|
+
import { readListedDependencies } from './readListedDependencies'
|
|
13
14
|
import { runnerDependenciesToIgnore } from './runnerDependenciesToIgnore'
|
|
14
15
|
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// '@syntopica/eslint-config/*'), so knip can't see the real caller and
|
|
21
|
-
// reports them as unused. Mirrors the same list and rationale in the
|
|
22
|
-
// repo-root knip.config.ts for the `templates/*` workspace.
|
|
23
|
-
//
|
|
24
|
-
// Two packages that used to sit here - `@vitest/eslint-plugin` and
|
|
25
|
-
// `eslint-plugin-testing-library` - were removed on 2026-08-24: knip resolved
|
|
26
|
-
// the real caller in all eight templates, so the entries were redundant
|
|
27
|
-
// everywhere and produced a hint no consumer could silence. The rest stay:
|
|
28
|
-
// `eslint-config-prettier` is redundant in four of the eight and load-bearing
|
|
29
|
-
// in the other four, which is exactly the case the list exists for. A consumer
|
|
30
|
-
// whose layout hides a caller can add its own entries through
|
|
31
|
-
// `ignoreDependencies`, which merges with this list rather than replacing it.
|
|
32
|
-
//
|
|
33
|
-
// Where an entry here IS redundant, knip says so:
|
|
34
|
-
// `<package> knip.config.ts Remove from ignoreDependencies`. That is a hint,
|
|
35
|
-
// not a gate failure. Do not filter the list consumer-side to silence it: the
|
|
36
|
-
// filter would drift the moment this list changes, and the cost of being wrong
|
|
37
|
-
// is a dependency that silently stops being checked. The one filter applied
|
|
38
|
-
// here mirrors knip's own rule: a package another installed dependency
|
|
39
|
-
// declares as a peer (`eslint-plugin-astro` hosts `typescript-eslint`) is
|
|
40
|
-
// 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.
|
|
41
21
|
const ESLINT_PEER_DEPENDENCIES = [
|
|
42
22
|
'@eslint/js',
|
|
43
23
|
'eslint-config-prettier',
|
|
@@ -85,7 +65,7 @@ export const createKnipConfig = (options: {
|
|
|
85
65
|
* `app/`. An app whose code sits at the repo root (`components/`, `hooks/`,
|
|
86
66
|
* `services/`, ...) is invisible to knip under that preset, and every
|
|
87
67
|
* dependency reached only from there reports as unused. This is a merge, not
|
|
88
|
-
* a replacement:
|
|
68
|
+
* a replacement: matching preset globs stay, so a project cannot silently opt
|
|
89
69
|
* out of scanning the directories the framework does own.
|
|
90
70
|
*
|
|
91
71
|
* Add a trailing `!` to a glob that holds runtime code
|
|
@@ -96,9 +76,9 @@ export const createKnipConfig = (options: {
|
|
|
96
76
|
/**
|
|
97
77
|
* Extra entry globs, merged with the framework preset's `entry`. Same
|
|
98
78
|
* reasoning as `project`, for a root nobody's plugin registers - a worker,
|
|
99
|
-
* a CLI, a script the app spawns.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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.
|
|
102
82
|
* Mark a runtime root with a trailing `!` (`'src/cli/main.ts!'`) so
|
|
103
83
|
* `knip --production` starts from it too; leave scripts and tooling unmarked.
|
|
104
84
|
*/
|
|
@@ -123,15 +103,16 @@ export const createKnipConfig = (options: {
|
|
|
123
103
|
}): KnipConfiguration => {
|
|
124
104
|
const cwd = options.cwd ?? process.cwd()
|
|
125
105
|
const hostedPeers = peersOfListedDependencies(cwd)
|
|
106
|
+
const usesSharedEslint = readListedDependencies(cwd).includes(
|
|
107
|
+
'@syntopica/eslint-config',
|
|
108
|
+
)
|
|
126
109
|
const { entry, project, includeEntryExports } =
|
|
127
110
|
FRAMEWORK_ENTRIES[options.framework]
|
|
128
111
|
|
|
129
112
|
return {
|
|
130
|
-
entry: options.entry
|
|
131
|
-
? [...existingEntries(entry, cwd), ...options.entry]
|
|
132
|
-
: entry,
|
|
113
|
+
entry: [...matchedPresetPatterns(entry, cwd), ...(options.entry ?? [])],
|
|
133
114
|
project: [
|
|
134
|
-
...project,
|
|
115
|
+
...matchedPresetPatterns(project, cwd),
|
|
135
116
|
...(options.project ?? []),
|
|
136
117
|
...PRODUCTION_PROJECT_EXCLUSIONS,
|
|
137
118
|
],
|
|
@@ -160,7 +141,7 @@ export const createKnipConfig = (options: {
|
|
|
160
141
|
...runnerDependenciesToIgnore(cwd),
|
|
161
142
|
...(FRAMEWORK_RUNTIME_PACKAGES[options.framework] ?? []),
|
|
162
143
|
...ESLINT_PEER_DEPENDENCIES.filter(
|
|
163
|
-
(dependency) => !hostedPeers.has(dependency),
|
|
144
|
+
(dependency) => usesSharedEslint && !hostedPeers.has(dependency),
|
|
164
145
|
),
|
|
165
146
|
...(options.ignoreDependencies ?? []),
|
|
166
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
|
+
})
|