[英]Eslint not working with the TypeScript syntax
I am trying to configure eslint
for my REACT-TypeScript
project.我正在尝试为我的
REACT-TypeScript
项目配置eslint
。 It was previously using tslint
which is going to deprecate soon.它以前使用
tslint
,它很快就会被弃用。 I have gone through the web and finally was able to create my .eslintrc.json
:我浏览了网络,终于能够创建我的
.eslintrc.json
:
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json",
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"browser": true,
"jest/globals": true
},
"extends": [
"airbnb",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint", "react-hooks", "jest", "prettier"],
"ignorePatterns": ["src/serviceWorker.ts", "src/enums.ts", "node_modules/"],
"rules": { },
"settings": {
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"prettier/prettier": [
"error",
{
"singleQuote": true,
"semi": "error"
}
]
}
When I run the lint
command, it throws errors about the TypeScript
syntax.当我运行
lint
命令时,它会抛出有关TypeScript
语法的错误。 Here are few:这里有几个:
All links on google are now purple and still, I can't seem to figure out what's wrong.谷歌上的所有链接现在都是紫色的,但我似乎无法弄清楚出了什么问题。 Please help me to see this through.
请帮我看看这个。
To me your configuration seems good.对我来说你的配置看起来不错。 If it is a Typescript error there is nothing you can do with ESLint.
如果是 Typescript 错误,则 ESLint 无能为力。 Just upgrade Typescript.
只需升级打字稿。
Just in case check this ESLint Prettier Typescript configuration which is a reference to me https://levelup.gitconnected.com/setting-up-eslint-with-prettier-typescript-and-visual-studio-code-d113bbec9857 ?以防万一检查这个ESLint Prettier Typescript配置,这是对我的参考https://levelup.gitconnected.com/setting-up-eslint-with-prettier-typescript-and-visual-studio-code-d113bbec9857 ? it is close to yours
它离你很近
You don't need to specify parser
, parserOptions
, settings
for TS or react.您不需要为 TS 或 react 指定
parser
、 parserOptions
、 settings
。 You can just extend airbnb TS config, and add the other plugins like (jest, prettier, ...) only:您可以扩展 airbnb TS 配置,并仅添加其他插件,例如 (jest, prettier, ...):
So your .eslintrc
will look like:所以你的
.eslintrc
看起来像:
{
"extends": ["airbnb-typescript", "plugin:jest/recommended"],
"plugins": ["jest", "prettier"]
}
to install airbnb TS config安装airbnb TS配置
npm install eslint-config-airbnb-typescript \
eslint-plugin-import@^2.18.2 \
eslint-plugin-jsx-a11y@^6.2.3 \
eslint-plugin-react@^7.15.1 \
eslint-plugin-react-hooks@^1.7.0 \
@typescript-eslint/eslint-plugin@^2.7.0 \
--save-dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.