knip 2.14.3 → 2.15.1

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 CHANGED
@@ -394,6 +394,7 @@ Knip contains a growing list of plugins:
394
394
  - [Sentry][plugin-sentry]
395
395
  - [Storybook][plugin-storybook]
396
396
  - [Stryker][plugin-stryker]
397
+ - [Stylelint][plugin-stylelint]
397
398
  - [Svelte][plugin-svelte]
398
399
  - [Tailwind][plugin-tailwind]
399
400
  - [TypeDoc][plugin-typedoc]
@@ -579,6 +580,29 @@ export const split = function () {};
579
580
 
580
581
  Knip does not report public exports and types as unused.
581
582
 
583
+ ## Ignore exports used in file
584
+
585
+ In files with multiple exports, some of them might be used only internally. If these exports should not be reported,
586
+ there is a `ignoreExportsUsedInFile` option available. With this option enabled, you don't need to mark everything
587
+ `@public` separately and when something is no longer used internally, it will still be reported.
588
+
589
+ ```json
590
+ {
591
+ "ignoreExportsUsedInFile": true
592
+ }
593
+ ```
594
+
595
+ In a more fine-grained manner, you can also ignore only specific issue types:
596
+
597
+ ```json
598
+ {
599
+ "ignoreExportsUsedInFile": {
600
+ "interface": true,
601
+ "type": true
602
+ }
603
+ }
604
+ ```
605
+
582
606
  ## Include exports in entry files
583
607
 
584
608
  When a repository is self-contained or private, you may want to include entry files when reporting unused exports:
@@ -768,6 +792,7 @@ Special thanks to the wonderful people who have contributed to this project:
768
792
  [plugin-sentry]: ./src/plugins/sentry
769
793
  [plugin-storybook]: ./src/plugins/storybook
770
794
  [plugin-stryker]: ./src/plugins/stryker
795
+ [plugin-stylelint]: ./src/plugins/stylelint
771
796
  [plugin-svelte]: ./src/plugins/svelte
772
797
  [plugin-tailwind]: ./src/plugins/tailwind
773
798
  [plugin-typedoc]: ./src/plugins/typedoc
@@ -437,6 +437,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
437
437
  entry?: string | string[] | undefined;
438
438
  project?: string | string[] | undefined;
439
439
  }>]>>;
440
+ stylelint: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
441
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
442
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
443
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
444
+ }, "strip", z.ZodTypeAny, {
445
+ config?: string | string[] | undefined;
446
+ entry?: string | string[] | undefined;
447
+ project?: string | string[] | undefined;
448
+ }, {
449
+ config?: string | string[] | undefined;
450
+ entry?: string | string[] | undefined;
451
+ project?: string | string[] | undefined;
452
+ }>]>>;
440
453
  tailwind: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
441
454
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
442
455
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -682,6 +695,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
682
695
  entry?: string | string[] | undefined;
683
696
  project?: string | string[] | undefined;
684
697
  } | undefined;
698
+ stylelint?: string | false | string[] | {
699
+ config?: string | string[] | undefined;
700
+ entry?: string | string[] | undefined;
701
+ project?: string | string[] | undefined;
702
+ } | undefined;
685
703
  tailwind?: string | false | string[] | {
686
704
  config?: string | string[] | undefined;
687
705
  entry?: string | string[] | undefined;
@@ -879,6 +897,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
879
897
  entry?: string | string[] | undefined;
880
898
  project?: string | string[] | undefined;
881
899
  } | undefined;
900
+ stylelint?: string | false | string[] | {
901
+ config?: string | string[] | undefined;
902
+ entry?: string | string[] | undefined;
903
+ project?: string | string[] | undefined;
904
+ } | undefined;
882
905
  tailwind?: string | false | string[] | {
883
906
  config?: string | string[] | undefined;
884
907
  entry?: string | string[] | undefined;
@@ -1326,6 +1349,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
1326
1349
  entry?: string | string[] | undefined;
1327
1350
  project?: string | string[] | undefined;
1328
1351
  }>]>>;
1352
+ stylelint: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
1353
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1354
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1355
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1356
+ }, "strip", z.ZodTypeAny, {
1357
+ config?: string | string[] | undefined;
1358
+ entry?: string | string[] | undefined;
1359
+ project?: string | string[] | undefined;
1360
+ }, {
1361
+ config?: string | string[] | undefined;
1362
+ entry?: string | string[] | undefined;
1363
+ project?: string | string[] | undefined;
1364
+ }>]>>;
1329
1365
  tailwind: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
1330
1366
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1331
1367
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1586,6 +1622,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1586
1622
  entry?: string | string[] | undefined;
1587
1623
  project?: string | string[] | undefined;
1588
1624
  } | undefined;
1625
+ stylelint?: string | false | string[] | {
1626
+ config?: string | string[] | undefined;
1627
+ entry?: string | string[] | undefined;
1628
+ project?: string | string[] | undefined;
1629
+ } | undefined;
1589
1630
  tailwind?: string | false | string[] | {
1590
1631
  config?: string | string[] | undefined;
1591
1632
  entry?: string | string[] | undefined;
@@ -1777,6 +1818,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1777
1818
  entry?: string | string[] | undefined;
1778
1819
  project?: string | string[] | undefined;
1779
1820
  } | undefined;
1821
+ stylelint?: string | false | string[] | {
1822
+ config?: string | string[] | undefined;
1823
+ entry?: string | string[] | undefined;
1824
+ project?: string | string[] | undefined;
1825
+ } | undefined;
1780
1826
  tailwind?: string | false | string[] | {
1781
1827
  config?: string | string[] | undefined;
1782
1828
  entry?: string | string[] | undefined;
@@ -1989,6 +2035,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1989
2035
  entry?: string | string[] | undefined;
1990
2036
  project?: string | string[] | undefined;
1991
2037
  } | undefined;
2038
+ stylelint?: string | false | string[] | {
2039
+ config?: string | string[] | undefined;
2040
+ entry?: string | string[] | undefined;
2041
+ project?: string | string[] | undefined;
2042
+ } | undefined;
1992
2043
  tailwind?: string | false | string[] | {
1993
2044
  config?: string | string[] | undefined;
1994
2045
  entry?: string | string[] | undefined;
@@ -2180,6 +2231,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2180
2231
  entry?: string | string[] | undefined;
2181
2232
  project?: string | string[] | undefined;
2182
2233
  } | undefined;
2234
+ stylelint?: string | false | string[] | {
2235
+ config?: string | string[] | undefined;
2236
+ entry?: string | string[] | undefined;
2237
+ project?: string | string[] | undefined;
2238
+ } | undefined;
2183
2239
  tailwind?: string | false | string[] | {
2184
2240
  config?: string | string[] | undefined;
2185
2241
  entry?: string | string[] | undefined;
@@ -93,6 +93,7 @@ const pluginsSchema = z.object({
93
93
  sentry: pluginSchema,
94
94
  storybook: pluginSchema,
95
95
  stryker: pluginSchema,
96
+ stylelint: pluginSchema,
96
97
  tailwind: pluginSchema,
97
98
  typedoc: pluginSchema,
98
99
  typescript: pluginSchema,
@@ -15,7 +15,7 @@ export class PrincipalFactory {
15
15
  options.compilerOptions = mergePaths(cwd, compilerOptions, paths);
16
16
  const principal = this.findReusablePrincipal(compilerOptions);
17
17
  if (principal) {
18
- this.linkPrincipal(principal, cwd, compilerOptions.paths);
18
+ this.linkPrincipal(principal, cwd, compilerOptions);
19
19
  return principal.principal;
20
20
  }
21
21
  else {
@@ -25,6 +25,8 @@ export class PrincipalFactory {
25
25
  findReusablePrincipal(compilerOptions) {
26
26
  const workspacePaths = compilerOptions?.paths ? Object.keys(compilerOptions.paths) : [];
27
27
  const principal = Array.from(this.principals).find(principal => {
28
+ if (compilerOptions.pathsBasePath && principal.principal.compilerOptions.pathsBasePath)
29
+ return false;
28
30
  if (compilerOptions.baseUrl === principal.principal.compilerOptions.baseUrl) {
29
31
  return workspacePaths.every(p => !principal.pathKeys.has(p));
30
32
  }
@@ -32,7 +34,10 @@ export class PrincipalFactory {
32
34
  });
33
35
  return principal;
34
36
  }
35
- linkPrincipal(principal, cwd, paths) {
37
+ linkPrincipal(principal, cwd, compilerOptions) {
38
+ const { pathsBasePath, paths } = compilerOptions;
39
+ if (pathsBasePath)
40
+ principal.principal.compilerOptions.pathsBasePath = pathsBasePath;
36
41
  Object.keys(paths ?? {}).forEach(p => principal.pathKeys.add(p));
37
42
  principal.principal.compilerOptions.paths = { ...principal.principal.compilerOptions.paths, ...paths };
38
43
  principal.cwds.add(cwd);
@@ -50,7 +50,7 @@ export declare class WorkspaceWorker {
50
50
  peerDependencies: PeerDependencies;
51
51
  installedBinaries: InstalledBinaries;
52
52
  referencedDependencies: ReferencedDependencies;
53
- enabledPlugins: ("ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
53
+ enabledPlugins: ("ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
54
54
  }>;
55
55
  }
56
56
  export {};
@@ -1,4 +1,4 @@
1
- import parse from 'bash-parser';
1
+ import parse from '@ericcornelissen/bash-parser';
2
2
  import parseArgs from 'minimist';
3
3
  import { debugLogObject } from '../util/debug.js';
4
4
  import * as FallbackResolver from './resolvers/fallback.js';
@@ -30,6 +30,7 @@ export * as semanticRelease from './semantic-release/index.js';
30
30
  export * as sentry from './sentry/index.js';
31
31
  export * as storybook from './storybook/index.js';
32
32
  export * as stryker from './stryker/index.js';
33
+ export * as stylelint from './stylelint/index.js';
33
34
  export * as svelte from './svelte/index.js';
34
35
  export * as tailwind from './tailwind/index.js';
35
36
  export * as typedoc from './typedoc/index.js';
@@ -30,6 +30,7 @@ export * as semanticRelease from './semantic-release/index.js';
30
30
  export * as sentry from './sentry/index.js';
31
31
  export * as storybook from './storybook/index.js';
32
32
  export * as stryker from './stryker/index.js';
33
+ export * as stylelint from './stylelint/index.js';
33
34
  export * as svelte from './svelte/index.js';
34
35
  export * as tailwind from './tailwind/index.js';
35
36
  export * as typedoc from './typedoc/index.js';
@@ -18,15 +18,22 @@ const resolveExtensibleConfig = async (configFilePath) => {
18
18
  return config;
19
19
  };
20
20
  const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
21
- const config = configFilePath.endsWith('package.json')
21
+ let config = configFilePath.endsWith('package.json')
22
22
  ? manifest.jest
23
23
  : await resolveExtensibleConfig(configFilePath);
24
+ if (typeof config === 'function')
25
+ config = await config();
24
26
  if (!config)
25
27
  return [];
26
28
  const replaceRootDir = (name) => name.includes('<rootDir>') ? join(cwd, name.replace(/^.*<rootDir>/, '')) : name;
27
29
  const presets = (config.preset ? [config.preset] : []).map(preset => isInternal(preset) ? preset : join(preset, 'jest-preset'));
28
30
  const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : [];
29
31
  const resolvers = config.resolver ? [config.resolver] : [];
32
+ const reporters = config.reporters
33
+ ? config.reporters
34
+ .map(reporter => (typeof reporter === 'string' ? reporter : reporter[0]))
35
+ .filter(reporter => !['default', 'github-actions', 'summary'].includes(reporter))
36
+ : [];
30
37
  const watchPlugins = config.watchPlugins?.map(watchPlugin => (typeof watchPlugin === 'string' ? watchPlugin : watchPlugin[0])) ?? [];
31
38
  const setupFiles = config.setupFiles ?? [];
32
39
  const setupFilesAfterEnv = config.setupFilesAfterEnv ?? [];
@@ -40,6 +47,7 @@ const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
40
47
  ...presets,
41
48
  ...environments,
42
49
  ...resolvers,
50
+ ...reporters,
43
51
  ...watchPlugins,
44
52
  ...setupFiles,
45
53
  ...setupFilesAfterEnv,
@@ -0,0 +1,6 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "Stylelint";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,22 @@
1
+ import { isInternal } from '../../util/path.js';
2
+ import { timerify } from '../../util/Performance.js';
3
+ import { hasDependency, load } from '../../util/plugin.js';
4
+ export const NAME = 'Stylelint';
5
+ export const ENABLERS = ['stylelint'];
6
+ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
+ export const CONFIG_FILE_PATTERNS = [
8
+ '.stylelintrc',
9
+ '.stylelintrc.{cjs,js,json,yaml,yml}',
10
+ 'stylelint.config.{cjs,mjs,js}',
11
+ ];
12
+ const findPluginDependencies = async (configFilePath, { manifest }) => {
13
+ const config = configFilePath.endsWith('package.json')
14
+ ? manifest.stylelint
15
+ : await load(configFilePath);
16
+ if (!config)
17
+ return [];
18
+ const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
19
+ const plugins = config.plugins ? [config.plugins].flat().filter(plugin => !isInternal(plugin)) : [];
20
+ return [...extend, ...plugins];
21
+ };
22
+ export const findDependencies = timerify(findPluginDependencies);
@@ -0,0 +1,4 @@
1
+ export type PluginConfig = {
2
+ extends?: string | string[];
3
+ plugins?: string[];
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -182,6 +182,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
182
182
  entry?: string | string[] | undefined;
183
183
  project?: string | string[] | undefined;
184
184
  } | undefined;
185
+ stylelint?: string | false | string[] | {
186
+ config?: string | string[] | undefined;
187
+ entry?: string | string[] | undefined;
188
+ project?: string | string[] | undefined;
189
+ } | undefined;
185
190
  tailwind?: string | false | string[] | {
186
191
  config?: string | string[] | undefined;
187
192
  entry?: string | string[] | undefined;
@@ -373,6 +378,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
373
378
  entry?: string | string[] | undefined;
374
379
  project?: string | string[] | undefined;
375
380
  } | undefined;
381
+ stylelint?: string | false | string[] | {
382
+ config?: string | string[] | undefined;
383
+ entry?: string | string[] | undefined;
384
+ project?: string | string[] | undefined;
385
+ } | undefined;
376
386
  tailwind?: string | false | string[] | {
377
387
  config?: string | string[] | undefined;
378
388
  entry?: string | string[] | undefined;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.14.3";
1
+ export declare const version = "2.15.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.14.3';
1
+ export const version = '2.15.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.14.3",
3
+ "version": "2.15.1",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",
@@ -33,22 +33,22 @@
33
33
  "docs:format": "remark README.md docs/*.md .github/*.md src/plugins/*/README.md -o",
34
34
  "qa": "npm run lint && npm run build && npm run knip && npm run knip:production && npm test",
35
35
  "release": "release-it",
36
- "create-plugin": "tsx ./scripts/create-new-plugin.ts",
37
- "postcreate-plugin": "prettier schema.json src/configuration-validator.ts --write --config .prettierrc --loglevel silent"
36
+ "create-plugin": "tsx --no-warnings ./scripts/create-new-plugin.ts",
37
+ "postcreate-plugin": "prettier schema.json src/ConfigurationValidator.ts --write --config .prettierrc --loglevel silent"
38
38
  },
39
39
  "files": [
40
40
  "dist",
41
41
  "schema.json"
42
42
  ],
43
43
  "dependencies": {
44
+ "@ericcornelissen/bash-parser": "^0.5.2",
44
45
  "@npmcli/map-workspaces": "^3.0.4",
45
46
  "@snyk/github-codeowners": "^1.1.0",
46
- "bash-parser": "^0.5.0",
47
47
  "chalk": "^5.2.0",
48
48
  "easy-table": "^1.2.0",
49
49
  "fast-glob": "^3.2.12",
50
50
  "globby": "^13.1.3",
51
- "jiti": "1.18.2",
51
+ "jiti": "1.19.1",
52
52
  "js-yaml": "^4.1.0",
53
53
  "micromatch": "^4.0.5",
54
54
  "minimist": "^1.2.8",
@@ -60,30 +60,30 @@
60
60
  "zod-validation-error": "1.3.1"
61
61
  },
62
62
  "devDependencies": {
63
- "@jest/types": "29.5.0",
64
- "@npmcli/package-json": "3.1.1",
65
- "@release-it/bumper": "4.0.2",
66
- "@types/eslint": "8.40.2",
63
+ "@jest/types": "29.6.1",
64
+ "@npmcli/package-json": "4.0.0",
65
+ "@release-it/bumper": "5.0.0",
66
+ "@types/eslint": "8.44.0",
67
67
  "@types/js-yaml": "4.0.5",
68
68
  "@types/micromatch": "4.0.2",
69
69
  "@types/minimist": "1.2.2",
70
- "@types/node": "20.3.1",
70
+ "@types/node": "20.4.1",
71
71
  "@types/npmcli__map-workspaces": "3.0.1",
72
72
  "@types/webpack": "5.28.1",
73
- "@typescript-eslint/eslint-plugin": "5.60.0",
74
- "@typescript-eslint/parser": "5.60.0",
73
+ "@typescript-eslint/eslint-plugin": "5.61.0",
74
+ "@typescript-eslint/parser": "5.61.0",
75
75
  "c8": "8.0.0",
76
- "eslint": "8.42.0",
76
+ "eslint": "8.44.0",
77
77
  "eslint-import-resolver-typescript": "3.5.5",
78
78
  "eslint-plugin-import": "2.27.5",
79
79
  "eslint-plugin-n": "16.0.1",
80
- "glob": "10.3.0",
81
- "prettier": "2.8.8",
82
- "release-it": "15.11.0",
80
+ "glob": "10.3.3",
81
+ "prettier": "3.0.0",
82
+ "release-it": "16.1.0",
83
83
  "remark-cli": "11.0.0",
84
84
  "remark-preset-webpro": "0.0.3",
85
85
  "tsx": "3.12.7",
86
- "type-fest": "3.12.0"
86
+ "type-fest": "3.13.0"
87
87
  },
88
88
  "engines": {
89
89
  "node": ">=16.17.0 <17 || >=18.6.0"
package/schema.json CHANGED
@@ -320,6 +320,10 @@
320
320
  "title": "Stryker plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/stryker/README.md)",
321
321
  "$ref": "#/definitions/plugin"
322
322
  },
323
+ "stylelint": {
324
+ "title": "stylelint plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/stylelint/README.md)",
325
+ "$ref": "#/definitions/plugin"
326
+ },
323
327
  "svelte": {
324
328
  "title": "svelte plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/svelte/README.md)",
325
329
  "$ref": "#/definitions/plugin"