Skip to content

Commit 5572cec

Browse files
Convert find-deadcode to a script
1 parent 08675e6 commit 5572cec

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@
17321732
"format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix",
17331733
"lint": "eslint . --ext .js,.ts,.tsx --max-warnings=0",
17341734
"lint:markdown": "markdownlint-cli2 \"../../**/*.{md,mdx}\" \"!**/node_modules/**\" \"!**/.vscode-test/**\" \"!**/build/cli/v*/**\"",
1735-
"find-deadcode": "ts-unused-exports tsconfig.deadcode.json --showLineNumber --excludePathsFromReport=$(find src test -type f '(' -name jest.config.ts -or -name 'index.tsx' -or -name 'index.ts' ')' -print0 | tr '\\0' ';')'gulpfile.ts/;src/stories/;test/vscode-tests/jest-runner-installed-extensions.ts'",
1735+
"find-deadcode": "ts-node scripts/find-deadcode.ts",
17361736
"format-staged": "lint-staged",
17371737
"storybook": "storybook dev -p 6006",
17381738
"build-storybook": "storybook build",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { basename, join, relative, resolve } from "path";
2+
import analyzeTsConfig from "ts-unused-exports";
3+
import { containsPath, pathsEqual } from "../src/common/files";
4+
import { exit } from "process";
5+
6+
function ignoreFile(file: string): boolean {
7+
return (
8+
containsPath("gulpfile.ts", file) ||
9+
containsPath(join("src", "stories"), file) ||
10+
pathsEqual(
11+
join("test", "vscode-tests", "jest-runner-installed-extensions.ts"),
12+
file,
13+
) ||
14+
basename(file) === "jest.config.ts" ||
15+
basename(file) === "index.tsx" ||
16+
basename(file) === "index.ts"
17+
);
18+
}
19+
20+
function main() {
21+
const repositoryRoot = resolve(join(__dirname, ".."));
22+
23+
const result = analyzeTsConfig("tsconfig.deadcode.json");
24+
let foundUnusedExports = false;
25+
26+
for (const [filepath, exportNameAndLocations] of Object.entries(result)) {
27+
const relativeFilepath = relative(repositoryRoot, filepath);
28+
29+
if (ignoreFile(relativeFilepath)) {
30+
continue;
31+
}
32+
33+
foundUnusedExports = true;
34+
35+
console.log(relativeFilepath);
36+
for (const exportNameAndLocation of exportNameAndLocations) {
37+
console.log(` ${exportNameAndLocation.exportName}`);
38+
}
39+
console.log();
40+
}
41+
42+
if (foundUnusedExports) {
43+
exit(1);
44+
}
45+
}
46+
47+
main();

0 commit comments

Comments
 (0)