best-practices.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. module.exports = {
  2. rules: {
  3. // enforces getter/setter pairs in objects
  4. // https://eslint.org/docs/rules/accessor-pairs
  5. 'accessor-pairs': 'off',
  6. // enforces return statements in callbacks of array's methods
  7. // https://eslint.org/docs/rules/array-callback-return
  8. 'array-callback-return': ['error', { allowImplicit: true }],
  9. // treat var statements as if they were block scoped
  10. // https://eslint.org/docs/rules/block-scoped-var
  11. 'block-scoped-var': 'error',
  12. // specify the maximum cyclomatic complexity allowed in a program
  13. // https://eslint.org/docs/rules/complexity
  14. complexity: ['off', 20],
  15. // enforce that class methods use "this"
  16. // https://eslint.org/docs/rules/class-methods-use-this
  17. 'class-methods-use-this': ['error', {
  18. exceptMethods: [],
  19. }],
  20. // require return statements to either always or never specify values
  21. // https://eslint.org/docs/rules/consistent-return
  22. 'consistent-return': 'error',
  23. // specify curly brace conventions for all control statements
  24. // https://eslint.org/docs/rules/curly
  25. curly: ['error', 'multi-line'], // multiline
  26. // require default case in switch statements
  27. // https://eslint.org/docs/rules/default-case
  28. 'default-case': ['error', { commentPattern: '^no default$' }],
  29. // Enforce default clauses in switch statements to be last
  30. // https://eslint.org/docs/rules/default-case-last
  31. 'default-case-last': 'error',
  32. // https://eslint.org/docs/rules/default-param-last
  33. 'default-param-last': 'error',
  34. // encourages use of dot notation whenever possible
  35. // https://eslint.org/docs/rules/dot-notation
  36. 'dot-notation': ['error', { allowKeywords: true }],
  37. // enforces consistent newlines before or after dots
  38. // https://eslint.org/docs/rules/dot-location
  39. 'dot-location': ['error', 'property'],
  40. // require the use of === and !==
  41. // https://eslint.org/docs/rules/eqeqeq
  42. eqeqeq: ['error', 'always', { null: 'ignore' }],
  43. // Require grouped accessor pairs in object literals and classes
  44. // https://eslint.org/docs/rules/grouped-accessor-pairs
  45. 'grouped-accessor-pairs': 'error',
  46. // make sure for-in loops have an if statement
  47. // https://eslint.org/docs/rules/guard-for-in
  48. 'guard-for-in': 'error',
  49. // enforce a maximum number of classes per file
  50. // https://eslint.org/docs/rules/max-classes-per-file
  51. 'max-classes-per-file': ['error', 1],
  52. // disallow the use of alert, confirm, and prompt
  53. // https://eslint.org/docs/rules/no-alert
  54. 'no-alert': 'warn',
  55. // disallow use of arguments.caller or arguments.callee
  56. // https://eslint.org/docs/rules/no-caller
  57. 'no-caller': 'error',
  58. // disallow lexical declarations in case/default clauses
  59. // https://eslint.org/docs/rules/no-case-declarations
  60. 'no-case-declarations': 'error',
  61. // Disallow returning value in constructor
  62. // https://eslint.org/docs/rules/no-constructor-return
  63. 'no-constructor-return': 'error',
  64. // disallow division operators explicitly at beginning of regular expression
  65. // https://eslint.org/docs/rules/no-div-regex
  66. 'no-div-regex': 'off',
  67. // disallow else after a return in an if
  68. // https://eslint.org/docs/rules/no-else-return
  69. 'no-else-return': ['error', { allowElseIf: false }],
  70. // disallow empty functions, except for standalone funcs/arrows
  71. // https://eslint.org/docs/rules/no-empty-function
  72. 'no-empty-function': ['error', {
  73. allow: [
  74. 'arrowFunctions',
  75. 'functions',
  76. 'methods',
  77. ]
  78. }],
  79. // disallow empty destructuring patterns
  80. // https://eslint.org/docs/rules/no-empty-pattern
  81. 'no-empty-pattern': 'error',
  82. // disallow comparisons to null without a type-checking operator
  83. // https://eslint.org/docs/rules/no-eq-null
  84. 'no-eq-null': 'off',
  85. // disallow use of eval()
  86. // https://eslint.org/docs/rules/no-eval
  87. 'no-eval': 'error',
  88. // disallow adding to native types
  89. // https://eslint.org/docs/rules/no-extend-native
  90. 'no-extend-native': 'error',
  91. // disallow unnecessary function binding
  92. // https://eslint.org/docs/rules/no-extra-bind
  93. 'no-extra-bind': 'error',
  94. // disallow Unnecessary Labels
  95. // https://eslint.org/docs/rules/no-extra-label
  96. 'no-extra-label': 'error',
  97. // disallow fallthrough of case statements
  98. // https://eslint.org/docs/rules/no-fallthrough
  99. 'no-fallthrough': 'error',
  100. // disallow the use of leading or trailing decimal points in numeric literals
  101. // https://eslint.org/docs/rules/no-floating-decimal
  102. 'no-floating-decimal': 'error',
  103. // disallow reassignments of native objects or read-only globals
  104. // https://eslint.org/docs/rules/no-global-assign
  105. 'no-global-assign': ['error', { exceptions: [] }],
  106. // deprecated in favor of no-global-assign
  107. // https://eslint.org/docs/rules/no-native-reassign
  108. 'no-native-reassign': 'off',
  109. // disallow implicit type conversions
  110. // https://eslint.org/docs/rules/no-implicit-coercion
  111. 'no-implicit-coercion': ['off', {
  112. boolean: false,
  113. number: true,
  114. string: true,
  115. allow: [],
  116. }],
  117. // disallow var and named functions in global scope
  118. // https://eslint.org/docs/rules/no-implicit-globals
  119. 'no-implicit-globals': 'off',
  120. // disallow use of eval()-like methods
  121. // https://eslint.org/docs/rules/no-implied-eval
  122. 'no-implied-eval': 'error',
  123. // disallow this keywords outside of classes or class-like objects
  124. // https://eslint.org/docs/rules/no-invalid-this
  125. 'no-invalid-this': 'off',
  126. // disallow usage of __iterator__ property
  127. // https://eslint.org/docs/rules/no-iterator
  128. 'no-iterator': 'error',
  129. // disallow use of labels for anything other than loops and switches
  130. // https://eslint.org/docs/rules/no-labels
  131. 'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
  132. // disallow unnecessary nested blocks
  133. // https://eslint.org/docs/rules/no-lone-blocks
  134. 'no-lone-blocks': 'error',
  135. // disallow creation of functions within loops
  136. // https://eslint.org/docs/rules/no-loop-func
  137. 'no-loop-func': 'error',
  138. // disallow magic numbers
  139. // https://eslint.org/docs/rules/no-magic-numbers
  140. 'no-magic-numbers': ['off', {
  141. ignore: [],
  142. ignoreArrayIndexes: true,
  143. enforceConst: true,
  144. detectObjects: false,
  145. }],
  146. // disallow use of multiple spaces
  147. // https://eslint.org/docs/rules/no-multi-spaces
  148. 'no-multi-spaces': ['error', {
  149. ignoreEOLComments: false,
  150. }],
  151. // disallow use of multiline strings
  152. // https://eslint.org/docs/rules/no-multi-str
  153. 'no-multi-str': 'error',
  154. // disallow use of new operator when not part of the assignment or comparison
  155. // https://eslint.org/docs/rules/no-new
  156. 'no-new': 'error',
  157. // disallow use of new operator for Function object
  158. // https://eslint.org/docs/rules/no-new-func
  159. 'no-new-func': 'error',
  160. // disallows creating new instances of String, Number, and Boolean
  161. // https://eslint.org/docs/rules/no-new-wrappers
  162. 'no-new-wrappers': 'error',
  163. // Disallow \8 and \9 escape sequences in string literals
  164. // https://eslint.org/docs/rules/no-nonoctal-decimal-escape
  165. 'no-nonoctal-decimal-escape': 'error',
  166. // disallow use of (old style) octal literals
  167. // https://eslint.org/docs/rules/no-octal
  168. 'no-octal': 'error',
  169. // disallow use of octal escape sequences in string literals, such as
  170. // var foo = 'Copyright \251';
  171. // https://eslint.org/docs/rules/no-octal-escape
  172. 'no-octal-escape': 'error',
  173. // disallow reassignment of function parameters
  174. // disallow parameter object manipulation except for specific exclusions
  175. // rule: https://eslint.org/docs/rules/no-param-reassign.html
  176. 'no-param-reassign': ['error', {
  177. props: true,
  178. ignorePropertyModificationsFor: [
  179. 'acc', // for reduce accumulators
  180. 'accumulator', // for reduce accumulators
  181. 'e', // for e.returnvalue
  182. 'ctx', // for Koa routing
  183. 'context', // for Koa routing
  184. 'req', // for Express requests
  185. 'request', // for Express requests
  186. 'res', // for Express responses
  187. 'response', // for Express responses
  188. '$scope', // for Angular 1 scopes
  189. 'staticContext', // for ReactRouter context
  190. ]
  191. }],
  192. // disallow usage of __proto__ property
  193. // https://eslint.org/docs/rules/no-proto
  194. 'no-proto': 'error',
  195. // disallow declaring the same variable more than once
  196. // https://eslint.org/docs/rules/no-redeclare
  197. 'no-redeclare': 'error',
  198. // disallow certain object properties
  199. // https://eslint.org/docs/rules/no-restricted-properties
  200. 'no-restricted-properties': ['error', {
  201. object: 'arguments',
  202. property: 'callee',
  203. message: 'arguments.callee is deprecated',
  204. }, {
  205. object: 'global',
  206. property: 'isFinite',
  207. message: 'Please use Number.isFinite instead',
  208. }, {
  209. object: 'self',
  210. property: 'isFinite',
  211. message: 'Please use Number.isFinite instead',
  212. }, {
  213. object: 'window',
  214. property: 'isFinite',
  215. message: 'Please use Number.isFinite instead',
  216. }, {
  217. object: 'global',
  218. property: 'isNaN',
  219. message: 'Please use Number.isNaN instead',
  220. }, {
  221. object: 'self',
  222. property: 'isNaN',
  223. message: 'Please use Number.isNaN instead',
  224. }, {
  225. object: 'window',
  226. property: 'isNaN',
  227. message: 'Please use Number.isNaN instead',
  228. }, {
  229. property: '__defineGetter__',
  230. message: 'Please use Object.defineProperty instead.',
  231. }, {
  232. property: '__defineSetter__',
  233. message: 'Please use Object.defineProperty instead.',
  234. }, {
  235. object: 'Math',
  236. property: 'pow',
  237. message: 'Use the exponentiation operator (**) instead.',
  238. }],
  239. // disallow use of assignment in return statement
  240. // https://eslint.org/docs/rules/no-return-assign
  241. 'no-return-assign': ['error', 'always'],
  242. // disallow redundant `return await`
  243. // https://eslint.org/docs/rules/no-return-await
  244. 'no-return-await': 'error',
  245. // disallow use of `javascript:` urls.
  246. // https://eslint.org/docs/rules/no-script-url
  247. 'no-script-url': 'error',
  248. // disallow self assignment
  249. // https://eslint.org/docs/rules/no-self-assign
  250. 'no-self-assign': ['error', {
  251. props: true,
  252. }],
  253. // disallow comparisons where both sides are exactly the same
  254. // https://eslint.org/docs/rules/no-self-compare
  255. 'no-self-compare': 'error',
  256. // disallow use of comma operator
  257. // https://eslint.org/docs/rules/no-sequences
  258. 'no-sequences': 'error',
  259. // restrict what can be thrown as an exception
  260. // https://eslint.org/docs/rules/no-throw-literal
  261. 'no-throw-literal': 'error',
  262. // disallow unmodified conditions of loops
  263. // https://eslint.org/docs/rules/no-unmodified-loop-condition
  264. 'no-unmodified-loop-condition': 'off',
  265. // disallow usage of expressions in statement position
  266. // https://eslint.org/docs/rules/no-unused-expressions
  267. 'no-unused-expressions': ['error', {
  268. allowShortCircuit: false,
  269. allowTernary: false,
  270. allowTaggedTemplates: false,
  271. }],
  272. // disallow unused labels
  273. // https://eslint.org/docs/rules/no-unused-labels
  274. 'no-unused-labels': 'error',
  275. // disallow unnecessary .call() and .apply()
  276. // https://eslint.org/docs/rules/no-useless-call
  277. 'no-useless-call': 'off',
  278. // Disallow unnecessary catch clauses
  279. // https://eslint.org/docs/rules/no-useless-catch
  280. 'no-useless-catch': 'error',
  281. // disallow useless string concatenation
  282. // https://eslint.org/docs/rules/no-useless-concat
  283. 'no-useless-concat': 'error',
  284. // disallow unnecessary string escaping
  285. // https://eslint.org/docs/rules/no-useless-escape
  286. 'no-useless-escape': 'error',
  287. // disallow redundant return; keywords
  288. // https://eslint.org/docs/rules/no-useless-return
  289. 'no-useless-return': 'error',
  290. // disallow use of void operator
  291. // https://eslint.org/docs/rules/no-void
  292. 'no-void': 'error',
  293. // disallow usage of configurable warning terms in comments: e.g. todo
  294. // https://eslint.org/docs/rules/no-warning-comments
  295. 'no-warning-comments': ['off', { terms: ['todo', 'fixme', 'xxx'], location: 'start' }],
  296. // disallow use of the with statement
  297. // https://eslint.org/docs/rules/no-with
  298. 'no-with': 'error',
  299. // require using Error objects as Promise rejection reasons
  300. // https://eslint.org/docs/rules/prefer-promise-reject-errors
  301. 'prefer-promise-reject-errors': ['error', { allowEmptyReject: true }],
  302. // Suggest using named capture group in regular expression
  303. // https://eslint.org/docs/rules/prefer-named-capture-group
  304. 'prefer-named-capture-group': 'off',
  305. // https://eslint.org/docs/rules/prefer-regex-literals
  306. 'prefer-regex-literals': ['error', {
  307. disallowRedundantWrapping: true,
  308. }],
  309. // require use of the second argument for parseInt()
  310. // https://eslint.org/docs/rules/radix
  311. radix: 'error',
  312. // require `await` in `async function` (note: this is a horrible rule that should never be used)
  313. // https://eslint.org/docs/rules/require-await
  314. 'require-await': 'off',
  315. // Enforce the use of u flag on RegExp
  316. // https://eslint.org/docs/rules/require-unicode-regexp
  317. 'require-unicode-regexp': 'off',
  318. // requires to declare all vars on top of their containing scope
  319. // https://eslint.org/docs/rules/vars-on-top
  320. 'vars-on-top': 'error',
  321. // require immediate function invocation to be wrapped in parentheses
  322. // https://eslint.org/docs/rules/wrap-iife.html
  323. 'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }],
  324. // require or disallow Yoda conditions
  325. // https://eslint.org/docs/rules/yoda
  326. yoda: 'error'
  327. }
  328. };