knip 5.67.1 → 5.69.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.
Files changed (309) hide show
  1. package/dist/CatalogCounselor.d.ts +18 -0
  2. package/dist/CatalogCounselor.js +47 -0
  3. package/dist/ConfigurationChief.d.ts +12 -0
  4. package/dist/ConfigurationChief.js +3 -1
  5. package/dist/IssueFixer.d.ts +2 -1
  6. package/dist/IssueFixer.js +51 -3
  7. package/dist/JsonCatalogPeeker.d.ts +12 -0
  8. package/dist/JsonCatalogPeeker.js +68 -0
  9. package/dist/PackagePeeker.js +1 -0
  10. package/dist/YamlCatalogPeeker.d.ts +12 -0
  11. package/dist/YamlCatalogPeeker.js +66 -0
  12. package/dist/binaries/bash-parser.js +1 -1
  13. package/dist/compilers/index.d.ts +24 -4
  14. package/dist/constants.d.ts +9 -1
  15. package/dist/constants.js +9 -0
  16. package/dist/graph/analyze.d.ts +3 -1
  17. package/dist/graph/analyze.js +4 -1
  18. package/dist/graph/build.d.ts +3 -1
  19. package/dist/graph/build.js +2 -1
  20. package/dist/index.js +4 -0
  21. package/dist/plugins/_template/index.d.ts +3 -12
  22. package/dist/plugins/_template/index.js +2 -1
  23. package/dist/plugins/angular/index.d.ts +3 -10
  24. package/dist/plugins/angular/index.js +2 -1
  25. package/dist/plugins/astro/index.d.ts +3 -13
  26. package/dist/plugins/astro/index.js +2 -1
  27. package/dist/plugins/astro-db/index.d.ts +3 -8
  28. package/dist/plugins/astro-db/index.js +2 -1
  29. package/dist/plugins/ava/index.d.ts +3 -11
  30. package/dist/plugins/ava/index.js +2 -1
  31. package/dist/plugins/babel/index.d.ts +4 -10
  32. package/dist/plugins/babel/index.js +2 -1
  33. package/dist/plugins/biome/index.d.ts +3 -10
  34. package/dist/plugins/biome/index.js +2 -1
  35. package/dist/plugins/bumpp/index.d.ts +3 -8
  36. package/dist/plugins/bumpp/index.js +2 -1
  37. package/dist/plugins/bun/index.d.ts +3 -11
  38. package/dist/plugins/bun/index.js +2 -1
  39. package/dist/plugins/c8/index.d.ts +3 -10
  40. package/dist/plugins/c8/index.js +2 -1
  41. package/dist/plugins/capacitor/index.d.ts +3 -10
  42. package/dist/plugins/capacitor/index.js +2 -1
  43. package/dist/plugins/changelogen/index.d.ts +3 -9
  44. package/dist/plugins/changelogen/index.js +2 -1
  45. package/dist/plugins/changelogithub/index.d.ts +3 -9
  46. package/dist/plugins/changelogithub/index.js +2 -1
  47. package/dist/plugins/changesets/index.d.ts +3 -11
  48. package/dist/plugins/changesets/index.js +2 -1
  49. package/dist/plugins/commitizen/index.d.ts +3 -12
  50. package/dist/plugins/commitizen/index.js +2 -1
  51. package/dist/plugins/commitlint/index.d.ts +3 -10
  52. package/dist/plugins/commitlint/index.js +2 -1
  53. package/dist/plugins/convex/index.d.ts +3 -8
  54. package/dist/plugins/convex/index.js +2 -1
  55. package/dist/plugins/create-typescript-app/index.d.ts +3 -8
  56. package/dist/plugins/create-typescript-app/index.js +2 -1
  57. package/dist/plugins/cspell/index.d.ts +3 -10
  58. package/dist/plugins/cspell/index.js +3 -2
  59. package/dist/plugins/cucumber/index.d.ts +3 -11
  60. package/dist/plugins/cucumber/index.js +2 -1
  61. package/dist/plugins/cypress/index.d.ts +3 -11
  62. package/dist/plugins/cypress/index.js +2 -1
  63. package/dist/plugins/danger/index.d.ts +3 -8
  64. package/dist/plugins/danger/index.js +2 -1
  65. package/dist/plugins/dependency-cruiser/index.d.ts +3 -12
  66. package/dist/plugins/dependency-cruiser/index.js +2 -1
  67. package/dist/plugins/docusaurus/index.d.ts +3 -12
  68. package/dist/plugins/docusaurus/index.js +2 -1
  69. package/dist/plugins/dotenv/index.d.ts +3 -8
  70. package/dist/plugins/dotenv/index.js +2 -1
  71. package/dist/plugins/drizzle/index.d.ts +3 -10
  72. package/dist/plugins/drizzle/index.js +2 -1
  73. package/dist/plugins/eleventy/index.d.ts +3 -11
  74. package/dist/plugins/eleventy/index.js +2 -1
  75. package/dist/plugins/eslint/helpers.d.ts +1 -0
  76. package/dist/plugins/eslint/helpers.js +14 -1
  77. package/dist/plugins/eslint/index.d.ts +3 -19
  78. package/dist/plugins/eslint/index.js +7 -2
  79. package/dist/plugins/expo/index.d.ts +3 -11
  80. package/dist/plugins/expo/index.js +2 -1
  81. package/dist/plugins/gatsby/index.d.ts +3 -11
  82. package/dist/plugins/gatsby/index.js +2 -1
  83. package/dist/plugins/github-action/index.d.ts +3 -9
  84. package/dist/plugins/github-action/index.js +2 -1
  85. package/dist/plugins/github-actions/index.d.ts +3 -10
  86. package/dist/plugins/github-actions/index.js +2 -1
  87. package/dist/plugins/glob/index.d.ts +3 -11
  88. package/dist/plugins/glob/index.js +2 -1
  89. package/dist/plugins/graphql-codegen/index.d.ts +3 -11
  90. package/dist/plugins/graphql-codegen/index.js +2 -1
  91. package/dist/plugins/hardhat/index.d.ts +3 -9
  92. package/dist/plugins/hardhat/index.js +2 -1
  93. package/dist/plugins/husky/index.d.ts +3 -10
  94. package/dist/plugins/husky/index.js +2 -1
  95. package/dist/plugins/i18next-parser/index.d.ts +3 -12
  96. package/dist/plugins/i18next-parser/index.js +2 -1
  97. package/dist/plugins/index.d.ts +118 -935
  98. package/dist/plugins/index.js +4 -0
  99. package/dist/plugins/jest/index.d.ts +3 -14
  100. package/dist/plugins/jest/index.js +2 -1
  101. package/dist/plugins/karma/index.d.ts +3 -10
  102. package/dist/plugins/karma/index.js +2 -1
  103. package/dist/plugins/ladle/index.d.ts +3 -12
  104. package/dist/plugins/ladle/index.js +2 -1
  105. package/dist/plugins/lefthook/index.d.ts +3 -9
  106. package/dist/plugins/lefthook/index.js +2 -1
  107. package/dist/plugins/lint-staged/index.d.ts +3 -10
  108. package/dist/plugins/lint-staged/index.js +2 -1
  109. package/dist/plugins/linthtml/index.d.ts +3 -11
  110. package/dist/plugins/linthtml/index.js +2 -1
  111. package/dist/plugins/lockfile-lint/index.d.ts +3 -8
  112. package/dist/plugins/lockfile-lint/index.js +2 -1
  113. package/dist/plugins/lost-pixel/index.d.ts +3 -8
  114. package/dist/plugins/lost-pixel/index.js +2 -1
  115. package/dist/plugins/markdownlint/index.d.ts +3 -10
  116. package/dist/plugins/markdownlint/index.js +2 -1
  117. package/dist/plugins/mdx/index.d.ts +3 -0
  118. package/dist/plugins/mdx/index.js +32 -0
  119. package/dist/plugins/mdx/types.d.ts +3 -0
  120. package/dist/plugins/mdx/types.js +1 -0
  121. package/dist/plugins/mdxlint/index.d.ts +3 -0
  122. package/dist/plugins/mdxlint/index.js +31 -0
  123. package/dist/plugins/mdxlint/types.d.ts +3 -0
  124. package/dist/plugins/mdxlint/types.js +1 -0
  125. package/dist/plugins/metro/index.d.ts +3 -11
  126. package/dist/plugins/metro/index.js +2 -1
  127. package/dist/plugins/mocha/index.d.ts +3 -14
  128. package/dist/plugins/mocha/index.js +2 -1
  129. package/dist/plugins/moonrepo/index.d.ts +3 -11
  130. package/dist/plugins/moonrepo/index.js +2 -1
  131. package/dist/plugins/msw/index.d.ts +3 -11
  132. package/dist/plugins/msw/index.js +2 -1
  133. package/dist/plugins/nano-staged/index.d.ts +3 -10
  134. package/dist/plugins/nano-staged/index.js +2 -1
  135. package/dist/plugins/nest/index.d.ts +3 -10
  136. package/dist/plugins/nest/index.js +2 -1
  137. package/dist/plugins/netlify/index.d.ts +3 -11
  138. package/dist/plugins/netlify/index.js +2 -1
  139. package/dist/plugins/next/index.d.ts +3 -10
  140. package/dist/plugins/next/index.js +2 -1
  141. package/dist/plugins/node/index.d.ts +3 -17
  142. package/dist/plugins/node/index.js +2 -1
  143. package/dist/plugins/node-modules-inspector/index.d.ts +3 -11
  144. package/dist/plugins/node-modules-inspector/index.js +2 -1
  145. package/dist/plugins/nodemon/index.d.ts +3 -10
  146. package/dist/plugins/nodemon/index.js +2 -1
  147. package/dist/plugins/npm-package-json-lint/index.d.ts +3 -11
  148. package/dist/plugins/npm-package-json-lint/index.js +2 -1
  149. package/dist/plugins/nuxt/index.d.ts +3 -12
  150. package/dist/plugins/nuxt/index.js +2 -1
  151. package/dist/plugins/nx/index.d.ts +3 -14
  152. package/dist/plugins/nx/index.js +2 -1
  153. package/dist/plugins/nyc/index.d.ts +3 -10
  154. package/dist/plugins/nyc/index.js +2 -1
  155. package/dist/plugins/oclif/index.d.ts +3 -10
  156. package/dist/plugins/oclif/index.js +2 -1
  157. package/dist/plugins/oxlint/index.d.ts +3 -11
  158. package/dist/plugins/oxlint/index.js +2 -1
  159. package/dist/plugins/playwright/index.d.ts +3 -15
  160. package/dist/plugins/playwright/index.js +2 -1
  161. package/dist/plugins/playwright-ct/index.d.ts +3 -10
  162. package/dist/plugins/playwright-ct/index.js +2 -1
  163. package/dist/plugins/playwright-test/index.d.ts +3 -12
  164. package/dist/plugins/playwright-test/index.js +2 -1
  165. package/dist/plugins/plop/index.d.ts +3 -8
  166. package/dist/plugins/plop/index.js +2 -1
  167. package/dist/plugins/pnpm/index.d.ts +3 -8
  168. package/dist/plugins/pnpm/index.js +2 -1
  169. package/dist/plugins/postcss/index.d.ts +3 -10
  170. package/dist/plugins/postcss/index.js +2 -1
  171. package/dist/plugins/preconstruct/index.d.ts +3 -10
  172. package/dist/plugins/preconstruct/index.js +2 -1
  173. package/dist/plugins/prettier/index.d.ts +3 -10
  174. package/dist/plugins/prettier/index.js +2 -1
  175. package/dist/plugins/prisma/index.d.ts +3 -13
  176. package/dist/plugins/prisma/index.js +10 -2
  177. package/dist/plugins/prisma/types.d.ts +3 -0
  178. package/dist/plugins/react-cosmos/index.d.ts +3 -11
  179. package/dist/plugins/react-cosmos/index.js +2 -1
  180. package/dist/plugins/react-router/index.d.ts +3 -10
  181. package/dist/plugins/react-router/index.js +3 -2
  182. package/dist/plugins/relay/index.d.ts +3 -15
  183. package/dist/plugins/relay/index.js +2 -1
  184. package/dist/plugins/release-it/index.d.ts +3 -10
  185. package/dist/plugins/release-it/index.js +2 -1
  186. package/dist/plugins/remark/index.d.ts +3 -11
  187. package/dist/plugins/remark/index.js +4 -2
  188. package/dist/plugins/remark/types.d.ts +1 -1
  189. package/dist/plugins/remix/index.d.ts +3 -9
  190. package/dist/plugins/remix/index.js +2 -1
  191. package/dist/plugins/rollup/index.d.ts +3 -10
  192. package/dist/plugins/rollup/index.js +2 -1
  193. package/dist/plugins/rsbuild/index.d.ts +3 -10
  194. package/dist/plugins/rsbuild/index.js +2 -1
  195. package/dist/plugins/rslib/index.d.ts +3 -10
  196. package/dist/plugins/rslib/index.js +2 -1
  197. package/dist/plugins/rspack/index.d.ts +3 -10
  198. package/dist/plugins/rspack/index.js +2 -1
  199. package/dist/plugins/rstest/index.d.ts +3 -10
  200. package/dist/plugins/rstest/index.js +2 -1
  201. package/dist/plugins/semantic-release/index.d.ts +3 -12
  202. package/dist/plugins/semantic-release/index.js +2 -1
  203. package/dist/plugins/sentry/index.d.ts +3 -8
  204. package/dist/plugins/sentry/index.js +2 -1
  205. package/dist/plugins/simple-git-hooks/index.d.ts +3 -10
  206. package/dist/plugins/simple-git-hooks/index.js +2 -1
  207. package/dist/plugins/size-limit/index.d.ts +3 -9
  208. package/dist/plugins/size-limit/index.js +2 -1
  209. package/dist/plugins/sst/index.d.ts +3 -9
  210. package/dist/plugins/sst/index.js +2 -1
  211. package/dist/plugins/starlight/index.d.ts +3 -9
  212. package/dist/plugins/starlight/index.js +2 -1
  213. package/dist/plugins/storybook/index.d.ts +3 -12
  214. package/dist/plugins/storybook/index.js +2 -1
  215. package/dist/plugins/stryker/index.d.ts +3 -10
  216. package/dist/plugins/stryker/index.js +2 -1
  217. package/dist/plugins/stylelint/index.d.ts +3 -10
  218. package/dist/plugins/stylelint/index.js +2 -1
  219. package/dist/plugins/svelte/index.d.ts +3 -10
  220. package/dist/plugins/svelte/index.js +2 -1
  221. package/dist/plugins/svgo/index.d.ts +3 -8
  222. package/dist/plugins/svgo/index.js +2 -1
  223. package/dist/plugins/syncpack/index.d.ts +3 -8
  224. package/dist/plugins/syncpack/index.js +2 -1
  225. package/dist/plugins/tailwind/index.d.ts +3 -8
  226. package/dist/plugins/tailwind/index.js +2 -1
  227. package/dist/plugins/travis/index.d.ts +3 -10
  228. package/dist/plugins/travis/index.js +2 -1
  229. package/dist/plugins/ts-node/index.d.ts +3 -14
  230. package/dist/plugins/ts-node/index.js +2 -1
  231. package/dist/plugins/tsdown/index.d.ts +3 -13
  232. package/dist/plugins/tsdown/index.js +2 -1
  233. package/dist/plugins/tsup/index.d.ts +3 -13
  234. package/dist/plugins/tsup/index.js +2 -1
  235. package/dist/plugins/tsx/index.d.ts +3 -15
  236. package/dist/plugins/tsx/index.js +2 -1
  237. package/dist/plugins/typedoc/index.d.ts +3 -16
  238. package/dist/plugins/typedoc/index.js +2 -1
  239. package/dist/plugins/typescript/index.d.ts +3 -18
  240. package/dist/plugins/typescript/index.js +2 -1
  241. package/dist/plugins/unbuild/index.d.ts +3 -10
  242. package/dist/plugins/unbuild/index.js +2 -1
  243. package/dist/plugins/unocss/index.d.ts +3 -8
  244. package/dist/plugins/unocss/index.js +2 -1
  245. package/dist/plugins/vercel-og/index.d.ts +3 -8
  246. package/dist/plugins/vercel-og/index.js +2 -1
  247. package/dist/plugins/vike/index.d.ts +3 -8
  248. package/dist/plugins/vike/index.js +2 -1
  249. package/dist/plugins/vite/index.d.ts +3 -10
  250. package/dist/plugins/vite/index.js +2 -1
  251. package/dist/plugins/vitest/index.d.ts +3 -16
  252. package/dist/plugins/vitest/index.js +2 -1
  253. package/dist/plugins/vue/index.d.ts +3 -10
  254. package/dist/plugins/vue/index.js +2 -1
  255. package/dist/plugins/webdriver-io/index.d.ts +3 -10
  256. package/dist/plugins/webdriver-io/index.js +2 -1
  257. package/dist/plugins/webpack/index.d.ts +3 -13
  258. package/dist/plugins/webpack/index.js +2 -1
  259. package/dist/plugins/wireit/index.d.ts +3 -10
  260. package/dist/plugins/wireit/index.js +2 -1
  261. package/dist/plugins/wrangler/index.d.ts +3 -10
  262. package/dist/plugins/wrangler/index.js +2 -1
  263. package/dist/plugins/xo/index.d.ts +3 -11
  264. package/dist/plugins/xo/index.js +2 -1
  265. package/dist/plugins/yarn/index.d.ts +3 -9
  266. package/dist/plugins/yarn/index.js +2 -1
  267. package/dist/plugins/yorkie/index.d.ts +3 -11
  268. package/dist/plugins/yorkie/index.js +2 -1
  269. package/dist/reporters/json.js +1 -0
  270. package/dist/reporters/util/util.d.ts +1 -1
  271. package/dist/schema/configuration.d.ts +24 -4
  272. package/dist/schema/configuration.js +1 -0
  273. package/dist/schema/plugins.d.ts +10 -0
  274. package/dist/schema/plugins.js +2 -0
  275. package/dist/types/PluginNames.d.ts +2 -2
  276. package/dist/types/PluginNames.js +2 -0
  277. package/dist/types/config.d.ts +2 -0
  278. package/dist/types/imports.d.ts +1 -3
  279. package/dist/types/issues.d.ts +1 -0
  280. package/dist/types/package-json.d.ts +12 -1
  281. package/dist/types.d.ts +1 -1
  282. package/dist/typescript/get-imports-and-exports.js +12 -8
  283. package/dist/typescript/visitors/dynamic-imports/importCall.js +23 -15
  284. package/dist/typescript/visitors/dynamic-imports/importType.js +7 -1
  285. package/dist/typescript/visitors/dynamic-imports/index.js +2 -1
  286. package/dist/typescript/visitors/dynamic-imports/jsDocType.js +13 -2
  287. package/dist/typescript/visitors/dynamic-imports/requireCall.js +13 -9
  288. package/dist/typescript/visitors/dynamic-imports/resolveCall.js +7 -1
  289. package/dist/typescript/visitors/dynamic-imports/urlConstructor.d.ts +3 -0
  290. package/dist/typescript/visitors/dynamic-imports/urlConstructor.js +24 -0
  291. package/dist/typescript/visitors/helpers.js +13 -2
  292. package/dist/typescript/visitors/imports/importDeclaration.js +6 -5
  293. package/dist/typescript/visitors/imports/importEqualsDeclaration.js +9 -1
  294. package/dist/typescript/visitors/imports/reExportDeclaration.js +10 -5
  295. package/dist/util/catalog.d.ts +6 -0
  296. package/dist/util/catalog.js +62 -0
  297. package/dist/util/cli-arguments.d.ts +1 -1
  298. package/dist/util/cli-arguments.js +3 -3
  299. package/dist/util/create-options.d.ts +27 -4
  300. package/dist/util/create-options.js +8 -5
  301. package/dist/util/errors.js +11 -1
  302. package/dist/util/get-included-issue-types.d.ts +1 -1
  303. package/dist/util/get-included-issue-types.js +3 -2
  304. package/dist/util/modules.js +26 -14
  305. package/dist/util/trace.js +4 -4
  306. package/dist/version.d.ts +1 -1
  307. package/dist/version.js +1 -1
  308. package/package.json +1 -1
  309. package/schema.json +52 -32
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { IMPORT_MODIFIERS } from '../../constants.js';
2
3
  export const isNotJS = (sourceFile) => !isJS(sourceFile);
3
4
  export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
4
5
  export const isModule = (sourceFile) => ts.isExternalModule(sourceFile);
@@ -13,7 +14,12 @@ export function getImportsFromPragmas(sourceFile) {
13
14
  const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
14
15
  const pos = jsxImportSourcePragma.range?.pos ?? 0;
15
16
  if (specifier)
16
- importNodes.push({ specifier, isTypeOnly: true, identifier: '__jsx', pos });
17
+ importNodes.push({
18
+ specifier,
19
+ identifier: '__jsx',
20
+ pos,
21
+ modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
22
+ });
17
23
  }
18
24
  const referencePragma = sourceFile.pragmas.get('reference');
19
25
  if (referencePragma) {
@@ -22,7 +28,12 @@ export function getImportsFromPragmas(sourceFile) {
22
28
  if (ref.arguments?.types) {
23
29
  const { value: specifier, pos } = ref.arguments.types;
24
30
  if (specifier)
25
- importNodes.push({ specifier, isTypeOnly: true, identifier: undefined, pos });
31
+ importNodes.push({
32
+ specifier,
33
+ identifier: undefined,
34
+ pos,
35
+ modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
36
+ });
26
37
  }
27
38
  }
28
39
  }
@@ -1,12 +1,12 @@
1
1
  import ts from 'typescript';
2
- import { IMPORT_STAR } from '../../../constants.js';
2
+ import { IMPORT_MODIFIERS, IMPORT_STAR } from '../../../constants.js';
3
3
  import { isDefaultImport } from '../../ast-helpers.js';
4
4
  import { importVisitor as visit } from '../index.js';
5
5
  export default visit(() => true, node => {
6
6
  if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) {
7
7
  const specifier = node.moduleSpecifier.text;
8
8
  if (!node.importClause) {
9
- return { specifier, identifier: undefined, pos: node.pos };
9
+ return { specifier, identifier: undefined, pos: node.pos, modifiers: IMPORT_MODIFIERS.NONE };
10
10
  }
11
11
  const imports = [];
12
12
  if (isDefaultImport(node)) {
@@ -16,6 +16,7 @@ export default visit(() => true, node => {
16
16
  specifier,
17
17
  symbol: node.importClause.symbol,
18
18
  pos: node.moduleSpecifier.pos,
19
+ modifiers: IMPORT_MODIFIERS.NONE,
19
20
  });
20
21
  }
21
22
  if (node.importClause?.namedBindings) {
@@ -25,8 +26,8 @@ export default visit(() => true, node => {
25
26
  symbol,
26
27
  specifier,
27
28
  identifier: IMPORT_STAR,
28
- isTypeOnly: node.importClause?.isTypeOnly,
29
29
  pos: symbol?.declarations[0]?.pos ?? node.pos,
30
+ modifiers: node.importClause?.isTypeOnly ? IMPORT_MODIFIERS.TYPE_ONLY : IMPORT_MODIFIERS.NONE,
30
31
  });
31
32
  }
32
33
  if (ts.isNamedImports(node.importClause.namedBindings)) {
@@ -36,8 +37,8 @@ export default visit(() => true, node => {
36
37
  identifier,
37
38
  specifier,
38
39
  symbol: element.symbol,
39
- isTypeOnly: node.importClause?.isTypeOnly,
40
40
  pos: element.getStart(),
41
+ modifiers: node.importClause?.isTypeOnly ? IMPORT_MODIFIERS.TYPE_ONLY : IMPORT_MODIFIERS.NONE,
41
42
  });
42
43
  }
43
44
  }
@@ -45,8 +46,8 @@ export default visit(() => true, node => {
45
46
  imports.push({
46
47
  specifier,
47
48
  identifier: undefined,
48
- isTypeOnly: node.importClause?.isTypeOnly,
49
49
  pos: node.importClause.namedBindings.pos,
50
+ modifiers: node.importClause?.isTypeOnly ? IMPORT_MODIFIERS.TYPE_ONLY : IMPORT_MODIFIERS.NONE,
50
51
  });
51
52
  }
52
53
  }
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { IMPORT_MODIFIERS } from '../../../constants.js';
2
3
  import { isNotJS } from '../helpers.js';
3
4
  import { importVisitor as visit } from '../index.js';
4
5
  export default visit(isNotJS, node => {
@@ -7,6 +8,13 @@ export default visit(isNotJS, node => {
7
8
  ts.isStringLiteralLike(node.moduleReference.expression)) {
8
9
  const specifier = node.moduleReference.expression.text;
9
10
  const alias = String(node.name.escapedText);
10
- return { specifier, alias, identifier: 'default', symbol: node.symbol, pos: node.moduleReference.expression.pos };
11
+ return {
12
+ specifier,
13
+ alias,
14
+ identifier: 'default',
15
+ symbol: node.symbol,
16
+ pos: node.moduleReference.expression.pos,
17
+ modifiers: IMPORT_MODIFIERS.NONE,
18
+ };
11
19
  }
12
20
  });
@@ -1,19 +1,24 @@
1
1
  import ts from 'typescript';
2
- import { IMPORT_STAR } from '../../../constants.js';
2
+ import { IMPORT_MODIFIERS, IMPORT_STAR } from '../../../constants.js';
3
3
  import { importVisitor as visit } from '../index.js';
4
4
  export default visit(() => true, node => {
5
5
  if (ts.isExportDeclaration(node)) {
6
6
  if (node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) {
7
7
  if (!node.exportClause) {
8
- return { identifier: IMPORT_STAR, specifier: node.moduleSpecifier.text, isReExport: true, pos: node.pos };
8
+ return {
9
+ identifier: IMPORT_STAR,
10
+ specifier: node.moduleSpecifier.text,
11
+ pos: node.pos,
12
+ modifiers: IMPORT_MODIFIERS.RE_EXPORT,
13
+ };
9
14
  }
10
15
  if (node.exportClause.kind === ts.SyntaxKind.NamespaceExport) {
11
16
  return {
12
17
  identifier: IMPORT_STAR,
13
18
  namespace: String(node.exportClause.name.text),
14
19
  specifier: node.moduleSpecifier.text,
15
- isReExport: true,
16
20
  pos: node.exportClause.name.pos,
21
+ modifiers: IMPORT_MODIFIERS.RE_EXPORT,
17
22
  };
18
23
  }
19
24
  const specifier = node.moduleSpecifier;
@@ -23,15 +28,15 @@ export default visit(() => true, node => {
23
28
  identifier: String(element.propertyName.text),
24
29
  alias: String(element.name.text),
25
30
  specifier: specifier.text,
26
- isReExport: true,
27
31
  pos: element.pos,
32
+ modifiers: IMPORT_MODIFIERS.RE_EXPORT,
28
33
  };
29
34
  }
30
35
  return {
31
36
  identifier: (element.propertyName ?? element.name).getText(),
32
37
  specifier: specifier.text,
33
- isReExport: true,
34
38
  pos: element.pos,
39
+ modifiers: IMPORT_MODIFIERS.RE_EXPORT,
35
40
  };
36
41
  });
37
42
  }
@@ -0,0 +1,6 @@
1
+ import type { CatalogContainer } from '../CatalogCounselor.js';
2
+ import type { PackageJson } from '../types/package-json.js';
3
+ export declare const DEFAULT_CATALOG = "default";
4
+ export declare const getCatalogContainer: (cwd: string, manifest: PackageJson, manifestPath: string, pnpmWorkspacePath?: string, pnpmWorkspace?: any) => Promise<CatalogContainer>;
5
+ export declare const parseCatalog: (container: CatalogContainer) => Set<string>;
6
+ export declare const extractCatalogReferences: (manifest: PackageJson) => Set<string>;
@@ -0,0 +1,62 @@
1
+ import { isFile } from './fs.js';
2
+ import { _load } from './loader.js';
3
+ import { basename, join } from './path.js';
4
+ export const DEFAULT_CATALOG = 'default';
5
+ export const getCatalogContainer = async (cwd, manifest, manifestPath, pnpmWorkspacePath, pnpmWorkspace) => {
6
+ const filePath = pnpmWorkspacePath ?? (isFile(join(cwd, '.yarnrc.yml')) ? join(cwd, '.yarnrc.yml') : manifestPath);
7
+ const yarnWorkspace = basename(filePath) === '.yarnrc.yml' ? await _load(filePath) : undefined;
8
+ const catalog = pnpmWorkspace?.catalog ??
9
+ yarnWorkspace?.catalog ??
10
+ manifest.catalog ??
11
+ ((!Array.isArray(manifest.workspaces) && manifest.workspaces?.catalog) || {});
12
+ const catalogs = pnpmWorkspace?.catalogs ??
13
+ yarnWorkspace?.catalogs ??
14
+ manifest.catalogs ??
15
+ ((!Array.isArray(manifest.workspaces) && manifest.workspaces?.catalogs) || {});
16
+ return { filePath, catalog, catalogs };
17
+ };
18
+ const extractEntries = (catalog) => {
19
+ if (catalog && typeof catalog === 'object')
20
+ return Object.keys(catalog).map(entry => `${DEFAULT_CATALOG}:${entry}`);
21
+ return [];
22
+ };
23
+ const extractNamedEntries = (catalogs) => {
24
+ const entries = new Set();
25
+ if (catalogs && typeof catalogs === 'object') {
26
+ for (const [catalogName, catalog] of Object.entries(catalogs)) {
27
+ for (const name of Object.keys(catalog))
28
+ entries.add(`${catalogName}:${name}`);
29
+ }
30
+ }
31
+ return entries;
32
+ };
33
+ export const parseCatalog = (container) => {
34
+ const entries = new Set();
35
+ if ('catalog' in container)
36
+ for (const id of extractEntries(container.catalog))
37
+ entries.add(id);
38
+ if ('catalogs' in container)
39
+ for (const id of extractNamedEntries(container.catalogs))
40
+ entries.add(id);
41
+ return entries;
42
+ };
43
+ export const extractCatalogReferences = (manifest) => {
44
+ const catalogReferences = new Set();
45
+ const checkDependencies = (dependencies) => {
46
+ if (!dependencies)
47
+ return;
48
+ for (const [name, version] of Object.entries(dependencies)) {
49
+ if (typeof version === 'string' && version.startsWith('catalog:')) {
50
+ const catalogName = version.slice('catalog:'.length) || DEFAULT_CATALOG;
51
+ catalogReferences.add([catalogName, name].join(':'));
52
+ }
53
+ }
54
+ };
55
+ checkDependencies(manifest.dependencies);
56
+ checkDependencies(manifest.devDependencies);
57
+ checkDependencies(manifest.peerDependencies);
58
+ checkDependencies(manifest.optionalDependencies);
59
+ checkDependencies(manifest.resolutions);
60
+ checkDependencies(manifest.pnpm?.overrides);
61
+ return catalogReferences;
62
+ };
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
1
+ export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates, catalog\n(2) Fixable issue types: dependencies, exports, types, catalog\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
2
2
  export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
3
3
  export default function parseCLIArgs(): {
4
4
  cache?: boolean | undefined;
@@ -16,7 +16,7 @@ Options:
16
16
  --no-gitignore Don't use .gitignore
17
17
  --include Report only provided issue type(s), can be comma-separated or repeated (1)
18
18
  --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
19
- --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved
19
+ --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog
20
20
  --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
21
21
  --files Shortcut for --include files
22
22
  --fix Fix issues
@@ -48,8 +48,8 @@ Options:
48
48
  -h, --help Print this help text
49
49
  -V, --version Print version
50
50
 
51
- (1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
52
- (2) Fixable issue types: dependencies, exports, types
51
+ (1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates, catalog
52
+ (2) Fixable issue types: dependencies, exports, types, catalog
53
53
 
54
54
  Examples:
55
55
 
@@ -5,6 +5,7 @@ interface CreateOptions extends Partial<Options> {
5
5
  }
6
6
  export declare const createOptions: (options: CreateOptions) => Promise<{
7
7
  cacheLocation: string;
8
+ catalog: import("../CatalogCounselor.js").CatalogContainer;
8
9
  config: string | undefined;
9
10
  configFilePath: string | undefined;
10
11
  cwd: string;
@@ -19,6 +20,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
19
20
  isDebug: boolean;
20
21
  isDisableConfigHints: boolean;
21
22
  isFix: boolean;
23
+ isFixCatalog: boolean;
22
24
  isFixDependencies: boolean;
23
25
  isFixFiles: boolean | undefined;
24
26
  isFixUnusedExports: boolean;
@@ -264,6 +266,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
264
266
  entry?: string | string[] | undefined;
265
267
  project?: string | string[] | undefined;
266
268
  } | undefined;
269
+ mdx?: string | boolean | string[] | {
270
+ config?: string | string[] | undefined;
271
+ entry?: string | string[] | undefined;
272
+ project?: string | string[] | undefined;
273
+ } | undefined;
274
+ mdxlint?: string | boolean | string[] | {
275
+ config?: string | string[] | undefined;
276
+ entry?: string | string[] | undefined;
277
+ project?: string | string[] | undefined;
278
+ } | undefined;
267
279
  metro?: string | boolean | string[] | {
268
280
  config?: string | string[] | undefined;
269
281
  entry?: string | string[] | undefined;
@@ -845,6 +857,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
845
857
  entry?: string | string[] | undefined;
846
858
  project?: string | string[] | undefined;
847
859
  } | undefined;
860
+ mdx?: string | boolean | string[] | {
861
+ config?: string | string[] | undefined;
862
+ entry?: string | string[] | undefined;
863
+ project?: string | string[] | undefined;
864
+ } | undefined;
865
+ mdxlint?: string | boolean | string[] | {
866
+ config?: string | string[] | undefined;
867
+ entry?: string | string[] | undefined;
868
+ project?: string | string[] | undefined;
869
+ } | undefined;
848
870
  metro?: string | boolean | string[] | {
849
871
  config?: string | string[] | undefined;
850
872
  entry?: string | string[] | undefined;
@@ -1211,10 +1233,10 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1211
1233
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1212
1234
  includeEntryExports?: boolean | undefined;
1213
1235
  }> | undefined;
1214
- include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[] | undefined;
1215
- exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[] | undefined;
1236
+ include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates" | "catalog")[] | undefined;
1237
+ exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates" | "catalog")[] | undefined;
1216
1238
  $schema?: string | undefined;
1217
- rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates", "error" | "warn" | "off">> | undefined;
1239
+ rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates" | "catalog", "error" | "warn" | "off">> | undefined;
1218
1240
  entry?: string | string[] | undefined;
1219
1241
  project?: string | string[] | undefined;
1220
1242
  paths?: Record<string, string[]> | undefined;
@@ -1225,7 +1247,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1225
1247
  ignoreMembers?: (string | RegExp)[] | undefined;
1226
1248
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1227
1249
  ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
1228
- ignoreIssues?: Record<string, ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[]> | undefined;
1250
+ ignoreIssues?: Record<string, ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates" | "catalog")[]> | undefined;
1229
1251
  ignoreWorkspaces?: string[] | undefined;
1230
1252
  includeEntryExports?: boolean | undefined;
1231
1253
  compilers?: Record<string, true | ((filename: string, contents: string) => string) | ((filename: string, contents: string) => Promise<string>)> | undefined;
@@ -1249,6 +1271,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1249
1271
  enumMembers: import("../types/issues.js").IssueSeverity;
1250
1272
  classMembers: import("../types/issues.js").IssueSeverity;
1251
1273
  duplicates: import("../types/issues.js").IssueSeverity;
1274
+ catalog: import("../types/issues.js").IssueSeverity;
1252
1275
  _files: import("../types/issues.js").IssueSeverity;
1253
1276
  };
1254
1277
  tags: import("../types/options.js").Tags;
@@ -1,9 +1,10 @@
1
1
  import { partitionCompilers } from '../compilers/index.js';
2
2
  import { KNIP_CONFIG_LOCATIONS } from '../constants.js';
3
3
  import { knipConfigurationSchema } from '../schema/configuration.js';
4
+ import { getCatalogContainer } from './catalog.js';
4
5
  import { ConfigurationError } from './errors.js';
5
6
  import { findFile, loadJSON } from './fs.js';
6
- import { getIncludedIssueTypes, shorthandDeps, shorthandFiles, shorthandTypes } from './get-included-issue-types.js';
7
+ import { getIncludedIssueTypes, shorthandDeps, shorthandExports, shorthandFiles } from './get-included-issue-types.js';
7
8
  import { defaultRules } from './issue-initializers.js';
8
9
  import { loadResolvedConfigFile } from './load-config.js';
9
10
  import { _load } from './loader.js';
@@ -34,9 +35,9 @@ export const createOptions = async (options) => {
34
35
  const parsedConfig = knipConfigurationSchema.parse(partitionCompilers(loadedConfig));
35
36
  if (!configFilePath && manifest.knip)
36
37
  configFilePath = manifestPath;
37
- const pnpmWorkspacesPath = findFile(cwd, 'pnpm-workspace.yaml');
38
- const pnpmWorkspaces = pnpmWorkspacesPath && (await _load(pnpmWorkspacesPath));
39
- const workspaces = pnpmWorkspaces?.packages ??
38
+ const pnpmWorkspacePath = findFile(cwd, 'pnpm-workspace.yaml');
39
+ const pnpmWorkspace = pnpmWorkspacePath && (await _load(pnpmWorkspacePath));
40
+ const workspaces = pnpmWorkspace?.packages ??
40
41
  (manifest.workspaces
41
42
  ? Array.isArray(manifest.workspaces)
42
43
  ? manifest.workspaces
@@ -54,7 +55,7 @@ export const createOptions = async (options) => {
54
55
  includeOverrides: [
55
56
  ...(options.includedIssueTypes ?? parsedCLIArgs.include ?? []),
56
57
  ...(parsedCLIArgs.dependencies ? shorthandDeps : []),
57
- ...(parsedCLIArgs.exports ? shorthandTypes : []),
58
+ ...(parsedCLIArgs.exports ? shorthandExports : []),
58
59
  ...(parsedCLIArgs.files ? shorthandFiles : []),
59
60
  ],
60
61
  });
@@ -69,6 +70,7 @@ export const createOptions = async (options) => {
69
70
  const tags = splitTags(parsedCLIArgs.tags ?? options.tags ?? parsedConfig.tags ?? parsedCLIArgs['experimental-tags'] ?? []);
70
71
  return {
71
72
  cacheLocation: parsedCLIArgs['cache-location'] ?? join(cwd, 'node_modules', '.cache', 'knip'),
73
+ catalog: await getCatalogContainer(cwd, manifest, manifestPath, pnpmWorkspacePath, pnpmWorkspace),
72
74
  config: parsedCLIArgs.config,
73
75
  configFilePath,
74
76
  cwd,
@@ -83,6 +85,7 @@ export const createOptions = async (options) => {
83
85
  isDebug: parsedCLIArgs.debug ?? false,
84
86
  isDisableConfigHints: parsedCLIArgs['no-config-hints'] || isProduction || Boolean(parsedCLIArgs.workspace),
85
87
  isFix: parsedCLIArgs.fix ?? options.isFix ?? isFixFiles ?? fixTypes.length > 0,
88
+ isFixCatalog: fixTypes.length === 0 || fixTypes.includes('catalog'),
86
89
  isFixDependencies: fixTypes.length === 0 || fixTypes.includes('dependencies'),
87
90
  isFixFiles,
88
91
  isFixUnusedExports: fixTypes.length === 0 || fixTypes.includes('exports'),
@@ -9,6 +9,16 @@ export const hasErrorCause = (error) => !isZodErrorLike(error) && error.cause in
9
9
  export const isConfigurationError = (error) => error instanceof ConfigurationError;
10
10
  export const getKnownErrors = (error) => {
11
11
  if (isZodErrorLike(error))
12
- return [...error.issues].map(error => new Error(error.message));
12
+ return [...error.issues].map(error => {
13
+ let message = error.message;
14
+ const details = [];
15
+ if (error.path.length > 0)
16
+ details.push(`location: ${error.path.join('.')}`);
17
+ if (typeof error.expected === 'string')
18
+ details.push(`expected: ${error.expected}`);
19
+ if (details.length > 0)
20
+ message += ` (${details.join(', ')})`;
21
+ return new Error(message);
22
+ });
13
23
  return [error];
14
24
  };
@@ -8,7 +8,7 @@ type GetIncludedIssueTypesOptions = {
8
8
  };
9
9
  export declare const defaultExcludedIssueTypes: string[];
10
10
  export declare const shorthandDeps: string[];
11
- export declare const shorthandTypes: string[];
11
+ export declare const shorthandExports: string[];
12
12
  export declare const shorthandFiles: string[];
13
13
  export declare const getIncludedIssueTypes: (options: GetIncludedIssueTypesOptions) => Report;
14
14
  export {};
@@ -3,8 +3,8 @@ import { ConfigurationError } from './errors.js';
3
3
  export const defaultExcludedIssueTypes = ['classMembers', 'nsExports', 'nsTypes'];
4
4
  const defaultIssueTypes = ISSUE_TYPES.filter(type => !defaultExcludedIssueTypes.includes(type));
5
5
  const normalize = (values) => values.flatMap(value => value.split(','));
6
- export const shorthandDeps = ['dependencies', 'optionalPeerDependencies', 'unlisted', 'binaries', 'unresolved'];
7
- export const shorthandTypes = ['types', 'nsTypes', 'enumMembers', 'duplicates'];
6
+ export const shorthandDeps = ['dependencies', 'unlisted', 'binaries', 'unresolved', 'catalog'];
7
+ export const shorthandExports = ['exports', 'types', 'enumMembers', 'duplicates'];
8
8
  export const shorthandFiles = ['files'];
9
9
  export const getIncludedIssueTypes = (options) => {
10
10
  const incl = normalize(options.includeOverrides ?? []);
@@ -19,6 +19,7 @@ export const getIncludedIssueTypes = (options) => {
19
19
  const _exclude = [...excl, ...excludes];
20
20
  if (options.isProduction) {
21
21
  _exclude.push('devDependencies');
22
+ _exclude.push('catalog');
22
23
  }
23
24
  else {
24
25
  if (_include.includes('dependencies'))
@@ -38,24 +38,36 @@ export const getPackageFromDefinitelyTyped = (typedDependency) => {
38
38
  }
39
39
  return typedDependency;
40
40
  };
41
+ const CHAR_EXCLAMATION = 33;
42
+ const CHAR_DASH = 45;
43
+ const CHAR_SLASH = 47;
44
+ const CHAR_COLON = 58;
45
+ const CHAR_HASH = 35;
46
+ const CHAR_QUESTION = 63;
41
47
  export const sanitizeSpecifier = (specifier) => {
42
48
  if (isBuiltin(specifier) || isAbsolute(specifier) || specifier.startsWith(PROTOCOL_VIRTUAL))
43
49
  return specifier;
44
- let s = specifier;
45
- let end = s.length;
46
- let i = 0;
47
- while (i < s.length && (s[i] === '!' || s[i] === '-'))
48
- i++;
49
- s = s.substring(i);
50
- for (let j = 0; j < s.length; j++) {
51
- const char = s[j];
52
- if (char === '!' || char === '?' || (char === '#' && j > 0)) {
53
- end = j;
50
+ const len = specifier.length;
51
+ let start = 0;
52
+ let end = len;
53
+ let colon = -1;
54
+ let sawSlash = false;
55
+ for (let i = 0; i < len; i++) {
56
+ const ch = specifier.charCodeAt(i);
57
+ if (i === start && (ch === CHAR_EXCLAMATION || ch === CHAR_DASH)) {
58
+ start++;
59
+ continue;
60
+ }
61
+ if (ch === CHAR_SLASH && colon === -1) {
62
+ sawSlash = true;
63
+ }
64
+ if (colon === -1 && ch === CHAR_COLON && !sawSlash) {
65
+ colon = i;
66
+ }
67
+ if (ch === CHAR_EXCLAMATION || ch === CHAR_QUESTION || (ch === CHAR_HASH && i > start)) {
68
+ end = i;
54
69
  break;
55
70
  }
56
71
  }
57
- s = s.substring(0, end);
58
- if (s.includes(':') && !s.includes('/'))
59
- s = s.split(':')[0];
60
- return s;
72
+ return colon !== -1 && colon < end ? specifier.slice(start, colon) : specifier.slice(start, end);
61
73
  };
@@ -9,14 +9,14 @@ const getPadding = (level, levels) => {
9
9
  padding += levels.has(i) ? `${picocolors.dim('│')} ` : ' ';
10
10
  return padding;
11
11
  };
12
- const renderTrace = (node, level = 0, levels = new Set()) => {
12
+ const renderTrace = (node, options, level = 0, levels = new Set()) => {
13
13
  let index = 0;
14
14
  const size = node.children.size;
15
15
  const padding = getPadding(level, levels);
16
16
  for (const child of node.children) {
17
17
  const isLast = ++index === size;
18
18
  const hasRef = child.hasRef === true;
19
- const rel = child.filePath;
19
+ const rel = toRelative(child.filePath, options.cwd);
20
20
  const file = hasRef ? rel : picocolors.dim(rel);
21
21
  const suffix = (hasRef ? HAS_REF : '') + (child.isEntry ? IS_ENTRY : '');
22
22
  const text = `${padding}${picocolors.dim(isLast ? '└─' : '├─')} ${file}${suffix}`;
@@ -26,7 +26,7 @@ const renderTrace = (node, level = 0, levels = new Set()) => {
26
26
  levels.add(level);
27
27
  if (isLast)
28
28
  levels.delete(level);
29
- renderTrace(child, level + 1, levels);
29
+ renderTrace(child, options, level + 1, levels);
30
30
  }
31
31
  }
32
32
  };
@@ -40,7 +40,7 @@ export const printTrace = (node, filePath, options, identifier) => {
40
40
  const suffix = (node.isEntry ? IS_ENTRY : '') + (node.children.size === 0 ? HAS_NO_REF : '');
41
41
  const header = `${toRelative(filePath, options.cwd)}${identifier ? `:${identifier}` : ''}${suffix}`;
42
42
  console.log(header);
43
- renderTrace(node);
43
+ renderTrace(node, options);
44
44
  console.log();
45
45
  };
46
46
  export const createNode = (filePath, { hasRef = false, isEntry = false, identifier } = {}) => ({
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.67.1";
1
+ export declare const version = "5.69.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.67.1';
1
+ export const version = '5.69.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.67.1",
3
+ "version": "5.69.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {