Skip to content

Commit

Permalink
chore: add knip (#8192)
Browse files Browse the repository at this point in the history
* chore: add knip

* chore: sync lockfile

* chore: bump knip

* ci: run knip in ci workflow

* ci: run knip as part of lint job

* refactor: replace `testRegex` with `testMatch`

* refactor: use satisfies in knip config

* chore: fix path to rule-tester fixtures

* chore: add dummypkg as knip workspace

* chore: get rid of  json-schema

* chore: fix knip issues in packages/website

* chore: sync lockfile

* chore: add missed merge stuff

* chore: install @jest/types in the root workspace

* chore: partially fix issues for website-eslint

* chore: fix knip issues for packages/website-eslint

* chore: add ncp resolution to the root package.json

* chore: wip wip wip

* chore: fix misspelling + handle few knip issues

* chore: finally (?)

* chore: expand ignoreDependencies regular expressions

* chore: revert unrelated changes

* chore: try to minimise docusaurus-related changes

* chore: remove extra entry

* chore: bump knip to 4.0.2

* wip

* add types to jest config

* yarn lint --fix

* add knip to ci

* !!!

* Revert "!!!"

This reverts commit 36fa481.

* revert yarn dedupe

* sed -i 's| -p tsconfig.json||g'

* update todo comment in eslint.config.js

* Update knip.ts

Co-authored-by: Josh Goldberg ✨ <[email protected]>

* oops

---------

Co-authored-by: Josh Goldberg ✨ <[email protected]>
  • Loading branch information
auvred and JoshuaKGoldberg authored May 13, 2024
1 parent 8acb8d4 commit f53fece
Show file tree
Hide file tree
Showing 27 changed files with 642 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
lint-task: ['lint', 'typecheck']
lint-task: ['lint', 'typecheck', 'knip']
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
3 changes: 1 addition & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check

// TODO - https://github.com/eslint/eslint/pull/17909
// either it gets back-ported (https://github.com/eslint/eslint/issues/17966) or we wait till v9
// TODO - https://github.com/nrwl/nx/issues/22576

/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigPromise} */
const config = (async () => (await import('./eslint.config.mjs')).default)();
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

// @ts-check
const { getJestProjects } = require('@nx/jest');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
projects: getJestProjects(),
};
128 changes: 128 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import type { KnipConfig } from 'knip';

export default {
rules: {
classMembers: 'off',
duplicates: 'off',
enumMembers: 'off',
exports: 'off',
nsExports: 'off',
nsTypes: 'off',
types: 'off',
unresolved: 'off',
},
workspaces: {
'.': {
ignoreDependencies: [
'@babel/code-frame',
'@babel/core',
'@babel/eslint-parser',
'@babel/parser',
'@babel/types',
'@nx/workspace',
'cross-fetch',
'glob',
'husky',
'jest-specific-snapshot',
'make-dir',
'ncp',
'tmp',

// imported in eslint.config.js
'@typescript-eslint/utils',
// imported in eslint.config.mjs
'@typescript-eslint/eslint-plugin-internal',
],
entry: ['tools/release/changelog-renderer.js'],
ignoreBinaries: [
// https://github.com/webpro/knip/issues/433
'stylelint',
],
},
'packages/ast-spec': {
ignore: [
'src/**/fixtures/**',
'tests/*.type-test.ts',
// @typescript-eslint/typescript-estree is not listed in dependencies to avoid circular dependency errors
// You can check a more detailed explanation in this file
'tests/util/parsers/typescript-estree-import.ts',
],
},
'packages/eslint-plugin': {
ignore: ['tests/fixtures/**'],
},
'packages/eslint-plugin-internal': {
ignore: ['tests/fixtures/**'],
},
'packages/integration-tests': {
ignore: ['fixtures/**'],
},
'packages/parser': {
ignore: ['tests/fixtures/**'],
},
'packages/scope-manager': {
ignore: ['tests/fixtures/**'],
},
'packages/type-utils': {
ignore: ['tests/fixtures/**'],
},
'packages/typescript-estree': {
entry: ['src/use-at-your-own-risk.ts'],
ignore: ['tests/fixtures/**'],
},
'packages/website': {
entry: [
'docusaurus.config.mts',
'src/pages/**/*.tsx',

// imported in MDX docs
'src/components/**/*.tsx',

// used by Docusaurus
'src/theme/**/*.tsx',
'src/theme/prism-include-languages.js',
],
ignoreDependencies: [
// used in MDX docs
'raw-loader',

// it's imported only as type (esquery types are forked and defined in packages/website/typings/esquery.d.ts)
'esquery',

'@babel/runtime',
'@docusaurus/mdx-loader',
'@docusaurus/types',
'@docusaurus/plugin-content-docs',
'@docusaurus/theme-search-algolia',
'@docusaurus/ExecutionEnvironment',
'@docusaurus/Link',
'@docusaurus/router',
'@docusaurus/useDocusaurusContext',
'@docusaurus/useBaseUrl',
'@docusaurus/BrowserOnly',
'@docusaurus/theme-classic',
'@generated/docusaurus.config',
'^@theme/.*',
'^@theme-original/.*',
],
},
'packages/website-eslint': {
ignoreDependencies: [
// virtual module
'vt',
],
entry: [
'src/index.js',
'src/mock/assert.js',
'src/mock/empty.js',
'src/mock/eslint-rules.js',
'src/mock/eslint.js',
'src/mock/lru-cache.js',
'src/mock/path.js',
'src/mock/typescript.js',
'src/mock/util.js',
],
},
'tools/dummypkg': {},
},
} satisfies KnipConfig;
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@babel/types": "^7.24.0",
"@eslint/eslintrc": "^2.1.4",
"@eslint/js": "^8.57.0",
"@jest/types": "29.6.3",
"@nx/eslint": "18.2.3",
"@nx/jest": "18.2.3",
"@nx/workspace": "18.2.3",
Expand All @@ -75,7 +76,6 @@
"@types/is-glob": "^4.0.4",
"@types/jest": "29.5.12",
"@types/jest-specific-snapshot": "^0.5.9",
"@types/marked": "^5.0.2",
"@types/natural-compare": "^1.4.3",
"@types/ncp": "^2.0.8",
"@types/node": "^20.12.5",
Expand Down Expand Up @@ -104,9 +104,8 @@
"globals": "^15.0.0",
"husky": "^8.0.3",
"jest": "29.7.0",
"jest-diff": "^29.7.0",
"jest-snapshot": "^29.7.0",
"jest-specific-snapshot": "^8.0.0",
"knip": "^5.9.4",
"lint-staged": "^15.2.2",
"make-dir": "^4.0.0",
"markdownlint-cli": "^0.39.0",
Expand All @@ -115,7 +114,6 @@
"nx": "18.2.3",
"prettier": "3.2.5",
"pretty-format": "^29.7.0",
"raw-loader": "^4.0.2",
"rimraf": "^5.0.5",
"tmp": "^0.2.3",
"tsx": "*",
Expand Down
5 changes: 2 additions & 3 deletions packages/ast-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "jest",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"funding": {
"type": "opencollective",
Expand All @@ -47,12 +47,11 @@
"@babel/code-frame": "*",
"@babel/core": "*",
"@babel/eslint-parser": "*",
"@babel/parser": "*",
"@jest/types": "29.6.3",
"@microsoft/api-extractor": "^7.43.0",
"glob": "*",
"jest": "29.7.0",
"jest-diff": "^29.7.0",
"jest-snapshot": "^29.7.0",
"jest-specific-snapshot": "^8.0.0",
"make-dir": "*",
"prettier": "^3.2.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@prettier/sync": "^0.5.1",
Expand All @@ -22,6 +22,7 @@
"prettier": "^3.2.5"
},
"devDependencies": {
"@jest/types": "29.6.3",
"jest": "29.7.0",
"rimraf": "*"
}
Expand Down
13 changes: 5 additions & 8 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,36 @@
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist && rimraf coverage",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"generate:breaking-changes": "yarn tsx tools/generate-breaking-changes.mts",
"generate:breaking-changes": "tsx tools/generate-breaking-changes.mts",
"generate:configs": "npx nx run repo-tools:generate-configs",
"lint": "npx nx lint",
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage --logHeapUsage",
"test-single": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --no-coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@eslint-community/regexpp": "^4.10.0",
"@typescript-eslint/scope-manager": "7.8.0",
"@typescript-eslint/type-utils": "7.8.0",
"@typescript-eslint/utils": "7.8.0",
"@typescript-eslint/visitor-keys": "7.8.0",
"debug": "^4.3.4",
"graphemer": "^1.4.0",
"ignore": "^5.3.1",
"natural-compare": "^1.4.0",
"semver": "^7.6.0",
"ts-api-utils": "^1.3.0"
},
"devDependencies": {
"@types/debug": "*",
"@types/marked": "*",
"@jest/types": "29.6.3",
"@types/marked": "^5.0.2",
"@types/mdast": "^4.0.3",
"@types/natural-compare": "*",
"@typescript-eslint/rule-schema-to-typescript-types": "7.8.0",
"@typescript-eslint/rule-tester": "7.8.0",
"ajv": "^6.12.6",
"chalk": "^5.3.0",
"cross-env": "^7.0.3",
"cross-fetch": "*",
"eslint": "*",
"grapheme-splitter": "^1.0.4",
"espree": "^10.0.1",
"jest": "29.7.0",
"jest-specific-snapshot": "^8.0.0",
"json-schema": "*",
Expand Down
3 changes: 2 additions & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "jest --no-coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@jest/types": "29.6.3",
"jest": "29.7.0",
"ncp": "*",
"tmp": "*",
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"eslint": "^8.56.0"
Expand All @@ -59,6 +59,7 @@
"debug": "^4.3.4"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@types/glob": "*",
"downlevel-dts": "*",
"glob": "*",
Expand Down
11 changes: 8 additions & 3 deletions packages/repo-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@typescript-eslint/repo-tools",
"version": "7.8.0",
"private": true,
"//": "NOTE: intentionally no build step in this package",
"scripts": {
"//": "NOTE: intentionally no build step in this package",
"apply-canary-version": "npx tsx ./src/apply-canary-version.mts",
"format": "npx prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"generate-configs": "npx tsx ./src/generate-configs.mts",
Expand All @@ -13,16 +13,21 @@
"lint": "npx nx lint",
"postinstall-script": "npx tsx ./src/postinstall.mts",
"test": "npx jest --coverage",
"typecheck": "npx tsc -p tsconfig.json --noEmit"
"typecheck": "npx tsc --noEmit"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@nx/devkit": "*",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/scope-manager": "7.8.0",
"@typescript-eslint/types": "7.8.0",
"@typescript-eslint/typescript-estree": "7.8.0",
"@typescript-eslint/utils": "7.8.0",
"cross-fetch": "*",
"execa": "*",
"prettier": "^3.2.5",
"rimraf": "*",
"semver": "7.6.0",
"tmp": "*",
"typescript": "*"
}
}
5 changes: 4 additions & 1 deletion packages/rule-schema-to-typescript-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
"lint": "npx nx lint",
"postinstall-script": "tsx ./src/postinstall.ts",
"test": "npx jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@typescript-eslint/type-utils": "7.8.0",
"@typescript-eslint/utils": "7.8.0",
"natural-compare": "^1.4.0",
"prettier": "^3.2.5"
},
"devDependencies": {
"@jest/types": "29.6.3"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/typescript-eslint"
Expand Down
6 changes: 5 additions & 1 deletion packages/rule-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"pretest-eslint-base": "tsc -b tsconfig.build.json",
"test-eslint-base": "mocha --require source-map-support/register ./tests/eslint-base/eslint-base.test.js",
"test": "npx jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
"typecheck": "tsc --noEmit"
},
"//": "NOTE - AJV is out-of-date, but it's intentionally synced with ESLint - https://github.com/eslint/eslint/blob/ad9dd6a933fd098a0d99c6a9aa059850535c23ee/package.json#L70",
"dependencies": {
Expand All @@ -59,9 +59,13 @@
"eslint": "^8.56.0"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@types/lodash.merge": "4.6.9",
"@typescript-eslint/parser": "7.8.0",
"chai": "^4.4.1",
"eslint-visitor-keys": "^4.0.0",
"espree": "^10.0.1",
"esprima": "^4.0.1",
"mocha": "^10.4.0",
"sinon": "^16.1.3",
"source-map-support": "^0.5.21",
Expand Down
1 change: 1 addition & 0 deletions packages/scope-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@typescript-eslint/visitor-keys": "7.8.0"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@types/glob": "*",
"@typescript-eslint/typescript-estree": "7.8.0",
"glob": "*",
Expand Down
Loading

0 comments on commit f53fece

Please sign in to comment.