When using ESLint and TypeScript checkers together, ESLint checker only runs at startup
Describe the bug
When I start up my Vite dev server, ESLint and TypeScript both run.
When I change a file after this point, only TypeScript runs. It runs twice on each file change. My logs look like this:
VITE v5.3.3 ready in 423 ms
➜ Local: http://localhost:5173/
➜ Network: http://172.21.0.2:5173/
[TypeScript] Found 0 errors. Watching for file changes.
[ESLint] Found 0 error and 0 warning
4:24:43 PM [vite] hmr update /src/Map.tsx
[TypeScript] Found 0 errors. Watching for file changes.
[TypeScript] Found 0 errors. Watching for file changes.
4:25:00 PM [vite] hmr update /src/Map.tsx
[TypeScript] Found 0 errors. Watching for file changes.
[TypeScript] Found 0 errors. Watching for file changes.
4:25:04 PM [vite] hmr update /src/Map.tsx
[TypeScript] Found 0 errors. Watching for file changes.
[TypeScript] Found 0 errors. Watching for file changes.
Reproduction
My config:
checker({
typescript: {buildMode: true},
eslint: {
lintCommand: 'eslint . --ext ts,tsx --report-unused-disable-directives',
},
}),
I believe this is all that's needed to reproduce the behavior!
Expected behavior
ESLint and Typescript checkers run once each on every change
System Info
System:
OS: Linux 6.8 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (16) x64 AMD Ryzen 7 5800X3D 8-Core Processor
Memory: 12.98 GB / 31.26 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 22.4.1 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.8.1 - /usr/local/bin/npm
npmPackages:
vite-plugin-checker: ^0.7.2 => 0.7.2
Additional context
No response
Validations
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
What's the version of typescript and eslint in your project?
Hey, thanks for taking a look at my issue! I'm on [email protected], [email protected], and [email protected]
This is the project in which I'm experiencing the symptoms (on the map branch): https://github.com/nsidc/aross-stations-ui Let me know if I haven't provided enough info, I'll be happy to work on a more complete reproduction.
same for me for a year
I had the same issue (eslint run only once at startup) but apparently not for the same reason, I just mention it if it can help someone:
Don't forget the directory in the lintCommand attribute (in my case lintCommand: "eslint ." instead of lintCommand: "eslint").
https://github.com/fi3ework/vite-plugin-checker/blob/e6d564f3e281d66f037bd54333cc852639e87af4/packages/vite-plugin-checker/src/checkers/eslint/main.ts#L144 https://github.com/fi3ework/vite-plugin-checker/blob/e6d564f3e281d66f037bd54333cc852639e87af4/packages/vite-plugin-checker/src/checkers/eslint/main.ts#L155
This plugin reads the file path from the command and sends it to the watcher for monitoring. Therefore, if no file path is provided, no files will be monitored. As a result, even when using Flat Config, a path must be passed for it to function properly.
I did pass the current directory . as a path in my command. Or did you mean something else? Admittedly it's been a while since I've worked with Vite at this point.
Sorry, I didn't notice that you provided . as the path. I was primarily explaining the reason mentioned in this comment about "Don't forget the directory in the lintCommand attribute" and reminding Flat Config users that they must include it as well, since Flat Config typically does not require specifying a path.
checker({
typescript: false, // NOTE: Set to false if you prefer to let the IDE check our TypeScript
// NOTE: when running vitest we're running in vite, but there is no need for linting
eslint: process.env.VITEST
? false
: {
lintCommand: 'eslint . "**/*.{ts,tsx}"',
useFlatConfig: true,
watchPath: '**/*.{ts,tsx,js,jsx}',
dev: {
logLevel: ['error', 'warning']
}
},
overlay: true,
terminal: true,
enableBuild: false
}),
I tried adding the ".", but eslint does NOT run when saving files:
[ESLint] Found 0 error and 1 warning
[TypeScript] Found 0 errors. Watching for file changes.
[TypeScript] Found 0 errors. Watching for file changes. (x2)
Did anyone get this to work?