初始化
- 安装:执行命令:yarn add eslint -D
初始化
- yarn eslint --init
- How would you like to use ESLint?
To check syntax, find problems, and enforce code style
,检查语法、检测问题并强制代码风格。- What type of modules does your project use?
JavaScript modules (import/export)
, 采用的 ES6 模块系统导入导出- Which framework does your project use?
React
或 vue- Does your project use TypeScript?
Yes
,eslint
配置文件默认支持Typescript
的parse
以及插件plugins
等。- Where does your code run?
Browser
和Node
- What format do you want your config file to be in?
JavaScript
,即生成的配置文件是 js 文件,更加灵活- Would you like to install them now with npm?
Yes
配置文件
- 创建
.eslintignore
文件(eslint 不校验的文件)
node_modules
dist
- 创建
eslintrc.json
或.js
文件- 相应扩展包插件: eslint-config-perttier / eslint-config-airbnb / eslint-config-standard
- js ~ eslint-plugin-import(检查和修复 JavaScript 导入语句)
- js ~ eslint-import-resolver-alias(允许 ESLint 中使用路径别名来引入模块,如@)
- ts ~ @typescript-eslint/parser(代码解析为抽象语法树AST的解析器,允许 ESLint 在分析和处理)
- ts ~ @typescript-eslint/eslint-plugin(检查和修复 TypeScript 代码中的潜在问题和错误)
- react ~ eslint-plugin-react (检查和修复 React 代码)
- react ~ eslint-plugin-jsx-a11y(检查和修复 JSX 元素的可访问性问题的规则)
- react ~ eslint-plugin-react-hooks(检查和修复 React Hooks 使用的规则)