index.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /**
  2. * AlloyTeam TSLint 规则
  3. *
  4. * 作者: xcatliu <xcatliu@gmail.com>
  5. * 仓库: https://github.com/AlloyTeam/tslint-config-alloy
  6. *
  7. * 基于 tslint@5.11.0
  8. * 此文件是由脚本 scripts/build.ts 自动生成
  9. *
  10. * @category 此规则属于哪种分类
  11. * @description 一句话描述此规则
  12. * @reason 为什么要开启(关闭)此规则
  13. * @ts-only 仅支持 ts 文件
  14. * @has-fixer 支持自动修复
  15. * @requires-type-info 需要提供类型信息(需要 --project 参数)
  16. * @prettier 可交由 prettier 控制
  17. */
  18. module.exports = {
  19. rules: {
  20. /**
  21. * @category typescript-specific
  22. * @description 重载的函数必须写在一起
  23. * @ts-only 仅支持 ts 文件
  24. */
  25. 'adjacent-overload-signatures': true,
  26. /**
  27. * @category typescript-specific
  28. * @description 禁用特定的类型
  29. * @reason 该规则用于禁止某个具体的类型的使用
  30. * @ts-only 仅支持 ts 文件
  31. */
  32. 'ban-types': false,
  33. /**
  34. * @category typescript-specific
  35. * @description 必须设置类的成员的可访问性
  36. * @reason 将不需要公开的成员设为私有的,可以增强代码的可理解性,对文档输出也很友好
  37. * @ts-only 仅支持 ts 文件
  38. * @has-fixer 支持自动修复
  39. */
  40. 'member-access': [true, 'check-accessor', 'check-constructor', 'check-parameter-property'],
  41. /**
  42. * @category typescript-specific
  43. * @description 指定类成员的排序规则
  44. * @reason 优先级:
  45. * 1. static > instance
  46. * 2. field > constructor > method
  47. * 3. public > protected > private
  48. * @has-fixer 支持自动修复
  49. */
  50. 'member-ordering': [
  51. true,
  52. {
  53. order: [
  54. 'public-static-field',
  55. 'protected-static-field',
  56. 'private-static-field',
  57. 'public-static-method',
  58. 'protected-static-method',
  59. 'private-static-method',
  60. 'public-instance-field',
  61. 'protected-instance-field',
  62. 'private-instance-field',
  63. 'public-constructor',
  64. 'protected-constructor',
  65. 'private-constructor',
  66. 'public-instance-method',
  67. 'protected-instance-method',
  68. 'private-instance-method'
  69. ]
  70. }
  71. ],
  72. /**
  73. * @category typescript-specific
  74. * @description 禁止使用 any
  75. * @reason 太严格了
  76. * @ts-only 仅支持 ts 文件
  77. */
  78. 'no-any': false,
  79. /**
  80. * @category typescript-specific
  81. * @description 禁止定义空的接口
  82. * @ts-only 仅支持 ts 文件
  83. */
  84. 'no-empty-interface': true,
  85. /**
  86. * @category typescript-specific
  87. * @description 禁止导入有副作用(立即执行)的模块,除了 css, less, sass, scss
  88. * @reason 有副作用(立即执行)的模块无法控制其执行过程
  89. */
  90. 'no-import-side-effect': [true, { 'ignore-module': '(\\.css|\\.less|\\.sass|\\.scss)$' }],
  91. /**
  92. * @category typescript-specific
  93. * @description 禁止给一个初始化时直接赋值为 number, string 或 boolean 的变量显式的指定类型
  94. * @reason 可以简化代码,并且支持自动修复
  95. * @ts-only 仅支持 ts 文件
  96. * @has-fixer 支持自动修复
  97. */
  98. 'no-inferrable-types': true,
  99. /**
  100. * @category typescript-specific
  101. * @description 禁止使用 module 来定义命名空间
  102. * @reason module 已成为 js 的关键字
  103. * @ts-only 仅支持 ts 文件
  104. * @has-fixer 支持自动修复
  105. */
  106. 'no-internal-module': true,
  107. /**
  108. * @category typescript-specific
  109. * @description 禁止使用魔法数字,仅允许使用一部分白名单中的数字
  110. * @reason 魔法数字无法理解
  111. */
  112. 'no-magic-numbers': [true, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 10000],
  113. /**
  114. * @category typescript-specific
  115. * @description 禁止使用 namespace 来定义命名空间
  116. * @reason 使用 es6 引入模块,才是更标准的方式。
  117. * 允许使用 declare namespace ... {} 来定义外部命名空间
  118. * @ts-only 仅支持 ts 文件
  119. */
  120. 'no-namespace': [true, 'allow-declarations'],
  121. /**
  122. * @category typescript-specific
  123. * @description 禁止使用 non-null 断言(感叹号)
  124. * @reason non-null 断言不安全,最好使用条件语句把 null 排除掉比较好
  125. * @ts-only 仅支持 ts 文件
  126. */
  127. 'no-non-null-assertion': true,
  128. /**
  129. * @category typescript-specific
  130. * @description 禁止对函数的参数重新赋值
  131. */
  132. 'no-parameter-reassignment': true,
  133. /**
  134. * @category typescript-specific
  135. * @description 禁止使用三斜线引入模块 /// <reference path="foo" />
  136. * @reason 引入模块时应使用更先进的 import 语法
  137. * 三斜线仅能用于引入一个类型文件 /// <reference types="foo" />
  138. */
  139. 'no-reference': true,
  140. /**
  141. * @category typescript-specific
  142. * @description 禁止无用的类型断言
  143. * @reason Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  144. * @ts-only 仅支持 ts 文件
  145. * @has-fixer 支持自动修复
  146. * @requires-type-info 需要提供类型信息
  147. */
  148. 'no-unnecessary-type-assertion': false,
  149. /**
  150. * @category typescript-specific
  151. * @description 禁止使用 require 来引入模块
  152. * @reason 统一使用 import 来引入模块,特殊情况使用单行注释允许 require 引入
  153. * @ts-only 仅支持 ts 文件
  154. */
  155. 'no-var-requires': true,
  156. /**
  157. * @category typescript-specific
  158. * @description 必须使用箭头函数,除非是单独的函数声明或是命名函数
  159. * @reason 统一使用箭头函数,避免 this 指向问题
  160. */
  161. 'only-arrow-functions': [true, 'allow-declarations', 'allow-named-functions'],
  162. /**
  163. * @category typescript-specific
  164. * @description 使用 for 循环遍历数组时,如果 index 仅用于获取成员,则必须使用 for of 循环替代 for 循环
  165. * @reason for of 循环更加易读
  166. */
  167. 'prefer-for-of': true,
  168. /**
  169. * @category typescript-specific
  170. * @description async 函数的返回值必须是 Promise
  171. * @reason 有时 async 函数在某个分支是同步的,不需要返回 Promise
  172. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  173. * @requires-type-info 需要提供类型信息
  174. */
  175. 'promise-function-async': false,
  176. /**
  177. * @category typescript-specific
  178. * @description 变量、函数返回值、函数参数等必须要有类型定义
  179. * @reason 大部分类型都可以依靠类型推论,没必要全部手动定义
  180. * @ts-only 仅支持 ts 文件
  181. */
  182. typedef: false,
  183. /**
  184. * @category typescript-specific
  185. * @description 类型定义的冒号前面必须没有空格,后面必须有一个空格
  186. * @ts-only 仅支持 ts 文件
  187. * @has-fixer 支持自动修复
  188. * @prettier 可交由 prettier 控制
  189. */
  190. 'typedef-whitespace': [
  191. true,
  192. {
  193. 'call-signature': 'nospace',
  194. 'index-signature': 'nospace',
  195. parameter: 'nospace',
  196. 'property-declaration': 'nospace',
  197. 'variable-declaration': 'nospace'
  198. },
  199. {
  200. 'call-signature': 'onespace',
  201. 'index-signature': 'onespace',
  202. parameter: 'onespace',
  203. 'property-declaration': 'onespace',
  204. 'variable-declaration': 'onespace'
  205. }
  206. ],
  207. /**
  208. * @category typescript-specific
  209. * @description 函数重载时,若能通过联合类型将两个函数的类型声明合为一个,则使用联合类型而不是两个函数声明
  210. * @ts-only 仅支持 ts 文件
  211. */
  212. 'unified-signatures': true,
  213. /**
  214. * @category functionality
  215. * @description await 必须接受 Promise
  216. * @reason promise-function-async 里已经允许 async 函数返回值为非 Promise 了,故也应该允许 await 接受非 Promise
  217. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  218. * @ts-only 仅支持 ts 文件
  219. * @requires-type-info 需要提供类型信息
  220. */
  221. 'await-promise': false,
  222. /**
  223. * @category functionality
  224. * @description 禁用指定的函数或全局方法
  225. * @reason 用于限制某个具体的函数不能使用
  226. */
  227. ban: false,
  228. /**
  229. * @category functionality
  230. * @description 禁止使用逗号操作符
  231. */
  232. 'ban-comma-operator': true,
  233. /**
  234. * @category functionality
  235. * @description if 后面必须有 {,除非是单行 if
  236. * @has-fixer 支持自动修复
  237. */
  238. curly: [true, 'ignore-same-line'],
  239. /**
  240. * @category functionality
  241. * @description for in 内部必须有 hasOwnProperty
  242. */
  243. forin: true,
  244. /**
  245. * @category functionality
  246. * @description 禁用指定的模块
  247. * @reason 用于限制某个具体的模块不能使用
  248. */
  249. 'import-blacklist': false,
  250. /**
  251. * @category functionality
  252. * @description 只允许在 do, for, while 或 switch 中使用 label
  253. * @reason 在任何情况都不应该使用 label
  254. */
  255. 'label-position': false,
  256. /**
  257. * @category functionality
  258. * @description 禁止使用 arguments.callee
  259. */
  260. 'no-arg': true,
  261. /**
  262. * @category functionality
  263. * @description 禁止使用位运算
  264. * @reason 位运算很常见
  265. */
  266. 'no-bitwise': false,
  267. /**
  268. * @category functionality
  269. * @description 禁止在分支条件判断中有赋值操作
  270. */
  271. 'no-conditional-assignment': true,
  272. /**
  273. * @category functionality
  274. * @description 禁止使用 console
  275. * @reason 没必要禁止,会让 autofixOnSave 很不方便
  276. */
  277. 'no-console': false,
  278. /**
  279. * @category functionality
  280. * @description 禁止使用 new 来生成 String, Number 或 Boolean
  281. */
  282. 'no-construct': true,
  283. /**
  284. * @category functionality
  285. * @description 禁止使用 debugger
  286. * @reason 没必要禁止,会让 autofixOnSave 很不方便
  287. */
  288. 'no-debugger': false,
  289. /**
  290. * @category functionality
  291. * @description 禁止 super 在一个构造函数中出现两次
  292. */
  293. 'no-duplicate-super': true,
  294. /**
  295. * @category functionality
  296. * @description 禁止在 switch 语句中出现重复测试表达式的 case
  297. */
  298. 'no-duplicate-switch-case': true,
  299. /**
  300. * @category functionality
  301. * @description 禁止出现重复的变量定义或函数参数名
  302. */
  303. 'no-duplicate-variable': [true, 'check-parameters'],
  304. /**
  305. * @category functionality
  306. * @description 禁止 delete 动态的值
  307. * @reason 没必要限制
  308. */
  309. 'no-dynamic-delete': false,
  310. /**
  311. * @category functionality
  312. * @description 禁止出现空代码块,允许 catch 是空代码块
  313. */
  314. 'no-empty': [true, 'allow-empty-catch', 'allow-empty-functions'],
  315. /**
  316. * @category functionality
  317. * @description 禁止使用 eval
  318. */
  319. 'no-eval': true,
  320. /**
  321. * @category functionality
  322. * @description 函数返回值为 Promise 时,必须被处理
  323. * @reason 太严格了
  324. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  325. * @ts-only 仅支持 ts 文件
  326. * @requires-type-info 需要提供类型信息
  327. */
  328. 'no-floating-promises': false,
  329. /**
  330. * @category functionality
  331. * @description 禁止对 array 使用 for in 循环
  332. * @reason 没必要限制
  333. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  334. * @requires-type-info 需要提供类型信息
  335. */
  336. 'no-for-in-array': false,
  337. /**
  338. * @category functionality
  339. * @description 禁止引入 package.json 中不存在的模块
  340. */
  341. 'no-implicit-dependencies': [true, 'dev'],
  342. /**
  343. * @category functionality
  344. * @description 禁止推论出的类型是空对象类型
  345. * @reason 没必要限制
  346. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  347. * @ts-only 仅支持 ts 文件
  348. * @requires-type-info 需要提供类型信息
  349. */
  350. 'no-inferred-empty-object-type': false,
  351. /**
  352. * @category functionality
  353. * @description 禁止在非模版字符串中出现 ${}
  354. */
  355. 'no-invalid-template-strings': true,
  356. /**
  357. * @category functionality
  358. * @description 禁止在类外面使用 this
  359. * @reason 禁止滥用 this,如需使用,在文件中局部禁用此规则即可
  360. */
  361. 'no-invalid-this': true,
  362. /**
  363. * @category functionality
  364. * @description 禁止在接口中定义 constructor,或在类中定义 new
  365. * @ts-only 仅支持 ts 文件
  366. */
  367. 'no-misused-new': false,
  368. /**
  369. * @category functionality
  370. * @description 禁止使用 null
  371. * @reason 没必要限制
  372. * @has-fixer 支持自动修复
  373. */
  374. 'no-null-keyword': false,
  375. /**
  376. * @category functionality
  377. * @description 禁止对对象字面量进行类型断言(断言成 any 是允许的)
  378. * @ts-only 仅支持 ts 文件
  379. */
  380. 'no-object-literal-type-assertion': true,
  381. /**
  382. * @category functionality
  383. * @description 禁止没必要的 return await
  384. * @reason return await 用起来没问题
  385. * @has-fixer 支持自动修复
  386. */
  387. 'no-return-await': false,
  388. /**
  389. * @category functionality
  390. * @description 禁止变量名与上层作用域内的定义过的变量重复
  391. * @reason 很多时候函数的形参和传参是同名的
  392. */
  393. 'no-shadowed-variable': false,
  394. /**
  395. * @category functionality
  396. * @description 禁止在数组中出现连续的逗号,如 let foo = [,,]
  397. */
  398. 'no-sparse-arrays': true,
  399. /**
  400. * @category functionality
  401. * @description 禁止出现 foo['bar'],必须写成 foo.bar
  402. * @has-fixer 支持自动修复
  403. */
  404. 'no-string-literal': true,
  405. /**
  406. * @category functionality
  407. * @description 禁止 throw 字符串,必须 throw 一个 Error 对象
  408. * @has-fixer 支持自动修复
  409. */
  410. 'no-string-throw': true,
  411. /**
  412. * @category functionality
  413. * @description 禁止 import 模块的子文件
  414. * @reason 没必要限制
  415. */
  416. 'no-submodule-imports': false,
  417. /**
  418. * @category functionality
  419. * @description switch 的 case 必须 return 或 break
  420. */
  421. 'no-switch-case-fall-through': true,
  422. /**
  423. * @category functionality
  424. * @description 禁止将 this 赋值给其他变量,除非是解构赋值
  425. */
  426. 'no-this-assignment': [true, { 'allow-destructuring': true }],
  427. /**
  428. * @category functionality
  429. * @description 使用实例的方法时,必须 bind 到实例上
  430. * @reason Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  431. * @ts-only 仅支持 ts 文件
  432. * @requires-type-info 需要提供类型信息
  433. */
  434. 'no-unbound-method': false,
  435. /**
  436. * @category functionality
  437. * @description 禁止定义没必要的类,比如只有静态方法的类
  438. * @reason 没必要限制
  439. */
  440. 'no-unnecessary-class': false,
  441. /**
  442. * @category functionality
  443. * @description 禁止取用一个类型为 any 的对象的属性
  444. * @reason 太严格了
  445. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  446. * @ts-only 仅支持 ts 文件
  447. * @requires-type-info 需要提供类型信息
  448. */
  449. 'no-unsafe-any': false,
  450. /**
  451. * @category functionality
  452. * @description 禁止 finally 内出现 return, continue, break, throw 等
  453. * @reason finally 会比 catch 先执行
  454. */
  455. 'no-unsafe-finally': true,
  456. /**
  457. * @category functionality
  458. * @description 禁止无用的表达式
  459. */
  460. 'no-unused-expression': true,
  461. /**
  462. * @category functionality
  463. * @description 变量必须先定义后使用
  464. * @reason 循环引用没法处理
  465. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  466. * @requires-type-info 需要提供类型信息
  467. */
  468. 'no-use-before-declare': false,
  469. /**
  470. * @category functionality
  471. * @description 禁止使用 var
  472. * @has-fixer 支持自动修复
  473. */
  474. 'no-var-keyword': true,
  475. /**
  476. * @category functionality
  477. * @description 禁止返回值为 void 类型
  478. * @reason 没必要限制,void 很常用
  479. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  480. * @requires-type-info 需要提供类型信息
  481. */
  482. 'no-void-expression': false,
  483. /**
  484. * @category functionality
  485. * @description 可以用三元表达式时,就不用 if else
  486. * @reason 没必要限制
  487. */
  488. 'prefer-conditional-expression': false,
  489. /**
  490. * @category functionality
  491. * @description 使用 { ...foo, bar: 1 } 代替 Object.assign({}, foo, { bar: 1 })
  492. * @reason 前者的类型检查更完善
  493. * @has-fixer 支持自动修复
  494. */
  495. 'prefer-object-spread': true,
  496. /**
  497. * @category functionality
  498. * @description parseInt 必须传入第二个参数
  499. */
  500. radix: true,
  501. /**
  502. * @category functionality
  503. * @description 使用加号时,两者必须同为数字或同为字符串
  504. * @reason 太严格了
  505. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  506. * @requires-type-info 需要提供类型信息
  507. */
  508. 'restrict-plus-operands': false,
  509. /**
  510. * @category functionality
  511. * @description 在分支条件判断中必须传入布尔类型的值
  512. * @reason 太严格了
  513. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  514. * @ts-only 仅支持 ts 文件
  515. * @requires-type-info 需要提供类型信息
  516. */
  517. 'strict-boolean-expressions': false,
  518. /**
  519. * @category functionality
  520. * @description 禁止出现永远为 true 或永远为 false 的条件判断(通过类型预测出一个表达式为 true 还是 false)
  521. * @reason 没必要限制
  522. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  523. * @ts-only 仅支持 ts 文件
  524. * @requires-type-info 需要提供类型信息
  525. */
  526. 'strict-type-predicates': false,
  527. /**
  528. * @category functionality
  529. * @description switch 语句必须有 default
  530. */
  531. 'switch-default': false,
  532. /**
  533. * @category functionality
  534. * @description 必须使用 === 或 !==,禁止使用 == 或 !=
  535. */
  536. 'triple-equals': true,
  537. /**
  538. * @category functionality
  539. * @description typeof 表达式比较的对象必须是 'undefined', 'object', 'boolean', 'number', 'string', 'function' 或 'symbol'
  540. * @reason TypeScirpt 2.2 之后,编译器已经只带了这个功能
  541. */
  542. 'typeof-compare': false,
  543. /**
  544. * @category functionality
  545. * @description 传入的类型与默认类型一致时,必须省略传入的类型
  546. * @reason 没必要限制
  547. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  548. * @ts-only 仅支持 ts 文件
  549. * @requires-type-info 需要提供类型信息
  550. */
  551. 'use-default-type-parameter': false,
  552. /**
  553. * @category functionality
  554. * @description 必须使用 isNaN(foo) 而不是 foo === NaN
  555. */
  556. 'use-isnan': true,
  557. /**
  558. * @category maintainability
  559. * @description 禁止函数的循环复杂度超过 20,详见 https://en.wikipedia.org/wiki/Cyclomatic_complexity
  560. */
  561. 'cyclomatic-complexity': [true, 20],
  562. /**
  563. * @category maintainability
  564. * @description 禁止使用废弃(被标识了 @deprecated)的 API
  565. * @reason 太严格了
  566. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  567. * @requires-type-info 需要提供类型信息
  568. */
  569. deprecation: false,
  570. /**
  571. * @category maintainability
  572. * @description 文件最后一行必须有一个空行
  573. * @has-fixer 支持自动修复
  574. * @prettier 可交由 prettier 控制
  575. */
  576. eofline: true,
  577. /**
  578. * @category maintainability
  579. * @description 一个缩进必须用四个空格替代
  580. * @has-fixer 支持自动修复
  581. * @prettier 可交由 prettier 控制
  582. */
  583. indent: [true, 'spaces', 2],
  584. /**
  585. * @category maintainability
  586. * @description 限制换行符为 LF 或 CRLF
  587. * @reason 没必要限制
  588. * @has-fixer 支持自动修复
  589. * @prettier 可交由 prettier 控制
  590. */
  591. 'linebreak-style': [true, 'LF'],
  592. /**
  593. * @category maintainability
  594. * @description 限制每个文件的类的数量
  595. * @reason 没必要限制
  596. */
  597. 'max-classes-per-file': false,
  598. /**
  599. * @category maintainability
  600. * @description 限制每个文件的行数
  601. * @reason 没必要限制
  602. */
  603. 'max-file-line-count': false,
  604. /**
  605. * @category maintainability
  606. * @description 限制每行字符数
  607. * @reason 没必要限制
  608. * @prettier 可交由 prettier 控制
  609. */
  610. 'max-line-length': false,
  611. /**
  612. * @category maintainability
  613. * @description 禁止使用 default export
  614. * @reason 没必要限制
  615. */
  616. 'no-default-export': false,
  617. /**
  618. * @category maintainability
  619. * @description 禁止出现重复的 import
  620. */
  621. 'no-duplicate-imports': true,
  622. /**
  623. * @category maintainability
  624. * @description 禁止一个文件中出现多个相同的 namespace
  625. * @ts-only 仅支持 ts 文件
  626. */
  627. 'no-mergeable-namespace': true,
  628. /**
  629. * @category maintainability
  630. * @description 禁止使用 require
  631. * @reason 有时需要动态引入,还是需要用 require
  632. */
  633. 'no-require-imports': false,
  634. /**
  635. * @category maintainability
  636. * @description 对象字面量必须按 key 排序
  637. * @reason 太严格了
  638. */
  639. 'object-literal-sort-keys': false,
  640. /**
  641. * @category maintainability
  642. * @description 申明后不再被修改的变量必须使用 const 来申明
  643. * @reason 没必要强制要求
  644. * @has-fixer 支持自动修复
  645. */
  646. 'prefer-const': false,
  647. /**
  648. * @category maintainability
  649. * @description 如果私有变量只在构造函数中被赋值,则必须使用 readonly 修饰符
  650. * @reason 没必要限制
  651. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  652. * @ts-only 仅支持 ts 文件
  653. * @requires-type-info 需要提供类型信息
  654. */
  655. 'prefer-readonly': false,
  656. /**
  657. * @category maintainability
  658. * @description 限制对象、数组、解构赋值等的最后一项末尾是否需要逗号
  659. * @has-fixer 支持自动修复
  660. * @prettier 可交由 prettier 控制
  661. */
  662. 'trailing-comma': [true, { multiline: 'never', singleline: 'never' }],
  663. /**
  664. * @category style
  665. * @description 变量定义需要竖向对其
  666. * @reason 没必要限制
  667. * @has-fixer 支持自动修复
  668. * @prettier 可交由 prettier 控制
  669. */
  670. align: false,
  671. /**
  672. * @category style
  673. * @description 限制必须使用 T[] 或 Array<T> 之中的一种来定义数组的类型
  674. * @reason 没必要限制
  675. * @ts-only 仅支持 ts 文件
  676. * @has-fixer 支持自动修复
  677. */
  678. 'array-type': false,
  679. /**
  680. * @category style
  681. * @description 箭头函数的参数必须有小括号
  682. * @has-fixer 支持自动修复
  683. * @prettier 可交由 prettier 控制
  684. */
  685. 'arrow-parens': true,
  686. /**
  687. * @category style
  688. * @description 箭头函数的函数体只有 return 语句的时候,必须简写
  689. * @has-fixer 支持自动修复
  690. */
  691. 'arrow-return-shorthand': true,
  692. /**
  693. * @category style
  694. * @description 数字字面量必须在加号的右边,即禁止 1 + x
  695. * @reason 没必要限制
  696. */
  697. 'binary-expression-operand-order': false,
  698. /**
  699. * @category style
  700. * @description 可以简写为函数类型的接口或字面类似,必须简写
  701. * @ts-only 仅支持 ts 文件
  702. * @has-fixer 支持自动修复
  703. */
  704. 'callable-types': true,
  705. /**
  706. * @category style
  707. * @description 类名与接口名必须为驼峰式
  708. */
  709. 'class-name': true,
  710. /**
  711. * @category style
  712. * @description 限制单行注释的规则
  713. * @has-fixer 支持自动修复
  714. */
  715. 'comment-format': [true, 'check-space'],
  716. /**
  717. * @category style
  718. * @description 类、函数等必须写注释
  719. * @reason 太严格了
  720. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  721. * @requires-type-info 需要提供类型信息
  722. */
  723. 'completed-docs': false,
  724. /**
  725. * @category style
  726. * @description 文件类型必须是 utf-8
  727. */
  728. encoding: true,
  729. /**
  730. * @category style
  731. * @description 文件的开头必须有指定的字符串
  732. * @reason 太严格了
  733. * @has-fixer 支持自动修复
  734. */
  735. 'file-header': false,
  736. /**
  737. * @category style
  738. * @description 约束文件命名规范
  739. * @reason 没必要约束
  740. */
  741. 'file-name-casing': false,
  742. /**
  743. * @category style
  744. * @description import 语句中,关键字之间的间距必须是一个空格
  745. * @prettier 可交由 prettier 控制
  746. */
  747. 'import-spacing': true,
  748. /**
  749. * @category style
  750. * @description 接口名称必须已 I 开头
  751. * @reason 没必要限制
  752. * @ts-only 仅支持 ts 文件
  753. */
  754. 'interface-name': false,
  755. /**
  756. * @category style
  757. * @description 优先使用接口而不是字面类型
  758. * @reason 接口可以 implement extend 和 merge
  759. * @ts-only 仅支持 ts 文件
  760. * @has-fixer 支持自动修复
  761. */
  762. 'interface-over-type-literal': true,
  763. /**
  764. * @category style
  765. * @description 注释必须符合 JSDoc 规范
  766. */
  767. 'jsdoc-format': [true, 'check-multiline-start'],
  768. /**
  769. * @category style
  770. * @description import 的名称必须和 export default 的名称一致
  771. * @reason 没必要限制
  772. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  773. * @ts-only 仅支持 ts 文件
  774. * @requires-type-info 需要提供类型信息
  775. */
  776. 'match-default-export-name': false,
  777. /**
  778. * @category style
  779. * @description new 后面只必须有一个空格
  780. * @prettier 可交由 prettier 控制
  781. */
  782. 'new-parens': true,
  783. /**
  784. * @category style
  785. * @description return 语句前必须有空行
  786. * @reason 没必要有空行
  787. */
  788. 'newline-before-return': false,
  789. /**
  790. * @category style
  791. * @description 链式调用时,每次调用都必须占用一行
  792. * @reason 没必要限制
  793. * @prettier 可交由 prettier 控制
  794. */
  795. 'newline-per-chained-call': false,
  796. /**
  797. * @category style
  798. * @description 类型断言必须使用 as Type,禁止使用 <Type>
  799. * @reason <Type> 容易被理解为 jsx
  800. * @ts-only 仅支持 ts 文件
  801. * @has-fixer 支持自动修复
  802. */
  803. 'no-angle-bracket-type-assertion': true,
  804. /**
  805. * @category style
  806. * @description 禁止变量与 true 或 false 比较
  807. * @reason 没必要限制
  808. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  809. * @ts-only 仅支持 ts 文件
  810. * @has-fixer 支持自动修复
  811. * @requires-type-info 需要提供类型信息
  812. */
  813. 'no-boolean-literal-compare': false,
  814. /**
  815. * @category style
  816. * @description 禁止连续超过三行空行
  817. * @has-fixer 支持自动修复
  818. * @prettier 可交由 prettier 控制
  819. */
  820. 'no-consecutive-blank-lines': [true, 3],
  821. /**
  822. * @category style
  823. * @description 禁止使用特殊空白符(比如全角空格)
  824. * @has-fixer 支持自动修复
  825. * @prettier 可交由 prettier 控制
  826. */
  827. 'no-irregular-whitespace': true,
  828. /**
  829. * @category style
  830. * @description 禁止给类的构造函数的参数添加修饰符
  831. * @ts-only 仅支持 ts 文件
  832. */
  833. 'no-parameter-properties': true,
  834. /**
  835. * @category style
  836. * @description 禁止 JSDoc 中的冗余类型声明,因为 TypeScirpt 已经包含了大部分功能
  837. * @ts-only 仅支持 ts 文件
  838. */
  839. 'no-redundant-jsdoc': true,
  840. /**
  841. * @category style
  842. * @description 如果已经引入过库,则禁止使用三斜杠引入类型定义文件
  843. * @ts-only 仅支持 ts 文件
  844. */
  845. 'no-reference-import': true,
  846. /**
  847. * @category style
  848. * @description 禁止行尾有空格
  849. * @has-fixer 支持自动修复
  850. * @prettier 可交由 prettier 控制
  851. */
  852. 'no-trailing-whitespace': true,
  853. /**
  854. * @category style
  855. * @description 禁止没必要的函数调用,如 x => f(x) 应该简写为 f
  856. * @reason 没必要限制
  857. */
  858. 'no-unnecessary-callback-wrapper': false,
  859. /**
  860. * @category style
  861. * @description 禁止变量定义时赋值为 undefined
  862. * @has-fixer 支持自动修复
  863. */
  864. 'no-unnecessary-initializer': true,
  865. /**
  866. * @category style
  867. * @description 在命名空间中,可以直接使用内部变量,不需要添加命名空间前缀
  868. * @reason 已经禁止使用命名空间了
  869. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  870. * @ts-only 仅支持 ts 文件
  871. * @has-fixer 支持自动修复
  872. * @requires-type-info 需要提供类型信息
  873. */
  874. 'no-unnecessary-qualifier': false,
  875. /**
  876. * @category style
  877. * @description 小数必须以 0. 开头,禁止以 . 开头,并且不能以 0 结尾
  878. * @prettier 可交由 prettier 控制
  879. */
  880. 'number-literal-format': true,
  881. /**
  882. * @category style
  883. * @description 对象的 key 必须用引号包起来
  884. * @reason 没必要限制
  885. * @has-fixer 支持自动修复
  886. * @prettier 可交由 prettier 控制
  887. */
  888. 'object-literal-key-quotes': false,
  889. /**
  890. * @category style
  891. * @description 必须使用 a = {b} 而不是 a = {b: b}
  892. * @has-fixer 支持自动修复
  893. */
  894. 'object-literal-shorthand': true,
  895. /**
  896. * @category style
  897. * @description if 后的 { 禁止换行
  898. * @has-fixer 支持自动修复
  899. * @prettier 可交由 prettier 控制
  900. */
  901. 'one-line': true,
  902. /**
  903. * @category style
  904. * @description 变量申明必须每行一个,for 循环的初始条件中除外
  905. */
  906. 'one-variable-per-declaration': [true, 'ignore-for-loop'],
  907. /**
  908. * @category style
  909. * @description import 必须排序
  910. * @has-fixer 支持自动修复
  911. */
  912. 'ordered-imports': false,
  913. /**
  914. * @category style
  915. * @description 类中没有使用 this 的方法应该提取成类外的函数
  916. * @reason 太严格了
  917. */
  918. 'prefer-function-over-method': false,
  919. /**
  920. * @category style
  921. * @description 必须使用 foo(): void 而不是 foo: () => void
  922. * @reason 没必要限制
  923. * @has-fixer 支持自动修复
  924. */
  925. 'prefer-method-signature': false,
  926. /**
  927. * @category style
  928. * @description 当 if 中只有 === 时,必须使用 switch 替换 if
  929. * @reason 没必要限制
  930. */
  931. 'prefer-switch': false,
  932. /**
  933. * @category style
  934. * @description 必须使用模版字符串而不是字符串连接
  935. * @reason 字符串连接很常用
  936. */
  937. 'prefer-template': false,
  938. /**
  939. * @category style
  940. * @description 当没有初始值的时候,必须使用 while 而不是 for
  941. * @reason 没必要限制
  942. * @has-fixer 支持自动修复
  943. */
  944. 'prefer-while': false,
  945. /**
  946. * @category style
  947. * @description 必须使用单引号,jsx 中必须使用双引号
  948. * @has-fixer 支持自动修复
  949. * @prettier 可交由 prettier 控制
  950. */
  951. quotemark: [true, 'single', 'jsx-double', 'avoid-template', 'avoid-escape'],
  952. /**
  953. * @category style
  954. * @description 使用 return; 而不是 return undefined;
  955. * @reason 没必要限制
  956. * Requires Type Info 的规则,无法在编辑器中显示错误,不方便修复
  957. * @requires-type-info 需要提供类型信息
  958. */
  959. 'return-undefined': false,
  960. /**
  961. * @category style
  962. * @description 行尾必须有分号
  963. * @has-fixer 支持自动修复
  964. * @prettier 可交由 prettier 控制
  965. */
  966. semicolon: [true, 'always'],
  967. /**
  968. * @category style
  969. * @description 函数名前必须有空格
  970. * @has-fixer 支持自动修复
  971. * @prettier 可交由 prettier 控制
  972. */
  973. 'space-before-function-paren': [true, 'asyncArrow'],
  974. /**
  975. * @category style
  976. * @description 括号内首尾禁止有空格
  977. * @has-fixer 支持自动修复
  978. * @prettier 可交由 prettier 控制
  979. */
  980. 'space-within-parens': [true, 0],
  981. /**
  982. * @category style
  983. * @description switch 的最后一项禁止有 break
  984. * @reason 没必要限制
  985. * @has-fixer 支持自动修复
  986. */
  987. 'switch-final-break': false,
  988. /**
  989. * @category style
  990. * @description 字面类型的每个成员都必须有分号
  991. * @ts-only 仅支持 ts 文件
  992. */
  993. 'type-literal-delimiter': true,
  994. /**
  995. * @category style
  996. * @description 限制变量命名规则
  997. * @reason 没必要限制
  998. */
  999. 'variable-name': false,
  1000. /**
  1001. * @category style
  1002. * @description 限制空格的位置
  1003. * @has-fixer 支持自动修复
  1004. * @prettier 可交由 prettier 控制
  1005. */
  1006. whitespace: [
  1007. true,
  1008. 'check-branch',
  1009. 'check-decl',
  1010. 'check-operator',
  1011. 'check-module',
  1012. 'check-separator',
  1013. 'check-rest-spread',
  1014. 'check-type',
  1015. 'check-typecast',
  1016. 'check-type-operator',
  1017. 'check-preblock'
  1018. ]
  1019. }
  1020. };