Skip to content

Commit 752135e

Browse files
webprojakebailey
andauthored
Remove unused exports & dead code (using Knip) (microsoft#56817)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent f7833b2 commit 752135e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1238
-683
lines changed

.github/workflows/ci.yml

+14
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ jobs:
8383
- name: Linter
8484
run: npm run lint
8585

86+
knip:
87+
runs-on: ubuntu-latest
88+
89+
steps:
90+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
91+
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
92+
with:
93+
node-version: '*'
94+
check-latest: true
95+
- run: npm ci
96+
97+
- name: Unused exports
98+
run: npm run knip
99+
86100
format:
87101
runs-on: ubuntu-latest
88102

Herebyfile.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ export const checkFormat = task({
565565
run: () => exec(process.execPath, ["node_modules/dprint/bin.js", "check"], { ignoreStdout: true }),
566566
});
567567

568+
export const knip = task({
569+
name: "knip",
570+
description: "Runs knip.",
571+
dependencies: [generateDiagnostics],
572+
run: () => exec(process.execPath, ["node_modules/knip/bin/knip.js", "--tags=+internal,-knipignore", "--exclude=duplicates,enumMembers", ...(cmdLineOptions.fix ? ["--fix"] : [])]),
573+
});
574+
568575
const { main: cancellationToken, watch: watchCancellationToken } = entrypointBuildTask({
569576
name: "cancellation-token",
570577
project: "src/cancellationToken",

knip.jsonc

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"includeEntryExports": true,
4+
"entry": [
5+
"Herebyfile.mjs",
6+
"src/cancellationToken/cancellationToken.ts",
7+
"src/testRunner/_namespaces/Harness.ts",
8+
"src/tsc/tsc.ts",
9+
"src/tsserver/server.ts",
10+
"src/typescript/typescript.ts",
11+
"src/typingsInstaller/nodeTypingsInstaller.ts",
12+
"src/watchGuard/watchGuard.ts",
13+
14+
"src/testRunner/tests.ts",
15+
"src/testRunner/_namespaces/Harness.ts",
16+
17+
// The rest of the entry files, mostly to track used dependencies:
18+
".eslint-plugin-local.cjs",
19+
".gulp.js",
20+
"scripts/eslint/{rules,tests}/*.cjs",
21+
"scripts/*.{cjs,mjs}"
22+
],
23+
"project": [
24+
"src/**",
25+
"scripts/**",
26+
"!src/lib/**/*.d.ts"
27+
],
28+
"ignore": [
29+
"scripts/failed-tests.d.cts"
30+
],
31+
"ignoreDependencies": ["c8", "eslint-formatter-autolinkable-stylish", "mocha-fivemat-progress-reporter"],
32+
"ignoreExportsUsedInFile": {
33+
"enum": true,
34+
"interface": true,
35+
"type": true
36+
},
37+
"mocha": false
38+
}

0 commit comments

Comments
 (0)