Create the React App
npx create-react-app my-app --typescript
cd my-app
Install ESLint and Prettier
npm i -D @types/react @types/react-dom @types/node @types/jest @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-config-react eslint-plugin-prettier prettier
Download eslint config
curl https://gist.githubusercontent.com/nnance/7278e4db2254186af1278a4d928adb5e/raw/1fc30b48d901b5acd6cdbf233341baa6be6ce735/.eslintrc.json -o .eslintrc.json
curl https://gist.githubusercontent.com/nnance/7278e4db2254186af1278a4d928adb5e/raw/1fc30b48d901b5acd6cdbf233341baa6be6ce735/.eslintignore -o .eslintignore
Add Lint Script to package.json
"lint": "eslint './src/**/*.{ts,tsx}'",
"lint:fix": "eslint './src/**/*.{ts,tsx}' --fix"
Configure vscode to use eslint.
- Open settings with
command ,
- type
eslint: validate
in the search box - click
edit in settings.json
and add the following lines
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "typescript",
"autoFix": true
},
{
"language": "typescriptreact",
"autoFix": true
}
],
Did you make a mistake with this or is it intentional?