Skip to content

Commit e1bbbd6

Browse files
Merge pull request #2631 from github/robertbrignull/deadcode_ci
Add check for deadcode for CI
2 parents ef27730 + 5572cec commit e1bbbd6

5 files changed

Lines changed: 215 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ jobs:
110110
run: |
111111
npm run lint:scenarios
112112
113+
- name: Find deadcode
114+
working-directory: extensions/ql-vscode
115+
run: |
116+
npm run find-deadcode
117+
113118
unit-test:
114119
name: Unit Test
115120
runs-on: ${{ matrix.os }}

extensions/ql-vscode/package-lock.json

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +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-node scripts/find-deadcode.ts",
17351736
"format-staged": "lint-staged",
17361737
"storybook": "storybook dev -p 6006",
17371738
"build-storybook": "storybook build",
@@ -1882,6 +1883,7 @@
18821883
"ts-loader": "^9.4.2",
18831884
"ts-node": "^10.7.0",
18841885
"ts-protoc-gen": "^0.9.0",
1886+
"ts-unused-exports": "^9.0.5",
18851887
"typescript": "^5.0.2",
18861888
"webpack": "^5.76.0",
18871889
"webpack-cli": "^5.0.1"
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();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["**/*.ts*"],
4+
"exclude": ["node_modules"]
5+
}

0 commit comments

Comments
 (0)