The ESLint team will no longer be maintaining typescript-eslint-parser
The repository will be archived as of today
There will be no further releases of typescript-eslint-parser on npm
Anyone using typescript-eslint-parser should use @typescript-eslint/parser instead
Those interested in how TypeScript support is coming along should follow the typescript-eslint repository
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
parserOptions: {
tsconfigRootDir: 'src',
project: ['../tsconfig.json'],
},
rules: {
}
};
eslint-plugin-react
这个插件,配置这样:module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
"plugin:react/recommended",
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
parserOptions: {
tsconfigRootDir: 'src',
project: ['../tsconfig.json'],
},
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'react/display-name': 'off',
'react/prop-types': 'off'
}
};
"indent": ["error", 4],
"max-lines": ["error", { "max": 300, "skipComments": true }]
"eslint": "eslint --ext .tsx,.ts --fix ./src"
--list-different
来检测是否格式化过代码。$ yarn prettier --list-different \"./**/*.{ts,js,json,md}\"
"prettier": "prettier --config ./.prettierrc.js --write ./src/**/*.tsx"
具体配置可以参考官网。
如果实在想用插件这么配:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
+ 'prettier/@typescript-eslint',
],
};
eslint-config-prettier
让这2者不冲突。{
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "typescript",
"autoFix": true
},
{
"language": "typescriptreact",
"autoFix": true
}
]
}