Closed mfisher87 closed 2 months ago
@mfisher87 I don't use type-aware linting as described in the readme, but rely on typescript checking done by VSCode's intellisense. This is my .eslintrc.cjs
file:
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
I don't use VSCode. The parser options recommended in the README include two additional values, project
and tsonfigRootDir
:
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
Instead of removing those two items like you have, I worked around this issue by modifying this line in tsconfig.node.json
to add src
to the list:
"include": ["vite.config.ts", "src"]
I'd like to propose a fix to the template, but I'm honestly not sure if I've fixed this in the "correct" way :) I write TypeScript maybe 1 month out of the year :grimacing:
Perhaps https://github.com/vitejs/vite/pull/17645 fixes it
This does in fact fix linting when I apply it to my "sscce" repository (if you want to test yourself, you can use the fix-attempt
branch)! Thank you. I will comment similarly on the PR.
Describe the bug
I'm trying to lint after following the "type-aware linting" instructions in the README of the react-ts template. But I'm getting errors:
Reproduction
https://github.com/mfisher87/sscce-vite-react-ts-template-typeaware-linting-broken
Steps to reproduce
First, I create a new project with
react-ts
template:This works fine.
Follow the instructions in the README:
At this point,
.eslintrc.cjs
looks like:Then run
npm run lint
again to reproduce the error. 1 error of 3 similar errors shown (see bottom for full error):System Info
Used Package Manager
npm
Logs
Click to expand!
```shell > test-create-vite-react-ts@0.0.0 lint > eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration . /home/robatt/Projects/_tmp/test-create-vite-react-ts/src/App.tsx 0:0 error Parsing error: ESLint was configured to run on `Validations