Skip to content

Commit

Permalink
ci: add dead code analysis (#318)
Browse files Browse the repository at this point in the history
## CI

- Add Knip for dead code analysis
- Lint unused code
- Enable strict Nx lint checks
  • Loading branch information
LayZeeDK authored Aug 31, 2024
2 parents 798c5a7 + 502c3cf commit 3d49dc6
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 9 deletions.
16 changes: 13 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"banTransitiveDependencies": true,
"checkNestedExternalImports": true,
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
Expand All @@ -18,13 +20,18 @@
}
]
}
]
],
"no-unused-labels": "error",
"no-unused-private-class-members": "error"
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-unused-vars": "error"
}
},
{
"files": ["*.ts"],
Expand All @@ -33,7 +40,10 @@
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
"rules": {
"no-unused-expressions": "error",
"no-unused-vars": "error"
}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ jobs:
run: yarn nx workspace-lint
- name: Lint all projects
run: yarn lint

dead-code:
name: Dead code analysis
runs-on: ubuntu-latest

steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Set up Node.js and Yarn
uses: ./.github/actions/setup-node
- name: Install package dependencies
run: yarn install --frozen-lockfile --no-interactive
- name: Dead code analysis
run: yarn knip

test:
name: Test
runs-on: ubuntu-latest
Expand Down
50 changes: 50 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"angular": {
"config": ["project.json"]
},
"include": ["nsExports", "nsTypes", "classMembers"],
"ignoreDependencies": [
"@angular-eslint/eslint-plugin",
"@angular-eslint/template-parser",
"@angular/cli",
"@angular/compiler",
"@angular/language-service",
"@ngrx/component-store",
"@nrwl/angular:application",
"@nrwl/angular:component",
"@nrwl/angular:library",
"@nrwl/cli",
"@nrwl/workspace",
"@schematics/angular:component",
"@typescript-eslint/eslint-plugin",
"ng-packagr",
"postcss",
"postcss-import",
"postcss-preset-env",
"postcss-url",
"prettier",
"ts-node",
"zone.js"
],
"jest": {
"config": ["jest.{config,preset}.{js,ts,mjs,cjs,json}", "package.json"],
"entry": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)",
"test-setup.[jt]s?(x)"
]
},
"nx": {
"config": ["nx.json", "project.json", "packages/**/project.json"]
},
"typescript": {
"config": ["tsconfig.json", "tsconfig.*.json"]
},
"workspaces": {
"packages/*": {
"entry": "src/index.ts",
"project": "**/*.ts"
}
}
}
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"build": "nx run-many --target=build --all",
"ci": "yarn lint && yarn test && yarn build",
"knip": "knip",
"lint": "nx workspace-lint && nx run-many --target=lint --all --max-warnings=0",
"nx": "nx",
"test": "nx run-many --target=test --all"
Expand Down Expand Up @@ -47,14 +48,15 @@
"@nrwl/linter": "15.4.8",
"@nrwl/workspace": "15.4.8",
"@types/jest": "28.1.8",
"@types/node": "16.11.7",
"@types/node": "18.19.47",
"@typescript-eslint/eslint-plugin": "5.36.1",
"@typescript-eslint/parser": "5.36.1",
"eslint": "8.15.0",
"eslint-config-prettier": "8.1.0",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.1",
"jest-preset-angular": "12.2.3",
"knip": "5.28.0",
"ng-packagr": "15.0.3",
"nx": "15.4.8",
"postcss": "8.4.18",
Expand All @@ -65,5 +67,11 @@
"ts-jest": "28.0.8",
"ts-node": "10.9.1",
"typescript": "4.8.4"
},
"resolutions": {
"jest/typescript": "4.8.4",
"knip/typescript": "5.5.4",
"ts-jest/typescript": "4.8.4",
"ts-node/typescript": "4.8.4"
}
}
Loading

0 comments on commit 3d49dc6

Please sign in to comment.