Skip to content

Commit

Permalink
Merge pull request #324 from inversify/chore/knip-integration
Browse files Browse the repository at this point in the history
knip integration
  • Loading branch information
notaphplover authored Jan 19, 2025
2 parents b3ed988 + fbbe539 commit 3026b56
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Lint affected source files
run: pnpm run lint --filter=[origin/${{github.base_ref}}]

- name: Check for unused code
run: pnpm run unused --no-config-hints

- name: Get current git commit hash
id: get-git-commit-hash
run: |
Expand Down
36 changes: 30 additions & 6 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ type RecordValues<T> = T extends Record<any, infer U> ? U : never;

type WorkspaceProjectConfig = RecordValues<Required<KnipConfig["workspaces"]>>;

const defaultWorkspaceProjectConfig: WorkspaceProjectConfig = {
const defaultWorkspaceProjectConfig: WorkspaceProjectConfig & {
entry: string[];
ignoreDependencies: string[];
project: string[];
} = {
entry: [
"{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
"src/{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
],
ignoreDependencies: ["ts-loader", "tslib"],
project: [
"**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}!",
"!jest.config.stryker.mjs",
Expand All @@ -17,31 +22,50 @@ const defaultWorkspaceProjectConfig: WorkspaceProjectConfig = {
};

export default {
commitlint: {
config: "config/commitlint/commitlint.config.js",
},
ignoreWorkspaces: ["packages/docs/services/inversify-site"],
workspaces: {
".": {
entry: ["config/commitlint/commitlint.config.js"],
entry: [],
ignoreDependencies: defaultWorkspaceProjectConfig.ignoreDependencies,
project: [],
},
"packages/container/libraries/*": defaultWorkspaceProjectConfig,
"packages/container/tools/*": defaultWorkspaceProjectConfig,
"packages/docs/services/*": defaultWorkspaceProjectConfig,
"packages/docs/tools/*": defaultWorkspaceProjectConfig,
"packages/docs/tools/inversify-code-examples": {
entry: ["src/examples/**/*.ts", "src/scripts/generateExamples.mts"],
ignoreDependencies: [
...defaultWorkspaceProjectConfig.ignoreDependencies,
"@docusaurus/Link",
"@docusaurus/plugin-content-docs",
"@docusaurus/useDocusaurusContext",
"@theme/*",
],
project: defaultWorkspaceProjectConfig.project,
},
"packages/docs/tools/*": defaultWorkspaceProjectConfig,
"packages/foundation/libraries/*": defaultWorkspaceProjectConfig,
"packages/foundation/tools/*": defaultWorkspaceProjectConfig,
"packages/foundation/tools/prettier-config": {
entry: ["{cjs,esm}/index.{js,d.ts}"],
ignoreDependencies: defaultWorkspaceProjectConfig.ignoreDependencies,
project: defaultWorkspaceProjectConfig.project,
},
"packages/container/tools/e2e-tests": {
entry: [
"config/*.mjs",
"src/*/parameters/*.ts",
"src/*/step-definitions/*.ts",
"src/app/hooks/*.ts",
],
project: [
...(defaultWorkspaceProjectConfig.project as string[]),
"!config/*",
ignoreDependencies: [
...defaultWorkspaceProjectConfig.ignoreDependencies,
"ts-node",
],
project: [...defaultWorkspaceProjectConfig.project, "!config/*"],
},
},
} satisfies KnipConfig;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"build": "turbo run build",
"commit": "commit",
"format": "turbo run format",
"knip": "knip",
"lint": "turbo run lint",
"prepare": "husky && turbo telemetry disable",
"prerelease": "pnpm run build",
Expand All @@ -49,6 +48,7 @@
"test": "turbo run test",
"test:e2e": "turbo run test:e2e",
"test:e2e:cjs": "turbo run test:e2e:cjs",
"test:e2e:esm": "turbo run test:e2e:esm"
"test:e2e:esm": "turbo run test:e2e:esm",
"unused": "knip"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class InversifyContainerError extends Error {
value: unknown,
kind: InversifyContainerErrorKind,
): value is InversifyContainerError {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return InversifyContainerError.is(value) && value.kind === kind;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export enum InversifyContainerErrorKind {
invalidOperation,
unknown,
}
1 change: 1 addition & 0 deletions packages/container/libraries/strongly-typed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"eslint": "9.18.0",
"jest": "29.7.0",
"prettier": "3.4.2",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
"rollup": "4.30.1",
"ts-loader": "9.5.2",
Expand Down
1 change: 1 addition & 0 deletions packages/docs/services/inversify-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "3.7.0",
"@docusaurus/types": "3.7.0",
"@eslint/js": "9.18.0",
"@types/react": "18.3.18",
"eslint": "9.18.0",
"eslint-plugin-prettier": "5.2.3",
Expand Down
1 change: 1 addition & 0 deletions packages/docs/tools/inversify-code-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
"ts-jest": "29.2.5",
"tslib": "2.8.1",
"typescript": "5.7.3"
},
"homepage": "https://inversify.io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"lib": ["ES2022"],
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
Expand Down

0 comments on commit 3026b56

Please sign in to comment.