本文主要是介绍TypeScript 项目 Airbnb 语法风格 ESLint 配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TypeScript 项目 Airbnb 语法风格 ESLint 配置
1. 配置
安装:
npm i -D eslint-config-airbnb-typescript @typescript-eslint/eslint-plugin@^6.0.0 @typescript-eslint/parser@^6.0.0
配置:
-
.eslintrc.js:
module.exports = {root: true,env: {node: true,browser: true,},extends: ['airbnb-base','airbnb-typescript/base',],parserOptions: {project: './tsconfig.json',}, };
-
tsconfig.json:
{// ..."include": ["src/**/*.ts","src/**/*.tsx","src/**/*.vue","tests/**/*.ts","tests/**/*.tsx","./*.js", // 匹配不到 `.eslintrc.js`,但可以匹配到 `webpack.config.js`"./.eslintrc.js", // 重点,缺少它会报如下错误] }
错误:
Parsing error: ESLint was configured to run on `<tsconfigRootDir>/.eslintrc.js` using `parserOptions.project`: <tsconfigRootDir>/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file
Process finished with exit code -1
注意:
- webstorm 上修改完 tsconfig.json 的 include 属性的值,需要重启才会生效
2. 参考
- eslint-config-airbnb-typescript
- Solve parserOptions.project bug with Typescript and ESLint
这篇关于TypeScript 项目 Airbnb 语法风格 ESLint 配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!