Add knip unused code & dependency analyser (#1441)

This commit is contained in:
Michael Telatynski 2024-01-18 10:10:51 +00:00 committed by GitHub
parent ae187445af
commit efde228da6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 697 additions and 351 deletions

View file

@ -138,6 +138,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
- name: Install Deps

View file

@ -67,6 +67,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
env:
# Workaround for https://github.com/actions/setup-node/issues/317

View file

@ -55,6 +55,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
# Does not need branch matching as only analyses this layer

View file

@ -53,6 +53,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
- name: Install Deps

View file

@ -96,6 +96,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
# Does not need branch matching as only analyses this layer

View file

@ -12,6 +12,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
# Does not need branch matching as only analyses this layer
@ -33,6 +34,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
# Does not need branch matching as only analyses this layer
@ -50,6 +52,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
# Does not need branch matching as only analyses this layer
@ -58,3 +61,20 @@ jobs:
- name: Run Linter
run: "yarn lint:workflows"
analyse_dead_code:
name: "Analyse Dead Code"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: "yarn"
- name: Install Deps
run: "yarn install --frozen-lockfile"
- name: Run linter
run: "yarn run lint:knip"

16
knip.ts Normal file
View file

@ -0,0 +1,16 @@
import { KnipConfig } from "knip";
export default {
entry: ["src/electron-main.ts", "src/preload.ts", "electron-builder.js", ".eslintrc-*.js", "scripts/**", "hak/**"],
project: ["**/*.{js,ts}"],
ignoreDependencies: [
// Brought in via hak scripts
"keytar",
"matrix-seshat",
// Needed by `electron-builder`
"electron-builder-squirrel-windows",
// Required for `action-validator`
"@action-validator/*",
],
ignoreBinaries: ["jq", "scripts/in-docker.sh"],
} satisfies KnipConfig;

View file

@ -13,7 +13,7 @@
"license": "Apache-2.0",
"files": [],
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"scripts": {
"i18n": "matrix-gen-i18n && yarn i18n:sort && yarn i18n:lint",
@ -41,6 +41,7 @@
"lint:types:scripts": "tsc --noEmit -p scripts/tsconfig.json",
"lint:types:hak": "tsc --noEmit -p hak/tsconfig.json",
"lint:workflows": "find .github/workflows -type f \\( -iname '*.yaml' -o -iname '*.yml' \\) | xargs -I {} sh -c 'echo \"Linting {}\"; action-validator \"{}\"'",
"lint:knip": "knip",
"build:native": "yarn run hak",
"build:native:universal": "yarn run hak --target x86_64-apple-darwin fetchandbuild && yarn run hak --target aarch64-apple-darwin fetchandbuild && yarn run hak --target x86_64-apple-darwin --target aarch64-apple-darwin copyandlink",
"build:32": "yarn run build:ts && yarn run build:res && electron-builder --ia32",
@ -80,17 +81,17 @@
"@babel/preset-typescript": "^7.18.6",
"@electron/asar": "^3.2.3",
"@electron/fuses": "^1.7.0",
"@playwright/test": "1.40.1",
"@types/auto-launch": "^5.0.1",
"@types/counterpart": "^0.18.1",
"@types/minimist": "^1.2.1",
"@types/mkdirp": "^1.0.2",
"@types/node": "16.18.70",
"@types/node": "18.19.8",
"@types/pacote": "^11.1.1",
"@types/tar": "^6.1.3",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"allchange": "^1.0.6",
"app-builder-lib": "24.11.0",
"chokidar": "^3.5.2",
"detect-libc": "^2.0.0",
@ -105,8 +106,8 @@
"eslint-plugin-matrix-org": "^1.0.0",
"eslint-plugin-unicorn": "^50.0.0",
"find-npm-prefix": "^1.0.2",
"fs-extra": "^11.0.0",
"glob": "^10.0.0",
"knip": "^4.0.1",
"matrix-web-i18n": "^3.1.3",
"mkdirp": "^3.0.0",
"node-pre-gyp": "^0.17.0",
@ -115,15 +116,13 @@
"rimraf": "^5.0.0",
"tar": "^6.1.2",
"ts-node": "^10.9.1",
"typescript": "5.3.3",
"@electron/fuses": "^1.7.0",
"@playwright/test": "1.40.1"
"typescript": "5.3.3"
},
"hakDependencies": {
"matrix-seshat": "^3.0.1",
"keytar": "^7.9.0"
},
"resolutions": {
"@types/node": "16.18.70"
"@types/node": "18.19.8"
}
}

View file

@ -24,10 +24,6 @@ const FALLBACK_LOCALE = "en";
type TranslationKey = TKey<typeof EN>;
export function _td(text: TranslationKey): TranslationKey {
return text;
}
type SubstitutionValue = number | string;
interface Variables {

988
yarn.lock

File diff suppressed because it is too large Load diff