best-practices.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. 'use strict';
  2. module.exports = {
  3. rules: {
  4. /**
  5. * Doesn't enforces getter/setter pairs in objects
  6. * @see http://eslint.org/docs/rules/accessor-pairs
  7. */
  8. 'accessor-pairs': 'off',
  9. /**
  10. * Enforces return statements in callbacks of following array’s methods
  11. *
  12. * ```js
  13. * Array.from
  14. * Array.prototype.every
  15. * Array.prototype.filter
  16. * Array.prototype.find
  17. * Array.prototype.findIndex
  18. * Array.prototype.map
  19. * Array.prototype.reduce
  20. * Array.prototype.reduceRight
  21. * Array.prototype.some
  22. * Array.prototype.sort
  23. * ```
  24. * @see http://eslint.org/docs/rules/array-callback-return
  25. */
  26. 'array-callback-return': 'error',
  27. /**
  28. * Disallows the usage of variables outside of their binding context and
  29. * emulate traditional block scope from other languages.
  30. * @see http://eslint.org/docs/rules/block-scoped-var
  31. * @since 3.0.0
  32. */
  33. 'block-scoped-var': 'error',
  34. /**
  35. * Doesn't limit cyclomatic complexity
  36. * @see http://eslint.org/docs/rules/complexity
  37. */
  38. complexity: 'off',
  39. /**
  40. * Doesn't require `return` statements to either always or never specify values
  41. * @see http://eslint.org/docs/rules/consistent-return
  42. * @example
  43. *
  44. * ```js
  45. * // correct
  46. * function doSomething(condition) {
  47. * if (condition) {
  48. * return true;
  49. * }
  50. * }
  51. * ```
  52. */
  53. 'consistent-return': 'off',
  54. /**
  55. * Requires following curly brace conventions
  56. *
  57. * 1. You can relax the rule to allow brace-less single-line `if`,
  58. * `else if`, `else`, `for`, `while`, or `do`, while still enforcing the use
  59. * of curly braces for other instances.
  60. *
  61. * @see http://eslint.org/docs/rules/curly
  62. * @example
  63. *
  64. * ```js
  65. * // incorrect
  66. * if (foo)
  67. * doSomething();
  68. * else
  69. * doSomethingElse();
  70. *
  71. * // correct
  72. * if (foo) doSomething();
  73. *
  74. * if (foo) doSomething();
  75. * else doSomethingElse();
  76. *
  77. * do something();
  78. * while (foo);
  79. * ```
  80. */
  81. curly: [ 'error', 'multi-line' ],
  82. /**
  83. * Requires default case in switch statements.
  84. * You may optionally include a `// no default` after the last case
  85. * if there is no default case
  86. * @see http://eslint.org/docs/rules/default-case
  87. * @since 3.0.0
  88. * @example
  89. *
  90. * ```js
  91. * // correct
  92. * switch (foo) {
  93. * case 1:
  94. * doSomething();
  95. * break;
  96. *
  97. * case 2:
  98. * doSomething();
  99. * break;
  100. *
  101. * // no default
  102. * }
  103. * ```
  104. */
  105. 'default-case': [ 'error', { commentPattern: '^no default$' }],
  106. /**
  107. * Encouraging use of the dot notation style whenever possible
  108. * @see http://eslint.org/docs/rules/dot-notation
  109. * @since 3.0.0
  110. * @example
  111. *
  112. * ```js
  113. * // incorrect
  114. * const x = foo['bar'];
  115. *
  116. * // correct
  117. * const obj = foo.bar;
  118. * const y = foo[arg];
  119. *
  120. * // Specially, to avoid dot notation for reserved word properties,
  121. * // following pattern is accepted
  122. * const foo = bar['class'];
  123. * ```
  124. */
  125. 'dot-notation': [ 'error', { allowKeywords: true }],
  126. /**
  127. * Doesn't enforce newline before and after dot
  128. * @see http://eslint.org/docs/rules/dot-location
  129. * @example
  130. *
  131. * ```js
  132. * // correct
  133. * const a = foo.
  134. * bar;
  135. *
  136. * const b = foo
  137. * .bar;
  138. * ```
  139. */
  140. 'dot-location': 'off',
  141. /**
  142. * Enforces using the type-safe equality operators `===` and
  143. * `!==` instead of their regular counterparts `==` and `!=`.
  144. * Tt permits comparing to null to check for `null` or `undefined`
  145. * in a single expression
  146. * @see http://eslint.org/docs/rules/eqeqeq
  147. * @example
  148. *
  149. * ```js
  150. * // correct
  151. * a === b
  152. * foo === true
  153. * bananas !== 1
  154. * value === undefined
  155. * typeof foo === 'undefined'
  156. * 'hello' !== 'world'
  157. * 0 === 0
  158. * true === true
  159. * foo === null
  160. * foo == null
  161. *
  162. * // incorrect
  163. * a == b
  164. * foo == true
  165. * bananas != 1
  166. * value == undefined
  167. * typeof foo == 'undefined'
  168. * 'hello' != 'world'
  169. * 0 == 0
  170. * true == true
  171. * ```
  172. */
  173. eqeqeq: [ 'error', 'allow-null' ],
  174. /**
  175. * Doesn't require filtering the results in the loop for
  176. * preventing unexpected behavior
  177. * @see http://eslint.org/docs/rules/guard-for-in
  178. */
  179. 'guard-for-in': 'off',
  180. /**
  181. * Disallow use of alert
  182. * @see http://eslint.org/docs/rules/no-alert
  183. */
  184. 'no-alert': 'error',
  185. /**
  186. * Disallow use of caller/callee
  187. * @see http://eslint.org/docs/rules/no-caller
  188. */
  189. 'no-caller': 'error',
  190. /**
  191. * Disallow lexical declarations in case/default clauses
  192. * @see http://eslint.org/docs/rules/no-case-declarations
  193. * @example
  194. *
  195. * ```js
  196. * // incorrect
  197. * switch (foo) {
  198. * case 1:
  199. * let x = 1;
  200. * break;
  201. * case 2:
  202. * const y = 2;
  203. * break;
  204. * // no default
  205. *
  206. * // correct
  207. * switch (foo) {
  208. * case 1: {
  209. * let x = 1;
  210. * break;
  211. * }
  212. * case 2: {
  213. * const y = 2;
  214. * break;
  215. * }
  216. * // no default
  217. * ```
  218. */
  219. 'no-case-declarations': 'error',
  220. /**
  221. * Disallow regexs that look like division
  222. * @see http://eslint.org/docs/rules/no-div-regex
  223. */
  224. 'no-div-regex': 'off',
  225. /**
  226. * Disallow return before else
  227. * @see http://eslint.org/docs/rules/no-else-return
  228. * @since 3.0.0
  229. */
  230. 'no-else-return': 'error',
  231. /**
  232. * Disallow empty functions
  233. * @see http://eslint.org/docs/rules/no-empty-function
  234. * @example
  235. *
  236. * Specially, these following patterns are permitted
  237. *
  238. * #### `arrowFunctions`
  239. *
  240. * ```js
  241. * const foo = () => {};
  242. * ```
  243. *
  244. * #### `functions`
  245. *
  246. * ```js
  247. * function foo() {}
  248. *
  249. * const foo = function() {};
  250. *
  251. * const obj = {
  252. * foo: function() {}
  253. * };
  254. * ```
  255. *
  256. * #### `methods`
  257. *
  258. * ```js
  259. * const obj = {
  260. * foo() {}
  261. * };
  262. *
  263. * class A {
  264. * foo() {}
  265. * static foo() {}
  266. * }
  267. * ```
  268. *
  269. * Codes bellow are not permitted
  270. *
  271. * ```js
  272. * // generatorFunctions
  273. * function* foo() {}
  274. * const foo = function*() {};
  275. *
  276. * // generatorMethods
  277. * const obj = {
  278. * foo: function*() {},
  279. * *foo() {},
  280. * };
  281. *
  282. * // getters or setters
  283. * const obj = {
  284. * get foo() {},
  285. * set foo(value) {},
  286. * };
  287. *
  288. * // constructors
  289. * class A {
  290. * constructor() {}
  291. * }
  292. *
  293. * // mixed
  294. * const obj = {
  295. * bar: 123,
  296. * foo: () => this.bar,
  297. * *foo() {},
  298. * }
  299. * ```
  300. */
  301. 'no-empty-function': [ 'error', {
  302. allow: [
  303. 'arrowFunctions',
  304. 'functions',
  305. 'methods',
  306. ],
  307. }],
  308. /**
  309. * Disallow empty destructuring patterns
  310. * @see http://eslint.org/docs/rules/no-empty-pattern
  311. * @example
  312. *
  313. * ```js
  314. * // incorrect
  315. * const {} = foo;
  316. * const [] = foo;
  317. * const {a: {}} = foo;
  318. * const {a: []} = foo;
  319. * function foo({}) {}
  320. * function foo([]) {}
  321. * function foo({a: {}}) {}
  322. * function foo({a: []}) {}
  323. * ```
  324. */
  325. 'no-empty-pattern': 'error',
  326. /**
  327. * Allow `foo == null`
  328. * @see http://eslint.org/docs/rules/no-eq-null
  329. */
  330. 'no-eq-null': 'off',
  331. /**
  332. * Disallow usage of `eval`
  333. * @see http://eslint.org/docs/rules/no-eval
  334. */
  335. 'no-eval': 'error',
  336. /**
  337. * Disallows directly modifying the prototype of builtin objects
  338. * @see http://eslint.org/docs/rules/no-extend-native
  339. * @example
  340. *
  341. * ```js
  342. * // incorrect
  343. * Object.prototype.a = "a";
  344. * Object.defineProperty(Array.prototype, "times", { value: 999 });
  345. * ```
  346. */
  347. 'no-extend-native': 'error',
  348. /**
  349. * Disallow unnecessary function binding
  350. * @see http://eslint.org/docs/rules/no-extra-bind
  351. */
  352. 'no-extra-bind': 'error',
  353. /**
  354. * If a loop contains no nested loops or switches,
  355. * labeling the loop is unnecessary
  356. * @see http://eslint.org/docs/rules/no-extra-label
  357. */
  358. 'no-extra-label': 'error',
  359. /**
  360. * Disallow case statements fallthrough
  361. * @see http://eslint.org/docs/rules/no-fallthrough
  362. */
  363. 'no-fallthrough': 'error',
  364. /**
  365. * Disallow floating decimals
  366. * @see http://eslint.org/docs/rules/no-floating-decimal
  367. * @since 3.0.0
  368. */
  369. 'no-floating-decimal': 'error',
  370. /**
  371. * Allow the type conversion with shorter notations
  372. * @see http://eslint.org/docs/rules/no-implicit-coercion
  373. * @example
  374. *
  375. * ```js
  376. * // correct
  377. * const b = !!foo;
  378. * const b = ~foo.indexOf(".");
  379. * const n = +foo;
  380. * const n = 1 * foo;
  381. * const s = "" + foo;
  382. * foo += "";
  383. * ```
  384. */
  385. 'no-implicit-coercion': 'off',
  386. /**
  387. * Allow `var` and named functions in global scope
  388. * @see http://eslint.org/docs/rules/no-implicit-globals
  389. */
  390. 'no-implicit-globals': 'off',
  391. /**
  392. * Disallow implied `eval()`
  393. * @see http://eslint.org/docs/rules/no-implied-eval
  394. */
  395. 'no-implied-eval': 'error',
  396. /**
  397. * Allow this keywords outside of classes or class-like objects
  398. * @see http://eslint.org/docs/rules/no-invalid-this
  399. */
  400. 'no-invalid-this': 'off',
  401. /**
  402. * Allow iterator
  403. * @see http://eslint.org/docs/rules/no-iterator
  404. */
  405. 'no-iterator': 'off',
  406. /**
  407. * Disallow labeled statements
  408. * @see http://eslint.org/docs/rules/no-labels
  409. */
  410. 'no-labels': [ 'error', { allowLoop: false, allowSwitch: false }],
  411. /**
  412. * Disallow unnecessary nested blocks
  413. * @see http://eslint.org/docs/rules/no-lone-blocks
  414. */
  415. 'no-lone-blocks': 'error',
  416. /**
  417. * Disallow functions in loops
  418. * @see http://eslint.org/docs/rules/no-loop-func
  419. */
  420. 'no-loop-func': 'error',
  421. /**
  422. * @see http://eslint.org/docs/rules/no-magic-numbers
  423. * @since 3.0.0
  424. */
  425. 'no-magic-numbers': 'off',
  426. /**
  427. * Disallow multiple spaces
  428. * @see http://eslint.org/docs/rules/no-multi-spaces
  429. */
  430. 'no-multi-spaces': 'error',
  431. /**
  432. * Disallow multi-line strings
  433. * @see http://eslint.org/docs/rules/no-multi-str
  434. */
  435. 'no-multi-str': 'error',
  436. /**
  437. * Disallow reassignment of native objects
  438. * @see http://eslint.org/docs/rules/no-native-reassign
  439. */
  440. 'no-native-reassign': 'error',
  441. /**
  442. * Doesn't require storing the object created by `new` with
  443. * a constructor in a variable
  444. * @see http://eslint.org/docs/rules/no-new
  445. * @example
  446. *
  447. * ```js
  448. * // correct
  449. * new Thing();
  450. *
  451. * const thing = new Thing();
  452. *
  453. * Thing();
  454. * ```
  455. */
  456. 'no-new': 'off',
  457. /**
  458. * Disallow function constructor
  459. * @see http://eslint.org/docs/rules/no-new-func
  460. */
  461. 'no-new-func': 'error',
  462. /**
  463. * Disallow primitive wrapper instances
  464. * @see http://eslint.org/docs/rules/no-new-wrappers
  465. */
  466. 'no-new-wrappers': 'error',
  467. /**
  468. * Disallow octal literals
  469. * @see http://eslint.org/docs/rules/no-octal
  470. */
  471. 'no-octal': 'error',
  472. /**
  473. * Disallow octal escape sequences in string literals
  474. * @see http://eslint.org/docs/rules/no-octal-escape
  475. */
  476. 'no-octal-escape': 'error',
  477. /**
  478. * Allow reassignment of function parameters
  479. * @see http://eslint.org/docs/rules/no-param-reassign
  480. */
  481. 'no-param-reassign': 'off',
  482. /**
  483. * Disallow use of `__proto__`
  484. * @see http://eslint.org/docs/rules/no-proto
  485. */
  486. 'no-proto': 'error',
  487. /**
  488. * Disallow redeclaring variables
  489. * @see http://eslint.org/docs/rules/no-redeclare
  490. */
  491. 'no-redeclare': 'error',
  492. /**
  493. * Disallow assignment in return statement
  494. * @see http://eslint.org/docs/rules/no-return-assign
  495. * @since 3.0.0
  496. */
  497. 'no-return-assign': 'error',
  498. /**
  499. * Disallow script URLs
  500. * @see http://eslint.org/docs/rules/no-script-url
  501. */
  502. 'no-script-url': 'error',
  503. /**
  504. * Disallow self assignment
  505. * @see http://eslint.org/docs/rules/no-self-assign
  506. */
  507. 'no-self-assign': 'error',
  508. /**
  509. * Disallow self comparison
  510. * @see http://eslint.org/docs/rules/no-self-compare
  511. * @since 3.0.0
  512. */
  513. 'no-self-compare': 'error',
  514. /**
  515. * Disallow use of the comma operator
  516. * @see http://eslint.org/docs/rules/no-sequences
  517. */
  518. 'no-sequences': 'error',
  519. /**
  520. * Doesn't restrict what can be thrown as an exception
  521. * @see http://eslint.org/docs/rules/no-throw-literal
  522. */
  523. 'no-throw-literal': 'off',
  524. /**
  525. * disallow unmodified conditions of loops
  526. * @see http://eslint.org/docs/rules/no-unmodified-loop-condition
  527. */
  528. 'no-unmodified-loop-condition': 'off',
  529. /**
  530. * Disallow unused expressions
  531. * @see http://eslint.org/docs/rules/no-unused-expressions
  532. * @since 3.0.0
  533. */
  534. 'no-unused-expressions': 'off',
  535. /**
  536. * disallow unused labels
  537. * @see http://eslint.org/docs/rules/no-unused-labels
  538. */
  539. 'no-unused-labels': 'error',
  540. /**
  541. * Allow unnecessary `.call()` and `.apply()`
  542. * @see http://eslint.org/docs/rules/no-useless-call
  543. */
  544. 'no-useless-call': 'off',
  545. /**
  546. * Disallow unnecessary concatenation of strings
  547. * @see http://eslint.org/docs/rules/no-useless-concat
  548. */
  549. 'no-useless-concat': 'error',
  550. /**
  551. * Disallow unnecessary string escaping
  552. * @see http://eslint.org/docs/rules/no-useless-escape
  553. */
  554. 'no-useless-escape': 'error',
  555. /**
  556. * Allow use of the void operator
  557. * @see http://eslint.org/docs/rules/no-void
  558. */
  559. 'no-void': 'off',
  560. /**
  561. * Allow warning comments
  562. * @see http://eslint.org/docs/rules/no-warning-comments
  563. */
  564. 'no-warning-comments': 'off',
  565. /**
  566. * disallow use of the `with` statement
  567. * @see http://eslint.org/docs/rules/no-with
  568. */
  569. 'no-with': 'error',
  570. /**
  571. * Doesn't require Radix Parameter
  572. * @see http://eslint.org/docs/rules/radix
  573. */
  574. radix: 'off',
  575. /**
  576. * Doesn't require variable declarations to be at the top of their scope
  577. * @see http://eslint.org/docs/rules/vars-on-top
  578. */
  579. 'vars-on-top': 'off',
  580. /**
  581. * Require IIFEs to be wrapped
  582. * @see http://eslint.org/docs/rules/wrap-iife
  583. */
  584. 'wrap-iife': 'off',
  585. /**
  586. * Disallow Yoda conditions
  587. * @see http://eslint.org/docs/rules/yoda
  588. */
  589. yoda: 'error',
  590. },
  591. };