|
| 1 | +module.exports = { |
| 2 | + parser: '@typescript-eslint/parser', |
| 3 | + env: { |
| 4 | + browser: true, |
| 5 | + es2021: true, |
| 6 | + }, |
| 7 | + plugins: ['@typescript-eslint', 'babel', 'react-hooks', 'react'], |
| 8 | + extends: [ |
| 9 | + 'eslint:recommended', |
| 10 | + 'plugin:@typescript-eslint/recommended', |
| 11 | + 'plugin:react/recommended', |
| 12 | + // 'airbnb-base', // airbnb-base中已经包含了eslint-plugin-import |
| 13 | + // 'prettier', // 使得eslint中的样式规范失效,遵循prettier中的样式规范 |
| 14 | + // 'prettier/@typescript-eslint', // 使得@typescript-eslint中的样式规范失效,遵循prettier中的样式规范 |
| 15 | + ], |
| 16 | + overrides: [ |
| 17 | + { |
| 18 | + env: { |
| 19 | + node: true, |
| 20 | + }, |
| 21 | + files: ['.eslintrc.{js,cjs}'], // |
| 22 | + parserOptions: { |
| 23 | + sourceType: 'script', |
| 24 | + }, |
| 25 | + }, |
| 26 | + ], |
| 27 | + parserOptions: { |
| 28 | + ecmaVersion: 'latest', |
| 29 | + sourceType: 'module', |
| 30 | + }, |
| 31 | + rules: { |
| 32 | + 'func-names': 0, // 函数表达式必须有名字 |
| 33 | + 'one-var': [1, 'never'], // 连续声明 |
| 34 | + 'prefer-const': 1, // 首选const |
| 35 | + 'no-unused-expressions': 0, // 禁止无用的表达式 |
| 36 | + 'new-cap': 2, // 构造函数首字母大写 |
| 37 | + 'prefer-arrow-callback': 2, // 首选箭头函数 |
| 38 | + 'arrow-body-style': 0, // 箭头函数体使用大括号 |
| 39 | + 'max-len': [ |
| 40 | + // 一行最大长度 |
| 41 | + 1, |
| 42 | + { |
| 43 | + code: 120, |
| 44 | + ignoreStrings: true, |
| 45 | + ignoreUrls: true, |
| 46 | + ignoreRegExpLiterals: true, |
| 47 | + }, |
| 48 | + ], |
| 49 | + 'consistent-return': 'off', // return 后面是否允许省略 |
| 50 | + 'default-case': 2, // switch 语句必须有 default |
| 51 | + 'prefer-rest-params': 2, // 必须使用解构 ...args 来代替 arguments |
| 52 | + 'no-script-url': 0, // 禁止使用 javascript:void(0) |
| 53 | + // 'no-console': [ // 禁止使用 console |
| 54 | + // 2, |
| 55 | + // { |
| 56 | + // allow: ['info', 'error', 'warn'], |
| 57 | + // }, |
| 58 | + // ], |
| 59 | + 'no-duplicate-imports': 2, // 禁止重复 import |
| 60 | + 'newline-per-chained-call': 2, // 链式调用必须换行 |
| 61 | + 'no-underscore-dangle': 2, // 禁止标识符中有悬空下划线 |
| 62 | + 'eol-last': 2, // 文件以单一的换行符结束 |
| 63 | + 'no-useless-rename': 2, // 禁止无用的重命名 |
| 64 | + 'no-undef': 0, // 禁止使用未定义的变量 |
| 65 | + 'class-methods-use-this': 0, // class 的非静态方法必须包含 this |
| 66 | + 'prefer-destructuring': 0, // 优先使用数组和对象解构 |
| 67 | + 'no-unused-vars': 0, // 禁止未使用过的变量 |
| 68 | + '@typescript-eslint/no-unused-vars': 1, // 禁止未使用过的变量 |
| 69 | + 'react/self-closing-comp': 2, // 非单行 JSX 必须使用括号包裹 |
| 70 | + 'react/jsx-indent-props': [2, 2], // jsx props 缩进 |
| 71 | + 'no-plusplus': 0, // 禁止使用 ++,-- |
| 72 | + 'react/jsx-uses-vars': 1, // jsx 文件中禁止使用变量 |
| 73 | + // 'react/no-multi-comp': [ // 禁止一个文件中定义多个组件 |
| 74 | + // 2, |
| 75 | + // { |
| 76 | + // ignoreStateless: true, |
| 77 | + // }, |
| 78 | + // ], |
| 79 | + 'react/jsx-uses-react': 2, // jsx 文件中禁止使用 React |
| 80 | + 'react/react-in-jsx-scope': 2, // jsx 文件中禁止使用 React |
| 81 | + 'react/sort-comp': 1, // 组件内方法顺序 |
| 82 | + 'react/jsx-tag-spacing': 2, // jsx 中的属性禁止使用空格 |
| 83 | + 'react/jsx-no-bind': 0, // jsx 中禁止使用 bind |
| 84 | + 'react/jsx-closing-bracket-location': 2, // jsx 中的右括号必须换行 |
| 85 | + 'react/prefer-stateless-function': 0, // 优先使用无状态组件 |
| 86 | + 'react/display-name': 0, // 组件必须写 displayName |
| 87 | + 'react/prop-types': 0, // 组件必须写 propTypes |
| 88 | + 'import/prefer-default-export': 0, // 优先使用 export default |
| 89 | + '@typescript-eslint/no-var-requires': 2, // 禁止 require() 使用表达式 |
| 90 | + 'no-use-before-define': 0, // 禁止定义前使用 |
| 91 | + '@typescript-eslint/no-use-before-define': [ |
| 92 | + // 禁止定义前使用 |
| 93 | + 0, |
| 94 | + // { |
| 95 | + // functions: false, |
| 96 | + // }, |
| 97 | + ], |
| 98 | + '@typescript-eslint/explicit-function-return-type': 0, // 函数必须有返回值 |
| 99 | + '@typescript-eslint/interface-name-prefix': 0, // 接口名称必须以 I 开头 |
| 100 | + '@typescript-eslint/explicit-module-boundary-types': 0, // 导出函数和类的公共方法必须声明返回类型 |
| 101 | + 'no-shadow': 0, // 禁止变量名与上层作用域内的定义过的变量重复 |
| 102 | + '@typescript-eslint/no-shadow': 1, // 禁止变量名与上层作用域内的定义过的变量重复TODO: 为2是不是好点? |
| 103 | + 'no-invalid-this': 0, // 禁止 this 关键字出现在类和类对象之外 |
| 104 | + 'no-await-in-loop': 'off', // 禁止在循环中出现 await |
| 105 | + 'array-callback-return': 'off', // 数组方法的回调函数中必须有 return 语句 |
| 106 | + 'no-restricted-syntax': 'off', // 禁止使用特定的语法 |
| 107 | + '@typescript-eslint/no-explicit-any': 0, // 禁止使用 any |
| 108 | + 'import/no-extraneous-dependencies': 0, // 禁止使用无关的 package |
| 109 | + 'import/no-unresolved': 0, // 禁止使用无关的 package |
| 110 | + '@typescript-eslint/explicit-member-accessibility': 0, // 类的成员之间是否需要空行 |
| 111 | + '@typescript-eslint/no-object-literal-type-assertion': 0, // 禁止使用 as Type |
| 112 | + 'react/no-find-dom-node': 0, // 禁止使用 findDOMNode |
| 113 | + 'no-param-reassign': [ |
| 114 | + // 禁止对函数参数再赋值 |
| 115 | + 2, |
| 116 | + { |
| 117 | + props: false, |
| 118 | + }, |
| 119 | + ], |
| 120 | + 'arrow-parens': 0, // 箭头函数参数括号 |
| 121 | + indent: 0, // 缩进 |
| 122 | + 'operator-linebreak': [0], // 换行符位置 |
| 123 | + 'max-classes-per-file': [2, 10], // 一个文件最多定义几个类 |
| 124 | + '@typescript-eslint/no-empty-function': [0], // 禁止空函数 |
| 125 | + 'import/extensions': 0, // 禁止导入文件时带上文件后缀 |
| 126 | + }, |
| 127 | +}; |
0 commit comments