-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unused dependency checker and fixer #23989
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
/*! | ||||||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||||||
* Licensed under the MIT License. | ||||||
*/ | ||||||
|
||||||
// Enable TypeScript type-checking for this file. | ||||||
// See https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check | ||||||
// @ts-check | ||||||
|
||||||
// Import the shared config from the root of the repo. | ||||||
import sharedConfig from "../../../knip.base.ts"; | ||||||
|
||||||
export default { | ||||||
include: [...sharedConfig.include], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ignoreDependencies: [ | ||||||
...sharedConfig.ignoreDependencies, | ||||||
|
||||||
// Oclif plugins are used dynamically at runtime. | ||||||
"@oclif/plugin-*", | ||||||
// Danger is used at runtime in the dangerfile. | ||||||
"danger", | ||||||
// Types from this package are used in markdown.ts. | ||||||
"mdast", | ||||||
// This is needed by the fluid-build task integration in policy-check. | ||||||
"tslib", | ||||||
], | ||||||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think most of the removed deps are actually used. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ | |
"build:test:esm": "tsc --project ./src/test/tsconfig.json", | ||
"check:biome": "biome check .", | ||
"check:format": "npm run check:biome", | ||
"check:knip": "knip --no-config-hints", | ||
"knip:fix": "knip --fix --fix-type dependencies --no-config-hints", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's mildly annoying the fix-types aren't part of config. DOesn't seem to be supported. |
||
"ci:build:docs": "api-extractor run", | ||
"clean": "rimraf --glob dist lib oclif.manifest.json \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc", | ||
"clean:manifest": "rimraf --glob oclif.manifest.json", | ||
|
@@ -79,105 +81,63 @@ | |
"temp-directory": "nyc/.nyc_output" | ||
}, | ||
"dependencies": { | ||
"@andrewbranch/untar.js": "^1.0.3", | ||
"@fluid-tools/build-infrastructure": "workspace:~", | ||
"@fluid-tools/version-tools": "workspace:~", | ||
Comment on lines
-82
to
-84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is definitely a false positive. Does it understand the |
||
"@fluidframework/build-tools": "workspace:~", | ||
"@fluidframework/bundle-size-tools": "workspace:~", | ||
"@inquirer/prompts": "^7.0.1", | ||
Comment on lines
-86
to
-87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likely a false positive. |
||
"@microsoft/api-extractor": "^7.47.11", | ||
"@oclif/core": "^4.0.30", | ||
"@oclif/plugin-autocomplete": "^3.2.7", | ||
"@oclif/plugin-commands": "^4.1.5", | ||
"@oclif/plugin-help": "^6.2.16", | ||
"@oclif/plugin-not-found": "^3.2.24", | ||
"@octokit/core": "^5.2.0", | ||
"@octokit/rest": "^21.0.2", | ||
"@rushstack/node-core-library": "^5.9.0", | ||
"async": "^3.2.6", | ||
"azure-devops-node-api": "^11.2.0", | ||
"change-case": "^3.1.0", | ||
"cosmiconfig": "^8.3.6", | ||
"danger": "^12.3.3", | ||
"date-fns": "^2.30.0", | ||
"debug": "^4.3.7", | ||
"execa": "^5.1.1", | ||
"fflate": "^0.8.2", | ||
"fs-extra": "^11.2.0", | ||
"github-slugger": "^2.0.0", | ||
"globby": "^11.1.0", | ||
"gray-matter": "^4.0.3", | ||
"human-id": "^4.1.1", | ||
"issue-parser": "^7.0.1", | ||
"json5": "^2.2.3", | ||
"jssm": "^5.104.1", | ||
"jszip": "^3.10.1", | ||
"latest-version": "^9.0.0", | ||
"mdast": "^3.0.0", | ||
"mdast-util-heading-range": "^4.0.0", | ||
"mdast-util-to-string": "^4.0.0", | ||
"minimatch": "^7.4.6", | ||
"npm-check-updates": "^16.14.20", | ||
"oclif": "^4.15.16", | ||
"picocolors": "^1.1.1", | ||
"prettier": "~3.2.5", | ||
"prompts": "^2.4.2", | ||
"read-pkg-up": "^7.0.1", | ||
"remark": "^15.0.1", | ||
"remark-gfm": "^4.0.0", | ||
"remark-github": "^12.0.0", | ||
"remark-github-beta-blockquote-admonitions": "^3.1.1", | ||
"remark-toc": "^9.0.0", | ||
"replace-in-file": "^7.2.0", | ||
"resolve.exports": "^2.0.2", | ||
"semver": "^7.6.3", | ||
"semver-utils": "^1.1.4", | ||
"simple-git": "^3.27.0", | ||
"sort-json": "^2.0.1", | ||
"sort-package-json": "1.57.0", | ||
"strip-ansi": "^6.0.1", | ||
"table": "^6.8.2", | ||
"ts-morph": "^22.0.0", | ||
"type-fest": "^2.19.0", | ||
"unist-util-visit": "^5.0.0", | ||
"xml2js": "^0.5.0" | ||
"type-fest": "^2.19.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "~1.9.3", | ||
"@fluidframework/build-common": "^2.0.3", | ||
"@fluidframework/eslint-config-fluid": "^5.4.0", | ||
"@oclif/test": "^4.1.0", | ||
"@types/async": "^3.2.24", | ||
"@types/chai": "^4.3.20", | ||
"@types/chai-arrays": "^2.0.3", | ||
"@types/debug": "^4.1.12", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/issue-parser": "^3.0.5", | ||
"@types/mdast": "^4.0.4", | ||
"@types/mocha": "^10.0.9", | ||
"@types/node": "^18.19.59", | ||
"@types/prettier": "^2.7.3", | ||
"@types/prompts": "^2.4.9", | ||
"@types/semver": "^7.5.8", | ||
"@types/semver-utils": "^1.1.3", | ||
"@types/sort-json": "^2.0.3", | ||
"@types/unist": "^3.0.3", | ||
"@types/xml2js": "^0.4.14", | ||
"c8": "^7.14.0", | ||
"chai": "^4.5.0", | ||
"chai-arrays": "^2.2.0", | ||
"concurrently": "^8.2.2", | ||
"copyfiles": "^2.4.1", | ||
"eslint": "~8.57.0", | ||
"eslint-config-oclif": "^5.2.1", | ||
"eslint-config-oclif-typescript": "^3.1.12", | ||
"eslint-config-prettier": "~9.1.0", | ||
"jssm-viz-cli": "^5.101.0", | ||
"knip": "^5.45.0", | ||
"mocha": "^10.7.3", | ||
"mocha-multi-reporters": "^1.5.1", | ||
"mocked-env": "^1.3.5", | ||
"rimraf": "^4.4.1", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.8.0", | ||
"typescript": "~5.4.5" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
// Enable TypeScript type-checking for this file. | ||
// See https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check | ||
// @ts-check | ||
|
||
export default { | ||
|
||
// Knip has the capability to report many issue types. For now we are only using "dependencies" to check for unused dependency declaration in package.json | ||
// In future, we can expand our requirements to report other issue types as well, for example: unused files, or unused exports etc. | ||
// See: https://knip.dev/reference/cli#--include | ||
include: ["dependencies"], | ||
ignoreDependencies: [ | ||
// The following deps are actually in use, but depcheck reports them unused. | ||
|
||
// These packages are used in the CI pipelines. | ||
"mocha-multi-reporters", | ||
"moment", | ||
|
||
// The following deps are reported as missing, but they are available. | ||
|
||
// We use a 'hack' to make plugins from the shared eslint config available to our packages, those these deps are not | ||
// directly needed in the package. | ||
"@typescript-eslint/eslint-plugin", | ||
"eslint-config-prettier", | ||
"eslint-import-resolver-typescript", | ||
"eslint-plugin-tsdoc", | ||
"eslint-plugin-unicorn", | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a doc comment with a type directive here so we can get type checking on the config object. Something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right it's typescript - just
import type
then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you can remove the ts-check-related comments.