.eslinttrc文件

  1. // 引入sorrycc - git(eslint-config-umi)开源插件
  2. "extends": "eslint-config-umi",

eslint-config-umi源码

分析package.json引用包

  1. eslint-config-react-app:
  2. eslint-plugin-flowtype: ESLint的 - 静态流类型规则。衍生了解flow
  3. eslint-plugin-import: 该插件旨在支持ES2015 +(ES6 +)导入/导出语法的检查,并防止文件路径和导入名称拼写错误的问题。ES2015 +静态模块语法打算提供的所有优点,已在您的编辑器中进行了标记。
  4. eslint-plugin-jsx-a11y: 静态AST检查器,用于JSX元素上的可访问性规则。
  5. eslint-plugin-react: 对ESLint对特定react规则做出反应
  6. eslint-plugin-react-hooks: 该ESLint插件强制执行“react hooks 规则”。它是React的Hooks API的一部分。
    1. "dependencies": {
    2. // 该软件包包括Create React App使用的可共享ESLint配置。
    3. "eslint-config-react-app": "5.0.2"
    4. },
    5. "peerDependencies": {
    6. "eslint-plugin-flowtype": "2.x",
    7. "eslint-plugin-import": "2.x",
    8. "eslint-plugin-jsx-a11y": "6.x",
    9. "eslint-plugin-react": "7.x",
    10. "eslint-plugin-react-hooks": "1.5.0"
    11. }

分析主文件

umi/packages/eslint-config-umi/index.js

  1. 注意导出方式
  2. module.exports = require('./lib').default; // 指定默认导出

umi/packages/eslint-config-umi/lib/index.js

  1. eslint-config-react-app: 默认导出create-react-app的eslint规则;后期可以增加详细规则篇 ```javascript import reactAppConfig from ‘eslint-config-react-app’;

export default { …reactAppConfig, rules: { …reactAppConfig.rules, strict: [0], // 禁用逗号操作符 ‘no-sequences’: [0], // 禁止混合使用不同的操作符 ‘no-mixed-operators’: [0],

  1. 'react/react-in-jsx-scope': [0],
  2. // 禁用不必要的转义字符
  3. 'no-useless-escape': [0],

}, // 配置文件添加共享设置 settings: { react: { version: ‘16.8’, }, }, }; ```