react.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. const assign = require('object.assign');
  2. const baseStyleRules = require('eslint-config-airbnb-base/rules/style').rules;
  3. const dangleRules = baseStyleRules['no-underscore-dangle'];
  4. module.exports = {
  5. plugins: [
  6. 'react',
  7. ],
  8. parserOptions: {
  9. ecmaFeatures: {
  10. jsx: true,
  11. },
  12. },
  13. // View link below for react rules documentation
  14. // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
  15. rules: {
  16. 'no-underscore-dangle': [dangleRules[0], assign({}, dangleRules[1], {
  17. allow: dangleRules[1].allow.concat(['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']),
  18. })],
  19. // Specify whether double or single quotes should be used in JSX attributes
  20. // https://eslint.org/docs/rules/jsx-quotes
  21. 'jsx-quotes': ['error', 'prefer-double'],
  22. 'class-methods-use-this': ['error', {
  23. exceptMethods: [
  24. 'render',
  25. 'getInitialState',
  26. 'getDefaultProps',
  27. 'getChildContext',
  28. 'componentWillMount',
  29. 'UNSAFE_componentWillMount',
  30. 'componentDidMount',
  31. 'componentWillReceiveProps',
  32. 'UNSAFE_componentWillReceiveProps',
  33. 'shouldComponentUpdate',
  34. 'componentWillUpdate',
  35. 'UNSAFE_componentWillUpdate',
  36. 'componentDidUpdate',
  37. 'componentWillUnmount',
  38. 'componentDidCatch',
  39. 'getSnapshotBeforeUpdate'
  40. ],
  41. }],
  42. // Prevent missing displayName in a React component definition
  43. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
  44. 'react/display-name': ['off', { ignoreTranspilerName: false }],
  45. // Forbid certain propTypes (any, array, object)
  46. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-prop-types.md
  47. 'react/forbid-prop-types': ['error', {
  48. forbid: ['any', 'array', 'object'],
  49. checkContextTypes: true,
  50. checkChildContextTypes: true,
  51. }],
  52. // Forbid certain props on DOM Nodes
  53. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-dom-props.md
  54. 'react/forbid-dom-props': ['off', { forbid: [] }],
  55. // Enforce boolean attributes notation in JSX
  56. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
  57. 'react/jsx-boolean-value': ['error', 'never', { always: [] }],
  58. // Validate closing bracket location in JSX
  59. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
  60. 'react/jsx-closing-bracket-location': ['error', 'line-aligned'],
  61. // Validate closing tag location in JSX
  62. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md
  63. 'react/jsx-closing-tag-location': 'error',
  64. // Enforce or disallow spaces inside of curly braces in JSX attributes
  65. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
  66. 'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
  67. // Enforce event handler naming conventions in JSX
  68. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
  69. 'react/jsx-handler-names': ['off', {
  70. eventHandlerPrefix: 'handle',
  71. eventHandlerPropPrefix: 'on',
  72. }],
  73. // Validate props indentation in JSX
  74. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
  75. 'react/jsx-indent-props': ['error', 2],
  76. // Validate JSX has key prop when in array or iterator
  77. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
  78. // Turned off because it has too many false positives
  79. 'react/jsx-key': 'off',
  80. // Limit maximum of props on a single line in JSX
  81. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
  82. 'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }],
  83. // Prevent usage of .bind() in JSX props
  84. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
  85. 'react/jsx-no-bind': ['error', {
  86. ignoreRefs: true,
  87. allowArrowFunctions: true,
  88. allowFunctions: false,
  89. allowBind: false,
  90. ignoreDOMComponents: true,
  91. }],
  92. // Prevent duplicate props in JSX
  93. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
  94. 'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }],
  95. // Prevent usage of unwrapped JSX strings
  96. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
  97. 'react/jsx-no-literals': ['off', { noStrings: true }],
  98. // Disallow undeclared variables in JSX
  99. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
  100. 'react/jsx-no-undef': 'error',
  101. // Enforce PascalCase for user-defined JSX components
  102. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
  103. 'react/jsx-pascal-case': ['error', {
  104. allowAllCaps: true,
  105. ignore: [],
  106. }],
  107. // Enforce propTypes declarations alphabetical sorting
  108. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
  109. 'react/sort-prop-types': ['off', {
  110. ignoreCase: true,
  111. callbacksLast: false,
  112. requiredFirst: false,
  113. sortShapeProp: true,
  114. }],
  115. // Deprecated in favor of react/jsx-sort-props
  116. 'react/jsx-sort-prop-types': 'off',
  117. // Enforce props alphabetical sorting
  118. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
  119. 'react/jsx-sort-props': ['off', {
  120. ignoreCase: true,
  121. callbacksLast: false,
  122. shorthandFirst: false,
  123. shorthandLast: false,
  124. noSortAlphabetically: false,
  125. reservedFirst: true,
  126. }],
  127. // Enforce defaultProps declarations alphabetical sorting
  128. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-sort-default-props.md
  129. 'react/jsx-sort-default-props': ['off', {
  130. ignoreCase: true,
  131. }],
  132. // Prevent React to be incorrectly marked as unused
  133. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
  134. 'react/jsx-uses-react': ['error'],
  135. // Prevent variables used in JSX to be incorrectly marked as unused
  136. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
  137. 'react/jsx-uses-vars': 'error',
  138. // Prevent usage of dangerous JSX properties
  139. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
  140. 'react/no-danger': 'warn',
  141. // Prevent usage of deprecated methods
  142. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
  143. 'react/no-deprecated': ['error'],
  144. // Prevent usage of setState in componentDidMount
  145. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
  146. // this is necessary for server-rendering
  147. 'react/no-did-mount-set-state': 'off',
  148. // Prevent usage of setState in componentDidUpdate
  149. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
  150. 'react/no-did-update-set-state': 'error',
  151. // Prevent usage of setState in componentWillUpdate
  152. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-will-update-set-state.md
  153. 'react/no-will-update-set-state': 'error',
  154. // Prevent direct mutation of this.state
  155. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
  156. 'react/no-direct-mutation-state': 'off',
  157. // Prevent usage of isMounted
  158. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
  159. 'react/no-is-mounted': 'error',
  160. // Prevent multiple component definition per file
  161. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
  162. 'react/no-multi-comp': 'off',
  163. // Prevent usage of setState
  164. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
  165. 'react/no-set-state': 'off',
  166. // Prevent using string references
  167. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
  168. 'react/no-string-refs': 'error',
  169. // Prevent usage of unknown DOM property
  170. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
  171. 'react/no-unknown-property': 'error',
  172. // Require ES6 class declarations over React.createClass
  173. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
  174. 'react/prefer-es6-class': ['error', 'always'],
  175. // Require stateless functions when not using lifecycle methods, setState or ref
  176. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
  177. 'react/prefer-stateless-function': ['error', { ignorePureComponents: true }],
  178. // Prevent missing props validation in a React component definition
  179. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
  180. 'react/prop-types': ['error', {
  181. ignore: [],
  182. customValidators: [],
  183. skipUndeclared: false
  184. }],
  185. // Prevent missing React when using JSX
  186. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
  187. 'react/react-in-jsx-scope': 'error',
  188. // Require render() methods to return something
  189. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
  190. 'react/require-render-return': 'error',
  191. // Prevent extra closing tags for components without children
  192. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
  193. 'react/self-closing-comp': 'error',
  194. // Enforce component methods order
  195. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/sort-comp.md
  196. 'react/sort-comp': ['error', {
  197. order: [
  198. 'static-variables',
  199. 'static-methods',
  200. 'instance-variables',
  201. 'lifecycle',
  202. '/^handle.+$/',
  203. '/^on.+$/',
  204. 'getters',
  205. 'setters',
  206. '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
  207. 'instance-methods',
  208. 'everything-else',
  209. 'rendering',
  210. ],
  211. groups: {
  212. lifecycle: [
  213. 'displayName',
  214. 'propTypes',
  215. 'contextTypes',
  216. 'childContextTypes',
  217. 'mixins',
  218. 'statics',
  219. 'defaultProps',
  220. 'constructor',
  221. 'getDefaultProps',
  222. 'getInitialState',
  223. 'state',
  224. 'getChildContext',
  225. 'getDerivedStateFromProps',
  226. 'componentWillMount',
  227. 'UNSAFE_componentWillMount',
  228. 'componentDidMount',
  229. 'componentWillReceiveProps',
  230. 'UNSAFE_componentWillReceiveProps',
  231. 'shouldComponentUpdate',
  232. 'componentWillUpdate',
  233. 'UNSAFE_componentWillUpdate',
  234. 'getSnapshotBeforeUpdate',
  235. 'componentDidUpdate',
  236. 'componentDidCatch',
  237. 'componentWillUnmount'
  238. ],
  239. rendering: [
  240. '/^render.+$/',
  241. 'render'
  242. ],
  243. },
  244. }],
  245. // Prevent missing parentheses around multilines JSX
  246. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-wrap-multilines.md
  247. 'react/jsx-wrap-multilines': ['error', {
  248. declaration: 'parens-new-line',
  249. assignment: 'parens-new-line',
  250. return: 'parens-new-line',
  251. arrow: 'parens-new-line',
  252. condition: 'parens-new-line',
  253. logical: 'parens-new-line',
  254. prop: 'parens-new-line',
  255. }],
  256. // Require that the first prop in a JSX element be on a new line when the element is multiline
  257. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
  258. 'react/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
  259. // Enforce spacing around jsx equals signs
  260. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
  261. 'react/jsx-equals-spacing': ['error', 'never'],
  262. // Enforce JSX indentation
  263. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
  264. 'react/jsx-indent': ['error', 2],
  265. // Disallow target="_blank" on links
  266. // https://github.com/yannickcr/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-no-target-blank.md
  267. 'react/jsx-no-target-blank': ['error', { enforceDynamicLinks: 'always' }],
  268. // only .jsx files may have JSX
  269. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
  270. 'react/jsx-filename-extension': ['error', { extensions: ['.jsx'] }],
  271. // prevent accidental JS comments from being injected into JSX as text
  272. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
  273. 'react/jsx-no-comment-textnodes': 'error',
  274. // disallow using React.render/ReactDOM.render's return value
  275. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
  276. 'react/no-render-return-value': 'error',
  277. // require a shouldComponentUpdate method, or PureRenderMixin
  278. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-optimization.md
  279. 'react/require-optimization': ['off', { allowDecorators: [] }],
  280. // warn against using findDOMNode()
  281. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md
  282. 'react/no-find-dom-node': 'error',
  283. // Forbid certain props on Components
  284. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md
  285. 'react/forbid-component-props': ['off', { forbid: [] }],
  286. // Forbid certain elements
  287. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-elements.md
  288. 'react/forbid-elements': ['off', { forbid: [], }],
  289. // Prevent problem with children and props.dangerouslySetInnerHTML
  290. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
  291. 'react/no-danger-with-children': 'error',
  292. // Prevent unused propType definitions
  293. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
  294. 'react/no-unused-prop-types': ['error', {
  295. customValidators: [
  296. ],
  297. skipShapeProps: true,
  298. }],
  299. // Require style prop value be an object or var
  300. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md
  301. 'react/style-prop-object': 'error',
  302. // Prevent invalid characters from appearing in markup
  303. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
  304. 'react/no-unescaped-entities': 'error',
  305. // Prevent passing of children as props
  306. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
  307. 'react/no-children-prop': 'error',
  308. // Validate whitespace in and around the JSX opening and closing brackets
  309. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-tag-spacing.md
  310. 'react/jsx-tag-spacing': ['error', {
  311. closingSlash: 'never',
  312. beforeSelfClosing: 'always',
  313. afterOpening: 'never',
  314. beforeClosing: 'never',
  315. }],
  316. // Enforce spaces before the closing bracket of self-closing JSX elements
  317. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
  318. // Deprecated in favor of jsx-tag-spacing
  319. 'react/jsx-space-before-closing': ['off', 'always'],
  320. // Prevent usage of Array index in keys
  321. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
  322. 'react/no-array-index-key': 'error',
  323. // Enforce a defaultProps definition for every prop that is not a required prop
  324. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/require-default-props.md
  325. 'react/require-default-props': ['error', {
  326. forbidDefaultForRequired: true,
  327. }],
  328. // Forbids using non-exported propTypes
  329. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md
  330. // this is intentionally set to "warn". it would be "error",
  331. // but it's only critical if you're stripping propTypes in production.
  332. 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
  333. // Prevent void DOM elements from receiving children
  334. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md
  335. 'react/void-dom-elements-no-children': 'error',
  336. // Enforce all defaultProps have a corresponding non-required PropType
  337. // https://github.com/yannickcr/eslint-plugin-react/blob/9e13ae2c51e44872b45cc15bf1ac3a72105bdd0e/docs/rules/default-props-match-prop-types.md
  338. 'react/default-props-match-prop-types': ['error', { allowRequiredDefaults: false }],
  339. // Prevent usage of shouldComponentUpdate when extending React.PureComponent
  340. // https://github.com/yannickcr/eslint-plugin-react/blob/9e13ae2c51e44872b45cc15bf1ac3a72105bdd0e/docs/rules/no-redundant-should-component-update.md
  341. 'react/no-redundant-should-component-update': 'error',
  342. // Prevent unused state values
  343. // https://github.com/yannickcr/eslint-plugin-react/pull/1103/
  344. 'react/no-unused-state': 'error',
  345. // Enforces consistent naming for boolean props
  346. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/boolean-prop-naming.md
  347. 'react/boolean-prop-naming': ['off', {
  348. propTypeNames: ['bool', 'mutuallyExclusiveTrueProps'],
  349. rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
  350. message: '',
  351. }],
  352. // Prevents common casing typos
  353. // https://github.com/yannickcr/eslint-plugin-react/blob/73abadb697034b5ccb514d79fb4689836fe61f91/docs/rules/no-typos.md
  354. 'react/no-typos': 'error',
  355. // Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children
  356. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
  357. 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
  358. // One JSX Element Per Line
  359. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-one-expression-per-line.md
  360. 'react/jsx-one-expression-per-line': ['error', { allow: 'single-child' }],
  361. // Enforce consistent usage of destructuring assignment of props, state, and context
  362. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/destructuring-assignment.md
  363. 'react/destructuring-assignment': ['error', 'always'],
  364. // Prevent using this.state within a this.setState
  365. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-access-state-in-setstate.md
  366. 'react/no-access-state-in-setstate': 'error',
  367. // Prevent usage of button elements without an explicit type attribute
  368. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/button-has-type.md
  369. 'react/button-has-type': ['error', {
  370. button: true,
  371. submit: true,
  372. reset: false,
  373. }],
  374. // Ensures inline tags are not rendered without spaces between them
  375. 'react/jsx-child-element-spacing': 'off',
  376. // Prevent this from being used in stateless functional components
  377. // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-this-in-sfc.md
  378. 'react/no-this-in-sfc': 'error',
  379. // Validate JSX maximum depth
  380. // https://github.com/yannickcr/eslint-plugin-react/blob/abe8381c0d6748047224c430ce47f02e40160ed0/docs/rules/jsx-max-depth.md
  381. 'react/jsx-max-depth': 'off',
  382. // Disallow multiple spaces between inline JSX props
  383. // https://github.com/yannickcr/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-props-no-multi-spaces.md
  384. 'react/jsx-props-no-multi-spaces': 'error',
  385. // Prevent usage of UNSAFE_ methods
  386. // https://github.com/yannickcr/eslint-plugin-react/blob/157cc932be2cfaa56b3f5b45df6f6d4322a2f660/docs/rules/no-unsafe.md
  387. 'react/no-unsafe': 'off',
  388. // Enforce shorthand or standard form for React fragments
  389. // https://github.com/yannickcr/eslint-plugin-react/blob/bc976b837abeab1dffd90ac6168b746a83fc83cc/docs/rules/jsx-fragments.md
  390. 'react/jsx-fragments': ['error', 'syntax'],
  391. // Enforce linebreaks in curly braces in JSX attributes and expressions.
  392. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-newline.md
  393. 'react/jsx-curly-newline': ['error', {
  394. multiline: 'consistent',
  395. singleline: 'consistent',
  396. }],
  397. // Enforce state initialization style
  398. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/state-in-constructor.md
  399. // TODO: set to "never" once babel-preset-airbnb supports public class fields
  400. 'react/state-in-constructor': ['error', 'always'],
  401. // Enforces where React component static properties should be positioned
  402. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/static-property-placement.md
  403. // TODO: set to "static public field" once babel-preset-airbnb supports public class fields
  404. 'react/static-property-placement': ['error', 'property assignment'],
  405. // Disallow JSX props spreading
  406. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
  407. 'react/jsx-props-no-spreading': ['error', {
  408. html: 'enforce',
  409. custom: 'enforce',
  410. explicitSpread: 'ignore',
  411. exceptions: [],
  412. }],
  413. // Enforce that props are read-only
  414. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-read-only-props.md
  415. 'react/prefer-read-only-props': 'off',
  416. // Prevent usage of `javascript:` URLs
  417. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md
  418. 'react/jsx-no-script-url': ['error', [
  419. {
  420. name: 'Link',
  421. props: ['to'],
  422. },
  423. ]],
  424. // Disallow unnecessary fragments
  425. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
  426. 'react/jsx-no-useless-fragment': 'error',
  427. // Prevent adjacent inline elements not separated by whitespace
  428. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-adjacent-inline-elements.md
  429. // TODO: enable? semver-major
  430. 'react/no-adjacent-inline-elements': 'off',
  431. // Enforce a specific function type for function components
  432. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
  433. 'react/function-component-definition': ['error', {
  434. namedComponents: ['function-declaration', 'function-expression'],
  435. unnamedComponents: 'function-expression',
  436. }],
  437. // Enforce a new line after jsx elements and expressions
  438. // https://github.com/yannickcr/eslint-plugin-react/blob/e2eaadae316f9506d163812a09424eb42698470a/docs/rules/jsx-newline.md
  439. 'react/jsx-newline': 'off',
  440. // Prevent react contexts from taking non-stable values
  441. // https://github.com/yannickcr/eslint-plugin-react/blob/e2eaadae316f9506d163812a09424eb42698470a/docs/rules/jsx-no-constructed-context-values.md
  442. 'react/jsx-no-constructed-context-values': 'error',
  443. // Prevent creating unstable components inside components
  444. // https://github.com/yannickcr/eslint-plugin-react/blob/c2a790a3472eea0f6de984bdc3ee2a62197417fb/docs/rules/no-unstable-nested-components.md
  445. 'react/no-unstable-nested-components': 'error',
  446. // Enforce that namespaces are not used in React elements
  447. // https://github.com/yannickcr/eslint-plugin-react/blob/8785c169c25b09b33c95655bf508cf46263bc53f/docs/rules/no-namespace.md
  448. 'react/no-namespace': 'error',
  449. // Prefer exact proptype definitions
  450. // https://github.com/yannickcr/eslint-plugin-react/blob/8785c169c25b09b33c95655bf508cf46263bc53f/docs/rules/prefer-exact-props.md
  451. 'react/prefer-exact-props': 'error',
  452. // Lifecycle methods should be methods on the prototype, not class fields
  453. // https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-arrow-function-lifecycle.md
  454. 'react/no-arrow-function-lifecycle': 'error',
  455. // Prevent usage of invalid attributes
  456. // https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-invalid-html-attribute.md
  457. 'react/no-invalid-html-attribute': 'error',
  458. // Prevent declaring unused methods of component class
  459. // https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-unused-class-component-methods.md
  460. 'react/no-unused-class-component-methods': 'error',
  461. },
  462. settings: {
  463. 'import/resolver': {
  464. node: {
  465. extensions: ['.js', '.jsx', '.json']
  466. }
  467. },
  468. react: {
  469. pragma: 'React',
  470. version: 'detect',
  471. },
  472. propWrapperFunctions: [
  473. 'forbidExtraProps', // https://www.npmjs.com/package/airbnb-prop-types
  474. 'exact', // https://www.npmjs.com/package/prop-types-exact
  475. 'Object.freeze', // https://tc39.github.io/ecma262/#sec-object.freeze
  476. ],
  477. }
  478. };