Skip to content

Commit 5d29f8f

Browse files
webproTkDodoDamianOsipiuk
authored
chore: introduce Knip as dead-code removal tool (#6368)
* Add knip with inital config * Rename vite.config.js → vite.config.js (`__dirname` not in ESM scope) * chore: upgrade to knip v3 * chore(knip): remove duplicate exports * chore(knip): remove unused types from query devtools * chore(knip): do not export unused types * chore(knip): run knip in ci * chore(knip): ignore certain .d.ts files * chore(knip): remove unused file * chore(knip): use devtools in next integration so the dependency doesn't show up as unused * chore(knip): remove unused dependencies * chore(knip): remove unused exports * chore(knip): add unlisted dependencies * chore(knip): remove unnecessary scope-manager dependency * Update knip to 3.3.0 * Update knip to 3.3.1 * chore: ignore custom deps, remove unneeded file * chore: remove unused util * chore: remove esbuild dep as it's not directly used * chore: bump tsup to match esbuild types with the plugin * chore: remove unused peer deps * chore: remove unneeded deps --------- Co-authored-by: Dominik Dorfmeister <[email protected]> Co-authored-by: Damian Osipiuk <[email protected]>
1 parent ac92fc9 commit 5d29f8f

File tree

33 files changed

+849
-813
lines changed

33 files changed

+849
-813
lines changed

.github/workflows/pr.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,24 @@ jobs:
100100
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
101101
- name: Run prettier
102102
run: pnpm run test:format
103+
knip:
104+
name: Knip
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
110+
- name: Setup pnpm
111+
uses: pnpm/action-setup@v2
112+
with:
113+
version: 8
114+
- name: Setup Node
115+
uses: actions/setup-node@v3
116+
with:
117+
node-version-file: .nvmrc
118+
cache: pnpm
119+
cache-dependency-path: pnpm-lock.yaml
120+
- name: Install dependencies
121+
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
122+
- name: Run Knip
123+
run: pnpm knip

integrations/react-cra4/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from '@tanstack/react-query'
22

3-
export const App = () => {
3+
const App = () => {
44
const query = useQuery({
55
queryKey: ['test'],
66
queryFn: async () => {

integrations/react-cra5/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from '@tanstack/react-query'
22

3-
export const App = () => {
3+
const App = () => {
44
const query = useQuery({
55
queryKey: ['test'],
66
queryFn: async () => {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use client'
22
import * as React from 'react'
33
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
4+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
45

56
export default function Providers({ children }: { children: React.ReactNode }) {
67
const [queryClient] = React.useState(() => new QueryClient())
78

89
return (
9-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
10+
<QueryClientProvider client={queryClient}>
11+
{children}
12+
<ReactQueryDevtools />
13+
</QueryClientProvider>
1014
)
1115
}

integrations/react-vite4/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from '@tanstack/react-query'
22

3-
export const App = () => {
3+
const App = () => {
44
const query = useQuery({
55
queryKey: ['test'],
66
queryFn: async () => {

integrations/react-vite5/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from '@tanstack/react-query'
22

3-
export const App = () => {
3+
const App = () => {
44
const query = useQuery({
55
queryKey: ['test'],
66
queryFn: async () => {

integrations/solid-vite/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Match, Switch } from 'solid-js'
22
import { createQuery } from '@tanstack/solid-query'
33

4-
export const App = () => {
4+
const App = () => {
55
const query = createQuery(() => ({
66
queryKey: ['test'],
77
queryFn: async () => {

knip.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// These aren't actual compilers, but performant & avoids root dependencies
2+
const svelteCompiler = (text: string) => text.matchAll(/import[^]*?'.*?'\n/gs)
3+
const vueCompiler = /<script\b[^>]*>([\s\S]*?)<\/script>/gm
4+
5+
export default {
6+
$schema: 'https://unpkg.com/knip@2/schema.json',
7+
ignoreWorkspaces: ['examples/**'],
8+
ignore: ['**/react-app-env.d.ts', '**/vite-env.d.ts'],
9+
workspaces: {
10+
'packages/codemods': {
11+
entry: ['src/v4/*.js', 'src/v5/*/*.js'],
12+
ignore: ['**/__testfixtures__/**'],
13+
},
14+
'packages/vue-query': {
15+
ignore: ['**/__mocks__/**'],
16+
ignoreDependencies: ['vue2', 'vue2.7'],
17+
},
18+
},
19+
compilers: {
20+
svelte: (text: string) => [...svelteCompiler(text)].join('\n'),
21+
vue: (text) => {
22+
const scripts = []
23+
let match
24+
while ((match = vueCompiler.exec(text))) scripts.push(match[1])
25+
return scripts.join(';')
26+
},
27+
},
28+
}

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
"@solidjs/testing-library": "^0.5.1",
4242
"@testing-library/jest-dom": "^6.1.4",
4343
"@testing-library/react": "^14.0.0",
44-
"@testing-library/react-hooks": "^8.0.1",
45-
"@testing-library/user-event": "^14.5.1",
4644
"@types/current-git-branch": "^1.1.5",
4745
"@types/eslint": "^8.44.0",
4846
"@types/git-log-parser": "^1.2.2",
@@ -58,11 +56,9 @@
5856
"@vitest/coverage-istanbul": "^0.33.0",
5957
"axios": "^1.5.1",
6058
"chalk": "^5.3.0",
61-
"concurrently": "^8.2.2",
6259
"cpy-cli": "^5.0.0",
6360
"cross-env": "^7.0.3",
6461
"current-git-branch": "^1.1.0",
65-
"esbuild": "^0.18.20",
6662
"esbuild-plugin-file-path-extensions": "^1.0.0",
6763
"eslint": "^8.34.0",
6864
"eslint-config-prettier": "^8.8.0",
@@ -73,6 +69,7 @@
7369
"git-log-parser": "^1.2.0",
7470
"jsdom": "^22.1.0",
7571
"jsonfile": "^6.1.0",
72+
"knip": "^3.3.1",
7673
"luxon": "^3.4.3",
7774
"nx": "^16.5.2",
7875
"nx-cloud": "^16.5.2",
@@ -86,13 +83,11 @@
8683
"sherif": "^0.5.0",
8784
"solid-js": "^1.8.1",
8885
"stream-to-array": "^2.3.0",
89-
"ts-node": "^10.7.0",
90-
"tsup": "^7.2.0",
86+
"tsup": "^7.3.0",
9187
"type-fest": "^4.5.0",
9288
"typescript": "5.1.6",
9389
"vite": "^4.4.11",
94-
"vitest": "^0.33.0",
95-
"vue": "^3.3.0"
90+
"vitest": "^0.33.0"
9691
},
9792
"pnpm": {
9893
"overrides": {

packages/eslint-plugin-query/src/utils/ast-utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
22
import { uniqueBy } from './unique-by'
33
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
4-
import type TSESLintScopeManager from '@typescript-eslint/scope-manager'
54
import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'
65

76
export const ASTUtils = {
@@ -143,7 +142,7 @@ export const ASTUtils = {
143142
},
144143
isDeclaredInNode(params: {
145144
functionNode: TSESTree.Node
146-
reference: TSESLintScopeManager.Reference
145+
reference: TSESLint.Scope.Reference
147146
scopeManager: TSESLint.Scope.ScopeManager
148147
}) {
149148
const { functionNode, reference, scopeManager } = params

0 commit comments

Comments
 (0)