1. /**
    2. * AlloyTeam ESLint 规则
    3. * https://alloyteam.github.io/eslint-config-alloy/
    4. *
    5. * 贡献者:
    6. * xcatliu <xcatliu@gmail.com>
    7. * heyli <lcxfs1991@gmail.com>
    8. * Swan <noreply@github.com>
    9. * DiamondYuan <admin@diamondyuan.com>
    10. * Dash Chen <noreply@github.com>
    11. * lzw <mingxin2014@gmail.com>
    12. * ryoliu <sfesh@163.com>
    13. * sunhui04 <sunhui04@meituan.com>
    14. *
    15. * 依赖版本:
    16. * eslint ^6.7.1
    17. * babel-eslint ^10.0.3
    18. * eslint-plugin-react ^7.16.0
    19. * vue-eslint-parser ^7.0.0
    20. * eslint-plugin-vue ^6.1.1
    21. * @typescript-eslint/parser ^2.13.0
    22. * @typescript-eslint/eslint-plugin ^2.13.0
    23. *
    24. * 此文件是由脚本 scripts/build.ts 自动生成
    25. *
    26. * @reason 为什么要开启(关闭)此规则
    27. */
    28. module.exports = {
    29. parser: 'babel-eslint',
    30. parserOptions: {
    31. ecmaVersion: 2019,
    32. // ECMAScript modules 模式
    33. sourceType: 'module',
    34. ecmaFeatures: {
    35. // 不允许 return 语句出现在 global 环境下
    36. globalReturn: false,
    37. // 开启全局 script 模式
    38. impliedStrict: true,
    39. jsx: true
    40. },
    41. // 即使没有 babelrc 配置文件,也使用 babel-eslint 来解析
    42. requireConfigFile: false,
    43. // 仅允许 import export 语句出现在模块的顶层
    44. allowImportExportEverywhere: false
    45. },
    46. env: {
    47. browser: true,
    48. node: true,
    49. commonjs: true,
    50. es6: true
    51. },
    52. // 以当前目录为根目录,不再向上查找 .eslintrc.js
    53. root: true,
    54. rules: {
    55. /**
    56. * setter 必须有对应的 getter,getter 可以没有对应的 setter
    57. */
    58. 'accessor-pairs': [
    59. 'error',
    60. {
    61. setWithoutGet: true,
    62. getWithoutSet: false
    63. }
    64. ],
    65. /**
    66. * 数组的方法除了 forEach 之外,回调函数必须有返回值
    67. */
    68. 'array-callback-return': 'error',
    69. /**
    70. * 将 var 定义的变量视为块作用域,禁止在块外使用
    71. * @reason 已经禁止使用 var 了
    72. */
    73. 'block-scoped-var': 'off',
    74. /**
    75. * callback 之后必须立即 return
    76. */
    77. 'callback-return': 'off',
    78. /**
    79. * 变量名必须是 camelcase 风格的
    80. * @reason 很多 api 或文件名都不是 camelcase 风格的
    81. */
    82. camelcase: 'off',
    83. /**
    84. * 注释的首字母必须大写
    85. */
    86. 'capitalized-comments': 'off',
    87. /**
    88. * 在类的非静态方法中,必须存在对 this 的引用
    89. */
    90. 'class-methods-use-this': 'off',
    91. /**
    92. * 禁止函数的循环复杂度超过 20
    93. * @reason https://en.wikipedia.org/wiki/Cyclomatic_complexity
    94. */
    95. complexity: [
    96. 'error',
    97. {
    98. max: 20
    99. }
    100. ],
    101. /**
    102. * 禁止函数在不同分支返回不同类型的值
    103. * @reason 缺少 TypeScript 的支持,类型判断是不准确的
    104. */
    105. 'consistent-return': 'off',
    106. /**
    107. * 限制 this 的别名
    108. */
    109. 'consistent-this': 'off',
    110. /**
    111. * constructor 中必须有 super
    112. */
    113. 'constructor-super': 'error',
    114. /**
    115. * switch 语句必须有 default
    116. */
    117. 'default-case': 'off',
    118. /**
    119. * 有默认值的参数必须放在函数参数的末尾
    120. */
    121. 'default-param-last': 'off',
    122. /**
    123. * 禁止使用 foo['bar'],必须写成 foo.bar
    124. * @reason 当需要写一系列属性的时候,可以更统一
    125. */
    126. 'dot-notation': 'off',
    127. /**
    128. * 必须使用 === 或 !==,禁止使用 == 或 !=
    129. */
    130. eqeqeq: ['error', 'always'],
    131. /**
    132. * 禁止方向错误的 for 循环
    133. */
    134. 'for-direction': 'error',
    135. /**
    136. * 函数赋值给变量的时候,函数名必须与变量名一致
    137. */
    138. 'func-name-matching': [
    139. 'error',
    140. 'always',
    141. {
    142. includeCommonJSModuleExports: false
    143. }
    144. ],
    145. /**
    146. * 函数必须有名字
    147. */
    148. 'func-names': 'off',
    149. /**
    150. * 必须只使用函数声明或只使用函数表达式
    151. */
    152. 'func-style': 'off',
    153. /**
    154. * getter 必须有返回值,并且禁止返回空
    155. */
    156. 'getter-return': 'error',
    157. /**
    158. * require 必须在全局作用域下
    159. */
    160. 'global-require': 'off',
    161. /**
    162. * setter 和 getter 必须写在一起
    163. */
    164. 'grouped-accessor-pairs': 'error',
    165. /**
    166. * for in 内部必须有 hasOwnProperty
    167. */
    168. 'guard-for-in': 'error',
    169. /**
    170. * callback 中的 err 必须被处理
    171. * @reason 它是通过字符串匹配来判断函数参数 err 的,不准确
    172. */
    173. 'handle-callback-err': 'off',
    174. /**
    175. * 禁止使用指定的标识符
    176. */
    177. 'id-blacklist': 'off',
    178. /**
    179. * 限制变量名长度
    180. */
    181. 'id-length': 'off',
    182. /**
    183. * 限制变量名必须匹配指定的正则表达式
    184. */
    185. 'id-match': 'off',
    186. /**
    187. * 变量必须在定义的时候赋值
    188. */
    189. 'init-declarations': 'off',
    190. /**
    191. * 单行注释必须写在上一行
    192. */
    193. 'line-comment-position': 'off',
    194. /**
    195. * 类的成员之间是否需要空行
    196. * @reason 有时为了紧凑需要挨在一起,有时为了可读性需要空一行
    197. */
    198. 'lines-between-class-members': 'off',
    199. /**
    200. * 限制一个文件中类的数量
    201. */
    202. 'max-classes-per-file': 'off',
    203. /**
    204. * 代码块嵌套的深度禁止超过 5 层
    205. */
    206. 'max-depth': ['error', 5],
    207. /**
    208. * 限制一个文件最多的行数
    209. */
    210. 'max-lines': 'off',
    211. /**
    212. * 限制函数块中的代码行数
    213. */
    214. 'max-lines-per-function': 'off',
    215. /**
    216. * 回调函数嵌套禁止超过 3 层,多了请用 async await 替代
    217. */
    218. 'max-nested-callbacks': ['error', 3],
    219. /**
    220. * 函数的参数禁止超过 3 个
    221. */
    222. 'max-params': ['error', 3],
    223. /**
    224. * 限制函数块中的语句数量
    225. */
    226. 'max-statements': 'off',
    227. /**
    228. * 限制一行中的语句数量
    229. */
    230. 'max-statements-per-line': 'off',
    231. /**
    232. * 约束多行注释的格式
    233. * @reason 能写注释已经不容易了,不需要限制太多
    234. */
    235. 'multiline-comment-style': 'off',
    236. /**
    237. * new 后面的类名必须首字母大写
    238. */
    239. 'new-cap': [
    240. 'error',
    241. {
    242. newIsCap: true,
    243. capIsNew: false,
    244. properties: true
    245. }
    246. ],
    247. /**
    248. * 禁止使用 alert
    249. */
    250. 'no-alert': 'off',
    251. /**
    252. * 禁止使用 Array 构造函数时传入的参数超过一个
    253. * @reason 参数为一个时表示创建一个指定长度的数组,比较常用
    254. * 参数为多个时表示创建一个指定内容的数组,此时可以用数组字面量实现,不必使用构造函数
    255. */
    256. 'no-array-constructor': 'error',
    257. /**
    258. * 禁止将 async 函数做为 new Promise 的回调函数
    259. * @reason 出现这种情况时,一般不需要使用 new Promise 实现异步了
    260. */
    261. 'no-async-promise-executor': 'error',
    262. /**
    263. * 禁止将 await 写在循环里,因为这样就无法同时发送多个异步请求了
    264. * @reason 要求太严格了,有时需要在循环中写 await
    265. */
    266. 'no-await-in-loop': 'off',
    267. /**
    268. * 禁止使用位运算
    269. */
    270. 'no-bitwise': 'off',
    271. /**
    272. * 禁止直接使用 Buffer
    273. * @reason Buffer 构造函数是已废弃的语法
    274. */
    275. 'no-buffer-constructor': 'error',
    276. /**
    277. * 禁止使用 caller 或 callee
    278. * @reason 它们是已废弃的语法
    279. */
    280. 'no-caller': 'error',
    281. /**
    282. * switch 的 case 内有变量定义的时候,必须使用大括号将 case 内变成一个代码块
    283. */
    284. 'no-case-declarations': 'error',
    285. /**
    286. * 禁止对已定义的 class 重新赋值
    287. */
    288. 'no-class-assign': 'error',
    289. /**
    290. * 禁止与负零进行比较
    291. */
    292. 'no-compare-neg-zero': 'error',
    293. /**
    294. * 禁止在测试表达式中使用赋值语句,除非这个赋值语句被括号包起来了
    295. */
    296. 'no-cond-assign': ['error', 'except-parens'],
    297. /**
    298. * 禁止使用 console
    299. */
    300. 'no-console': 'off',
    301. /**
    302. * 禁止对使用 const 定义的常量重新赋值
    303. */
    304. 'no-const-assign': 'error',
    305. /**
    306. * 禁止将常量作为分支条件判断中的测试表达式,但允许作为循环条件判断中的测试表达式
    307. */
    308. 'no-constant-condition': [
    309. 'error',
    310. {
    311. checkLoops: false
    312. }
    313. ],
    314. /**
    315. * 禁止在构造函数中返回值
    316. */
    317. 'no-constructor-return': 'error',
    318. /**
    319. * 禁止使用 continue
    320. */
    321. 'no-continue': 'off',
    322. /**
    323. * 禁止在正则表达式中出现 Ctrl 键的 ASCII 表示,即禁止使用 /\x1f/
    324. * @reason 几乎不会遇到这种场景
    325. */
    326. 'no-control-regex': 'off',
    327. /**
    328. * 禁止使用 debugger
    329. */
    330. 'no-debugger': 'error',
    331. /**
    332. * 禁止对一个变量使用 delete
    333. * @reason 编译阶段就会报错了
    334. */
    335. 'no-delete-var': 'off',
    336. /**
    337. * 禁止在正则表达式中出现形似除法操作符的开头,如 let a = /=foo/
    338. * @reason 有代码高亮的话,在阅读这种代码时,也完全不会产生歧义或理解上的困难
    339. */
    340. 'no-div-regex': 'off',
    341. /**
    342. * 禁止在函数参数中出现重复名称的参数
    343. * @reason 编译阶段就会报错了
    344. */
    345. 'no-dupe-args': 'off',
    346. /**
    347. * 禁止重复定义类的成员
    348. */
    349. 'no-dupe-class-members': 'error',
    350. /**
    351. * 禁止 if else 的条件判断中出现重复的条件
    352. */
    353. 'no-dupe-else-if': 'error',
    354. /**
    355. * 禁止在对象字面量中出现重复的键名
    356. */
    357. 'no-dupe-keys': 'error',
    358. /**
    359. * 禁止在 switch 语句中出现重复测试表达式的 case
    360. */
    361. 'no-duplicate-case': 'error',
    362. /**
    363. * 禁止重复导入模块
    364. */
    365. 'no-duplicate-imports': 'error',
    366. /**
    367. * 禁止在 else 内使用 return,必须改为提前结束
    368. * @reason else 中使用 return 可以使代码结构更清晰
    369. */
    370. 'no-else-return': 'off',
    371. /**
    372. * 禁止出现空代码块,允许 catch 为空代码块
    373. */
    374. 'no-empty': [
    375. 'error',
    376. {
    377. allowEmptyCatch: true
    378. }
    379. ],
    380. /**
    381. * 禁止在正则表达式中使用空的字符集 []
    382. */
    383. 'no-empty-character-class': 'error',
    384. /**
    385. * 不允许有空函数
    386. * @reason 有时需要将一个空函数设置为某个项的默认值
    387. */
    388. 'no-empty-function': 'off',
    389. /**
    390. * 禁止解构赋值中出现空 {} 或 []
    391. */
    392. 'no-empty-pattern': 'error',
    393. /**
    394. * 禁止使用 foo == null,必须使用 foo === null
    395. */
    396. 'no-eq-null': 'error',
    397. /**
    398. * 禁止使用 eval
    399. */
    400. 'no-eval': 'error',
    401. /**
    402. * 禁止将 catch 的第一个参数 error 重新赋值
    403. */
    404. 'no-ex-assign': 'error',
    405. /**
    406. * 禁止修改原生对象
    407. * @reason 修改原生对象可能会与将来版本的 js 冲突
    408. */
    409. 'no-extend-native': 'error',
    410. /**
    411. * 禁止出现没必要的 bind
    412. */
    413. 'no-extra-bind': 'error',
    414. /**
    415. * 禁止不必要的布尔类型转换
    416. */
    417. 'no-extra-boolean-cast': 'error',
    418. /**
    419. * 禁止出现没必要的 label
    420. * @reason 已经禁止使用 label 了
    421. */
    422. 'no-extra-label': 'off',
    423. /**
    424. * switch 的 case 内必须有 break, return 或 throw,空的 case 除外
    425. */
    426. 'no-fallthrough': 'error',
    427. /**
    428. * 禁止将一个函数声明重新赋值
    429. */
    430. 'no-func-assign': 'error',
    431. /**
    432. * 禁止对全局变量赋值
    433. */
    434. 'no-global-assign': 'error',
    435. /**
    436. * 禁止使用 ~+ 等难以理解的类型转换,仅允许使用 !!
    437. */
    438. 'no-implicit-coercion': [
    439. 'error',
    440. {
    441. allow: ['!!']
    442. }
    443. ],
    444. /**
    445. * 禁止在全局作用域下定义变量或申明函数
    446. * @reason 模块化之后,不会出现这种在全局作用域下定义变量的情况
    447. */
    448. 'no-implicit-globals': 'off',
    449. /**
    450. * 禁止在 setTimeout 或 setInterval 中传入字符串
    451. */
    452. 'no-implied-eval': 'error',
    453. /**
    454. * 禁止对导入的模块进行赋值
    455. */
    456. 'no-import-assign': 'error',
    457. /**
    458. * 禁止在代码后添加单行注释
    459. */
    460. 'no-inline-comments': 'off',
    461. /**
    462. * 禁止在 if 代码块内出现函数声明
    463. */
    464. 'no-inner-declarations': ['error', 'both'],
    465. /**
    466. * 禁止在 RegExp 构造函数中出现非法的正则表达式
    467. */
    468. 'no-invalid-regexp': 'error',
    469. /**
    470. * 禁止在类之外的地方使用 this
    471. * @reason 只允许在 class 中使用 this
    472. */
    473. 'no-invalid-this': 'error',
    474. /**
    475. * 禁止使用特殊空白符(比如全角空格),除非是出现在字符串、正则表达式或模版字符串中
    476. */
    477. 'no-irregular-whitespace': [
    478. 'error',
    479. {
    480. skipStrings: true,
    481. skipComments: false,
    482. skipRegExps: true,
    483. skipTemplates: true
    484. }
    485. ],
    486. /**
    487. * 禁止使用 __iterator__
    488. * @reason __iterator__ 是一个已废弃的属性
    489. * 使用 [Symbol.iterator] 替代它
    490. */
    491. 'no-iterator': 'error',
    492. /**
    493. * 禁止 label 名称与已定义的变量重复
    494. * @reason 已经禁止使用 label 了
    495. */
    496. 'no-label-var': 'off',
    497. /**
    498. * 禁止使用 label
    499. */
    500. 'no-labels': 'error',
    501. /**
    502. * 禁止使用没必要的 {} 作为代码块
    503. */
    504. 'no-lone-blocks': 'error',
    505. /**
    506. * 禁止 else 中只有一个单独的 if
    507. * @reason 单独的 if 可以把逻辑表达的更清楚
    508. */
    509. 'no-lonely-if': 'off',
    510. /**
    511. * 禁止在循环内的函数内部出现循环体条件语句中定义的变量
    512. * @reason 使用 let 就已经解决了这个问题了
    513. */
    514. 'no-loop-func': 'off',
    515. /**
    516. * 禁止使用 magic numbers
    517. */
    518. 'no-magic-numbers': 'off',
    519. /**
    520. * 禁止正则表达式中使用肉眼无法区分的特殊字符
    521. * @reason 某些特殊字符很难看出差异,最好不要在正则中使用
    522. */
    523. 'no-misleading-character-class': 'error',
    524. /**
    525. * 相同类型的 require 必须放在一起
    526. */
    527. 'no-mixed-requires': 'off',
    528. /**
    529. * 禁止连续赋值,比如 foo = bar = 1
    530. */
    531. 'no-multi-assign': 'off',
    532. /**
    533. * 禁止使用 \ 来换行字符串
    534. */
    535. 'no-multi-str': 'error',
    536. /**
    537. * 禁止 if 里有否定的表达式
    538. * @reason 否定的表达式可以把逻辑表达的更清楚
    539. */
    540. 'no-negated-condition': 'off',
    541. /**
    542. * 禁止使用嵌套的三元表达式,比如 a ? b : c ? d : e
    543. */
    544. 'no-nested-ternary': 'off',
    545. /**
    546. * 禁止直接 new 一个类而不赋值
    547. * @reason new 应该作为创建一个类的实例的方法,所以不能不赋值
    548. */
    549. 'no-new': 'error',
    550. /**
    551. * 禁止使用 new Function
    552. * @reason 这和 eval 是等价的
    553. */
    554. 'no-new-func': 'error',
    555. /**
    556. * 禁止直接 new Object
    557. */
    558. 'no-new-object': 'error',
    559. /**
    560. * 禁止直接 new require('foo')
    561. */
    562. 'no-new-require': 'error',
    563. /**
    564. * 禁止使用 new 来生成 Symbol
    565. */
    566. 'no-new-symbol': 'error',
    567. /**
    568. * 禁止使用 new 来生成 String, Number 或 Boolean
    569. */
    570. 'no-new-wrappers': 'error',
    571. /**
    572. * 禁止将 Math, JSON 或 Reflect 直接作为函数调用
    573. */
    574. 'no-obj-calls': 'error',
    575. /**
    576. * 禁止使用 0 开头的数字表示八进制数
    577. * @reason 编译阶段就会报错了
    578. */
    579. 'no-octal': 'off',
    580. /**
    581. * 禁止使用八进制的转义符
    582. * @reason 编译阶段就会报错了
    583. */
    584. 'no-octal-escape': 'off',
    585. /**
    586. * 禁止对函数的参数重新赋值
    587. */
    588. 'no-param-reassign': 'error',
    589. /**
    590. * 禁止对 __dirname 或 __filename 使用字符串连接
    591. * @reason 不同平台下的路径符号不一致,建议使用 path 处理平台差异性
    592. */
    593. 'no-path-concat': 'error',
    594. /**
    595. * 禁止使用 ++ 或 --
    596. */
    597. 'no-plusplus': 'off',
    598. /**
    599. * 禁止使用 process.env.NODE_ENV
    600. */
    601. 'no-process-env': 'off',
    602. /**
    603. * 禁止使用 process.exit(0)
    604. */
    605. 'no-process-exit': 'off',
    606. /**
    607. * 禁止使用 __proto__
    608. * @reason __proto__ 是已废弃的语法
    609. */
    610. 'no-proto': 'error',
    611. /**
    612. * 禁止使用 hasOwnProperty, isPrototypeOf 或 propertyIsEnumerable
    613. * @reason hasOwnProperty 比较常用
    614. */
    615. 'no-prototype-builtins': 'off',
    616. /**
    617. * 禁止重复定义变量
    618. * @reason 禁用 var 之后,编译阶段就会报错了
    619. */
    620. 'no-redeclare': 'off',
    621. /**
    622. * 禁止在正则表达式中出现连续的空格
    623. */
    624. 'no-regex-spaces': 'error',
    625. /**
    626. * 禁止使用指定的全局变量
    627. */
    628. 'no-restricted-globals': 'off',
    629. /**
    630. * 禁止导入指定的模块
    631. */
    632. 'no-restricted-imports': 'off',
    633. /**
    634. * 禁止使用指定的模块
    635. */
    636. 'no-restricted-modules': 'off',
    637. /**
    638. * 禁止使用指定的对象属性
    639. */
    640. 'no-restricted-properties': 'off',
    641. /**
    642. * 禁止使用指定的语法
    643. */
    644. 'no-restricted-syntax': 'off',
    645. /**
    646. * 禁止在 return 语句里赋值
    647. */
    648. 'no-return-assign': ['error', 'always'],
    649. /**
    650. * 禁止在 return 语句里使用 await
    651. */
    652. 'no-return-await': 'error',
    653. /**
    654. * 禁止出现 location.href = 'javascript:void(0)';
    655. * @reason 有些场景下还是需要用到这个
    656. */
    657. 'no-script-url': 'off',
    658. /**
    659. * 禁止将自己赋值给自己
    660. */
    661. 'no-self-assign': 'error',
    662. /**
    663. * 禁止将自己与自己比较
    664. */
    665. 'no-self-compare': 'error',
    666. /**
    667. * 禁止使用逗号操作符
    668. */
    669. 'no-sequences': 'error',
    670. /**
    671. * 禁止 setter 有返回值
    672. */
    673. 'no-setter-return': 'error',
    674. /**
    675. * 禁止变量名与上层作用域内的已定义的变量重复
    676. * @reason 很多时候函数的形参和传参是同名的
    677. */
    678. 'no-shadow': 'off',
    679. /**
    680. * 禁止使用保留字作为变量名
    681. */
    682. 'no-shadow-restricted-names': 'error',
    683. /**
    684. * 禁止在数组中出现连续的逗号
    685. */
    686. 'no-sparse-arrays': 'error',
    687. /**
    688. * 禁止使用 node 中的同步的方法,比如 fs.readFileSync
    689. */
    690. 'no-sync': 'off',
    691. /**
    692. * 禁止在普通字符串中出现模版字符串里的变量形式
    693. */
    694. 'no-template-curly-in-string': 'error',
    695. /**
    696. * 禁止使用三元表达式
    697. */
    698. 'no-ternary': 'off',
    699. /**
    700. * 禁止在 super 被调用之前使用 this 或 super
    701. */
    702. 'no-this-before-super': 'error',
    703. /**
    704. * 禁止 throw 字面量,必须 throw 一个 Error 对象
    705. */
    706. 'no-throw-literal': 'error',
    707. /**
    708. * 禁止使用未定义的变量
    709. */
    710. 'no-undef': 'error',
    711. /**
    712. * 禁止将 undefined 赋值给变量
    713. */
    714. 'no-undef-init': 'error',
    715. /**
    716. * 禁止使用 undefined
    717. */
    718. 'no-undefined': 'off',
    719. /**
    720. * 禁止变量名出现下划线
    721. */
    722. 'no-underscore-dangle': 'off',
    723. /**
    724. * 循环内必须对循环条件中的变量有修改
    725. */
    726. 'no-unmodified-loop-condition': 'error',
    727. /**
    728. * 必须使用 !a 替代 a ? false : true
    729. * @reason 后者表达的更清晰
    730. */
    731. 'no-unneeded-ternary': 'off',
    732. /**
    733. * 禁止在 return, throw, break 或 continue 之后还有代码
    734. */
    735. 'no-unreachable': 'error',
    736. /**
    737. * 禁止在 finally 中出现 return, throw, break 或 continue
    738. * @reason finally 中的语句会在 try 之前执行
    739. */
    740. 'no-unsafe-finally': 'error',
    741. /**
    742. * 禁止在 in 或 instanceof 操作符的左侧变量前使用感叹号
    743. */
    744. 'no-unsafe-negation': 'error',
    745. /**
    746. * 禁止无用的表达式
    747. */
    748. 'no-unused-expressions': [
    749. 'error',
    750. {
    751. allowShortCircuit: true,
    752. allowTernary: true,
    753. allowTaggedTemplates: true
    754. }
    755. ],
    756. /**
    757. * 禁止出现没用到的 label
    758. * @reason 已经禁止使用 label 了
    759. */
    760. 'no-unused-labels': 'off',
    761. /**
    762. * 已定义的变量必须使用
    763. */
    764. 'no-unused-vars': [
    765. 'error',
    766. {
    767. vars: 'all',
    768. args: 'none',
    769. ignoreRestSiblings: false,
    770. caughtErrors: 'none'
    771. }
    772. ],
    773. /**
    774. * 变量必须先定义后使用
    775. */
    776. 'no-use-before-define': [
    777. 'error',
    778. {
    779. variables: false,
    780. functions: false,
    781. classes: false
    782. }
    783. ],
    784. /**
    785. * 禁止出现没必要的 call 或 apply
    786. */
    787. 'no-useless-call': 'error',
    788. /**
    789. * 禁止在 catch 中仅仅只是把错误 throw 出去
    790. * @reason 这样的 catch 是没有意义的,等价于直接执行 try 里的代码
    791. */
    792. 'no-useless-catch': 'error',
    793. /**
    794. * 禁止出现没必要的计算键名
    795. */
    796. 'no-useless-computed-key': 'error',
    797. /**
    798. * 禁止出现没必要的字符串连接
    799. */
    800. 'no-useless-concat': 'error',
    801. /**
    802. * 禁止出现没必要的 constructor
    803. */
    804. 'no-useless-constructor': 'error',
    805. /**
    806. * 禁止出现没必要的转义
    807. * @reason 转义可以使代码更易懂
    808. */
    809. 'no-useless-escape': 'off',
    810. /**
    811. * 禁止解构赋值时出现同样名字的的重命名,比如 let { foo: foo } = bar;
    812. */
    813. 'no-useless-rename': 'error',
    814. /**
    815. * 禁止没必要的 return
    816. */
    817. 'no-useless-return': 'off',
    818. /**
    819. * 禁止使用 var
    820. */
    821. 'no-var': 'error',
    822. /**
    823. * 禁止使用 void
    824. */
    825. 'no-void': 'error',
    826. /**
    827. * 禁止注释中出现 TODO 和 FIXME
    828. */
    829. 'no-warning-comments': 'off',
    830. /**
    831. * 禁止使用 with
    832. * @reason 编译阶段就会报错了
    833. */
    834. 'no-with': 'off',
    835. /**
    836. * 必须使用 a = {b} 而不是 a = {b: b}
    837. * @reason 有时后者可以使代码结构更清晰
    838. */
    839. 'object-shorthand': 'off',
    840. /**
    841. * 禁止变量申明时用逗号一次申明多个
    842. */
    843. 'one-var': ['error', 'never'],
    844. /**
    845. * 必须使用 x = x + y 而不是 x += y
    846. */
    847. 'operator-assignment': 'off',
    848. /**
    849. * 限制语句之间的空行规则,比如变量定义完之后必须要空行
    850. */
    851. 'padding-line-between-statements': 'off',
    852. /**
    853. * 申明后不再被修改的变量必须使用 const 来申明
    854. */
    855. 'prefer-const': 'off',
    856. /**
    857. * 必须使用解构赋值
    858. */
    859. 'prefer-destructuring': 'off',
    860. /**
    861. * 使用 ES2016 的语法 ** 替代 Math.pow
    862. */
    863. 'prefer-exponentiation-operator': 'off',
    864. /**
    865. * 使用 ES2018 中的正则表达式命名组
    866. * @reason 正则表达式已经较难理解了,没必要强制加上命名组
    867. */
    868. 'prefer-named-capture-group': 'off',
    869. /**
    870. * 必须使用 0b11111011 而不是 parseInt()
    871. */
    872. 'prefer-numeric-literals': 'off',
    873. /**
    874. * 必须使用 ... 而不是 Object.assign,除非 Object.assign 的第一个参数是一个变量
    875. */
    876. 'prefer-object-spread': 'error',
    877. /**
    878. * Promise 的 reject 中必须传入 Error 对象,而不是字面量
    879. */
    880. 'prefer-promise-reject-errors': 'error',
    881. /**
    882. * 优先使用正则表达式字面量,而不是 RegExp 构造函数
    883. */
    884. 'prefer-regex-literals': 'error',
    885. /**
    886. * 必须使用 ...args 而不是 arguments
    887. */
    888. 'prefer-rest-params': 'off',
    889. /**
    890. * 必须使用 ... 而不是 apply,比如 foo(...args)
    891. */
    892. 'prefer-spread': 'off',
    893. /**
    894. * 必须使用模版字符串而不是字符串连接
    895. */
    896. 'prefer-template': 'off',
    897. /**
    898. * parseInt 必须传入第二个参数
    899. */
    900. radix: 'error',
    901. /**
    902. * 禁止将 await 或 yield 的结果做为运算符的后面项
    903. * @reason 这样会导致不符合预期的结果
    904. * https://github.com/eslint/eslint/issues/11899
    905. * 在上面 issue 修复之前,关闭此规则
    906. */
    907. 'require-atomic-updates': 'off',
    908. /**
    909. * async 函数中必须存在 await 语句
    910. */
    911. 'require-await': 'off',
    912. /**
    913. * 正则表达式中必须要加上 u 标志
    914. */
    915. 'require-unicode-regexp': 'off',
    916. /**
    917. * generator 函数内必须有 yield
    918. */
    919. 'require-yield': 'error',
    920. /**
    921. * 导入必须按规则排序
    922. */
    923. 'sort-imports': 'off',
    924. /**
    925. * 对象字面量的键名必须排好序
    926. */
    927. 'sort-keys': 'off',
    928. /**
    929. * 变量申明必须排好序
    930. */
    931. 'sort-vars': 'off',
    932. /**
    933. * 注释的斜线或 * 后必须有空格
    934. */
    935. 'spaced-comment': [
    936. 'error',
    937. 'always',
    938. {
    939. block: {
    940. exceptions: ['*'],
    941. balanced: true
    942. }
    943. }
    944. ],
    945. /**
    946. * 禁止使用 'strict';
    947. */
    948. strict: ['error', 'never'],
    949. /**
    950. * 创建 Symbol 时必须传入参数
    951. */
    952. 'symbol-description': 'error',
    953. /**
    954. * 必须使用 isNaN(foo) 而不是 foo === NaN
    955. */
    956. 'use-isnan': 'error',
    957. /**
    958. * typeof 表达式比较的对象必须是 'undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 或 'bigint'
    959. */
    960. 'valid-typeof': 'error',
    961. /**
    962. * var 必须在作用域的最前面
    963. */
    964. 'vars-on-top': 'off',
    965. /**
    966. * 必须使用 if (foo === 5) 而不是 if (5 === foo)
    967. */
    968. yoda: [
    969. 'error',
    970. 'never',
    971. {
    972. onlyEquality: true
    973. }
    974. ]
    975. }
    976. };