index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. // Inspired by https://github.com/airbnb/javascript but less opinionated.
  9. // We use eslint-loader so even warnings are very visible.
  10. // This is why we prefer to use "WARNING" level for potential errors,
  11. // and we try not to use "ERROR" level at all.
  12. // In the future, we might create a separate list of rules for production.
  13. // It would probably be more strict.
  14. // The ESLint browser environment defines all browser globals as valid,
  15. // even though most people don't know some of them exist (e.g. `name` or `status`).
  16. // This is dangerous as it hides accidentally undefined variables.
  17. // We blacklist the globals that we deem potentially confusing.
  18. // To use them, explicitly reference them, e.g. `window.name` or `window.status`.
  19. const restrictedGlobals = require('confusing-browser-globals');
  20. module.exports = {
  21. extends: [require.resolve('./base')],
  22. plugins: ['import', 'flowtype', 'jsx-a11y', 'react-hooks'],
  23. overrides: [
  24. {
  25. files: ['**/*.ts?(x)'],
  26. parser: '@typescript-eslint/parser',
  27. parserOptions: {
  28. ecmaVersion: 2018,
  29. sourceType: 'module',
  30. ecmaFeatures: {
  31. jsx: true,
  32. },
  33. // typescript-eslint specific options
  34. warnOnUnsupportedTypeScriptVersion: true,
  35. },
  36. plugins: ['@typescript-eslint'],
  37. // If adding a typescript-eslint version of an existing ESLint rule,
  38. // make sure to disable the ESLint rule here.
  39. rules: {
  40. // TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906)
  41. 'default-case': 'off',
  42. // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
  43. 'no-dupe-class-members': 'off',
  44. // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477)
  45. 'no-undef': 'off',
  46. // Add TypeScript specific rules (and turn off ESLint equivalents)
  47. '@typescript-eslint/consistent-type-assertions': 'warn',
  48. 'no-array-constructor': 'off',
  49. '@typescript-eslint/no-array-constructor': 'warn',
  50. 'no-redeclare': 'off',
  51. '@typescript-eslint/no-redeclare': 'warn',
  52. 'no-use-before-define': 'off',
  53. '@typescript-eslint/no-use-before-define': [
  54. 'warn',
  55. {
  56. functions: false,
  57. classes: false,
  58. variables: false,
  59. typedefs: false,
  60. },
  61. ],
  62. 'no-unused-expressions': 'off',
  63. '@typescript-eslint/no-unused-expressions': [
  64. 'error',
  65. {
  66. allowShortCircuit: true,
  67. allowTernary: true,
  68. allowTaggedTemplates: true,
  69. },
  70. ],
  71. 'no-unused-vars': 'off',
  72. '@typescript-eslint/no-unused-vars': [
  73. 'warn',
  74. {
  75. args: 'none',
  76. ignoreRestSiblings: true,
  77. },
  78. ],
  79. 'no-useless-constructor': 'off',
  80. '@typescript-eslint/no-useless-constructor': 'warn',
  81. },
  82. },
  83. ],
  84. // NOTE: When adding rules here, you need to make sure they are compatible with
  85. // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible.
  86. rules: {
  87. // http://eslint.org/docs/rules/
  88. 'array-callback-return': 'warn',
  89. 'default-case': ['warn', { commentPattern: '^no default$' }],
  90. 'dot-location': ['warn', 'property'],
  91. eqeqeq: ['warn', 'smart'],
  92. 'new-parens': 'warn',
  93. 'no-array-constructor': 'warn',
  94. 'no-caller': 'warn',
  95. 'no-cond-assign': ['warn', 'except-parens'],
  96. 'no-const-assign': 'warn',
  97. 'no-control-regex': 'warn',
  98. 'no-delete-var': 'warn',
  99. 'no-dupe-args': 'warn',
  100. 'no-dupe-class-members': 'warn',
  101. 'no-dupe-keys': 'warn',
  102. 'no-duplicate-case': 'warn',
  103. 'no-empty-character-class': 'warn',
  104. 'no-empty-pattern': 'warn',
  105. 'no-eval': 'warn',
  106. 'no-ex-assign': 'warn',
  107. 'no-extend-native': 'warn',
  108. 'no-extra-bind': 'warn',
  109. 'no-extra-label': 'warn',
  110. 'no-fallthrough': 'warn',
  111. 'no-func-assign': 'warn',
  112. 'no-implied-eval': 'warn',
  113. 'no-invalid-regexp': 'warn',
  114. 'no-iterator': 'warn',
  115. 'no-label-var': 'warn',
  116. 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
  117. 'no-lone-blocks': 'warn',
  118. 'no-loop-func': 'warn',
  119. 'no-mixed-operators': [
  120. 'warn',
  121. {
  122. groups: [
  123. ['&', '|', '^', '~', '<<', '>>', '>>>'],
  124. ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
  125. ['&&', '||'],
  126. ['in', 'instanceof'],
  127. ],
  128. allowSamePrecedence: false,
  129. },
  130. ],
  131. 'no-multi-str': 'warn',
  132. 'no-native-reassign': 'warn',
  133. 'no-negated-in-lhs': 'warn',
  134. 'no-new-func': 'warn',
  135. 'no-new-object': 'warn',
  136. 'no-new-symbol': 'warn',
  137. 'no-new-wrappers': 'warn',
  138. 'no-obj-calls': 'warn',
  139. 'no-octal': 'warn',
  140. 'no-octal-escape': 'warn',
  141. 'no-redeclare': 'warn',
  142. 'no-regex-spaces': 'warn',
  143. 'no-restricted-syntax': ['warn', 'WithStatement'],
  144. 'no-script-url': 'warn',
  145. 'no-self-assign': 'warn',
  146. 'no-self-compare': 'warn',
  147. 'no-sequences': 'warn',
  148. 'no-shadow-restricted-names': 'warn',
  149. 'no-sparse-arrays': 'warn',
  150. 'no-template-curly-in-string': 'warn',
  151. 'no-this-before-super': 'warn',
  152. 'no-throw-literal': 'warn',
  153. 'no-undef': 'error',
  154. 'no-restricted-globals': ['error'].concat(restrictedGlobals),
  155. 'no-unreachable': 'warn',
  156. 'no-unused-expressions': [
  157. 'error',
  158. {
  159. allowShortCircuit: true,
  160. allowTernary: true,
  161. allowTaggedTemplates: true,
  162. },
  163. ],
  164. 'no-unused-labels': 'warn',
  165. 'no-unused-vars': [
  166. 'warn',
  167. {
  168. args: 'none',
  169. ignoreRestSiblings: true,
  170. },
  171. ],
  172. 'no-use-before-define': [
  173. 'warn',
  174. {
  175. functions: false,
  176. classes: false,
  177. variables: false,
  178. },
  179. ],
  180. 'no-useless-computed-key': 'warn',
  181. 'no-useless-concat': 'warn',
  182. 'no-useless-constructor': 'warn',
  183. 'no-useless-escape': 'warn',
  184. 'no-useless-rename': [
  185. 'warn',
  186. {
  187. ignoreDestructuring: false,
  188. ignoreImport: false,
  189. ignoreExport: false,
  190. },
  191. ],
  192. 'no-with': 'warn',
  193. 'no-whitespace-before-property': 'warn',
  194. 'react-hooks/exhaustive-deps': 'warn',
  195. 'require-yield': 'warn',
  196. 'rest-spread-spacing': ['warn', 'never'],
  197. strict: ['warn', 'never'],
  198. 'unicode-bom': ['warn', 'never'],
  199. 'use-isnan': 'warn',
  200. 'valid-typeof': 'warn',
  201. 'no-restricted-properties': [
  202. 'error',
  203. {
  204. object: 'require',
  205. property: 'ensure',
  206. message:
  207. 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting',
  208. },
  209. {
  210. object: 'System',
  211. property: 'import',
  212. message:
  213. 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting',
  214. },
  215. ],
  216. 'getter-return': 'warn',
  217. // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
  218. 'import/first': 'error',
  219. 'import/no-amd': 'error',
  220. 'import/no-anonymous-default-export': 'warn',
  221. 'import/no-webpack-loader-syntax': 'error',
  222. // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
  223. 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
  224. 'react/jsx-no-comment-textnodes': 'warn',
  225. 'react/jsx-no-duplicate-props': 'warn',
  226. 'react/jsx-no-target-blank': 'warn',
  227. 'react/jsx-no-undef': 'error',
  228. 'react/jsx-pascal-case': [
  229. 'warn',
  230. {
  231. allowAllCaps: true,
  232. ignore: [],
  233. },
  234. ],
  235. 'react/no-danger-with-children': 'warn',
  236. // Disabled because of undesirable warnings
  237. // See https://github.com/facebook/create-react-app/issues/5204 for
  238. // blockers until its re-enabled
  239. // 'react/no-deprecated': 'warn',
  240. 'react/no-direct-mutation-state': 'warn',
  241. 'react/no-is-mounted': 'warn',
  242. 'react/no-typos': 'error',
  243. 'react/require-render-return': 'error',
  244. 'react/style-prop-object': 'warn',
  245. // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
  246. 'jsx-a11y/alt-text': 'warn',
  247. 'jsx-a11y/anchor-has-content': 'warn',
  248. 'jsx-a11y/anchor-is-valid': [
  249. 'warn',
  250. {
  251. aspects: ['noHref', 'invalidHref'],
  252. },
  253. ],
  254. 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
  255. 'jsx-a11y/aria-props': 'warn',
  256. 'jsx-a11y/aria-proptypes': 'warn',
  257. 'jsx-a11y/aria-role': ['warn', { ignoreNonDOM: true }],
  258. 'jsx-a11y/aria-unsupported-elements': 'warn',
  259. 'jsx-a11y/heading-has-content': 'warn',
  260. 'jsx-a11y/iframe-has-title': 'warn',
  261. 'jsx-a11y/img-redundant-alt': 'warn',
  262. 'jsx-a11y/no-access-key': 'warn',
  263. 'jsx-a11y/no-distracting-elements': 'warn',
  264. 'jsx-a11y/no-redundant-roles': 'warn',
  265. 'jsx-a11y/role-has-required-aria-props': 'warn',
  266. 'jsx-a11y/role-supports-aria-props': 'warn',
  267. 'jsx-a11y/scope': 'warn',
  268. // https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks
  269. 'react-hooks/rules-of-hooks': 'error',
  270. // https://github.com/gajus/eslint-plugin-flowtype
  271. 'flowtype/define-flow-type': 'warn',
  272. 'flowtype/require-valid-file-annotation': 'warn',
  273. 'flowtype/use-flow-type': 'warn',
  274. },
  275. };