Skip to content

Instantly share code, notes, and snippets.

@gee1k
Created March 28, 2022 06:50
Show Gist options
  • Save gee1k/6af659ceb6f8788885925f7bad58483b to your computer and use it in GitHub Desktop.
Save gee1k/6af659ceb6f8788885925f7bad58483b to your computer and use it in GitHub Desktop.
React Typescript ESLint Prettier
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['react', '@typescript-eslint'],
settings: {
react: {
version: 'detect',
},
},
rules: {
'prettier/prettier': [
'error',
{
printWidth: 120,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'all',
bracketSpacing: true,
arrowParens: 'always',
endOfLine: 'auto',
},
],
},
}
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}

1.初始化 React 项目

npx create-react-app my-app --template typescript

2.安装 ESLint React 和 Typescript 支持

npm i -D eslint eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/parser @typescript-eslint/eslint-plugin

3.安装 Prettier 支持

npm i -D prettier eslint-config-prettier eslint-plugin-prettier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment