react.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. 'use strict';
  2. module.exports = {
  3. plugins: [
  4. 'react',
  5. ],
  6. parserOptions: {
  7. ecmaFeatures: {
  8. jsx: true,
  9. },
  10. },
  11. // View link below for react rules documentation
  12. // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
  13. rules: {
  14. // Specify whether double or single quotes should be used in JSX attributes
  15. // http://eslint.org/docs/rules/jsx-quotes
  16. 'jsx-quotes': [ 'error', 'prefer-double' ],
  17. 'class-methods-use-this': [ 'error', {
  18. exceptMethods: [
  19. 'render',
  20. 'getInitialState',
  21. 'getDefaultProps',
  22. 'getChildContext',
  23. 'componentWillMount',
  24. 'componentDidMount',
  25. 'componentWillReceiveProps',
  26. 'shouldComponentUpdate',
  27. 'componentWillUpdate',
  28. 'componentDidUpdate',
  29. 'componentWillUnmount',
  30. ],
  31. }],
  32. // Prevent missing displayName in a React component definition
  33. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
  34. 'react/display-name': [ 'off', { ignoreTranspilerName: false }],
  35. // Forbid certain propTypes (any, array, object)
  36. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
  37. 'react/forbid-prop-types': [ 'off' ],
  38. // Enforce boolean attributes notation in JSX
  39. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
  40. 'react/jsx-boolean-value': [ 'error', 'never' ],
  41. // Validate closing bracket location in JSX
  42. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
  43. 'react/jsx-closing-bracket-location': [ 'error', 'line-aligned' ],
  44. // Enforce or disallow spaces inside of curly braces in JSX attributes
  45. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
  46. 'react/jsx-curly-spacing': [ 'error', 'never', { allowMultiline: true }],
  47. // Enforce event handler naming conventions in JSX
  48. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
  49. 'react/jsx-handler-names': [ 'off', {
  50. eventHandlerPrefix: 'handle',
  51. eventHandlerPropPrefix: 'on',
  52. }],
  53. // Validate props indentation in JSX
  54. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
  55. 'react/jsx-indent-props': [ 'error', 2 ],
  56. // Validate JSX has key prop when in array or iterator
  57. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
  58. 'react/jsx-key': 'off',
  59. // Limit maximum of props on a single line in JSX
  60. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
  61. 'react/jsx-max-props-per-line': [ 'off', { maximum: 1 }],
  62. // Prevent usage of .bind() in JSX props
  63. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
  64. 'react/jsx-no-bind': [ 'error', {
  65. ignoreRefs: true,
  66. allowArrowFunctions: true,
  67. allowBind: false,
  68. }],
  69. // Prevent duplicate props in JSX
  70. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
  71. 'react/jsx-no-duplicate-props': [ 'error', { ignoreCase: true }],
  72. // Prevent usage of unwrapped JSX strings
  73. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
  74. 'react/jsx-no-literals': 'off',
  75. // Disallow undeclared variables in JSX
  76. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
  77. 'react/jsx-no-undef': 'error',
  78. // Enforce PascalCase for user-defined JSX components
  79. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
  80. 'react/jsx-pascal-case': [ 'error', {
  81. allowAllCaps: true,
  82. ignore: [],
  83. }],
  84. // Enforce propTypes declarations alphabetical sorting
  85. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
  86. 'react/sort-prop-types': [ 'off', {
  87. ignoreCase: true,
  88. callbacksLast: false,
  89. requiredFirst: false,
  90. }],
  91. // Deprecated in favor of react/jsx-sort-props
  92. 'react/jsx-sort-prop-types': 'off',
  93. // Enforce props alphabetical sorting
  94. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
  95. 'react/jsx-sort-props': [ 'off', {
  96. ignoreCase: true,
  97. callbacksLast: false,
  98. shorthandFirst: false,
  99. shorthandLast: false,
  100. }],
  101. // Prevent React to be incorrectly marked as unused
  102. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
  103. 'react/jsx-uses-react': [ 'error' ],
  104. // Prevent variables used in JSX to be incorrectly marked as unused
  105. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
  106. 'react/jsx-uses-vars': 'error',
  107. // Prevent usage of dangerous JSX properties
  108. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
  109. 'react/no-danger': 'warn',
  110. // Prevent usage of deprecated methods
  111. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
  112. 'react/no-deprecated': [ 'error' ],
  113. // Prevent usage of setState in componentDidMount
  114. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
  115. 'react/no-did-mount-set-state': [ 'error' ],
  116. // Prevent usage of setState in componentDidUpdate
  117. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
  118. 'react/no-did-update-set-state': [ 'error' ],
  119. // Prevent direct mutation of this.state
  120. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
  121. 'react/no-direct-mutation-state': 'off',
  122. // Prevent usage of isMounted
  123. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
  124. 'react/no-is-mounted': 'error',
  125. // Prevent multiple component definition per file
  126. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
  127. 'react/no-multi-comp': [ 'error', { ignoreStateless: true }],
  128. // Prevent usage of setState
  129. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
  130. 'react/no-set-state': 'off',
  131. // Prevent using string references
  132. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
  133. 'react/no-string-refs': 'error',
  134. // Prevent usage of unknown DOM property
  135. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
  136. 'react/no-unknown-property': 'error',
  137. // Require ES6 class declarations over React.createClass
  138. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
  139. 'react/prefer-es6-class': [ 'error', 'always' ],
  140. // Require stateless functions when not using lifecycle methods, setState or ref
  141. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
  142. 'react/prefer-stateless-function': 'off',
  143. // Prevent missing props validation in a React component definition
  144. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
  145. 'react/prop-types': [ 'error', { ignore: [], customValidators: [] }],
  146. // Prevent missing React when using JSX
  147. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
  148. 'react/react-in-jsx-scope': 'error',
  149. // Require render() methods to return something
  150. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
  151. 'react/require-render-return': 'error',
  152. // Prevent extra closing tags for components without children
  153. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
  154. 'react/self-closing-comp': 'error',
  155. // Enforce component methods order
  156. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
  157. 'react/sort-comp': [ 'error', {
  158. order: [
  159. 'static-methods',
  160. 'lifecycle',
  161. '/^on.+$/',
  162. '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
  163. 'everything-else',
  164. '/^render.+$/',
  165. 'render',
  166. ],
  167. }],
  168. // Prevent missing parentheses around multilines JSX
  169. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
  170. 'react/jsx-wrap-multilines': [ 'error', {
  171. declaration: true,
  172. assignment: true,
  173. return: true,
  174. }],
  175. // Require that the first prop in a JSX element be on a new line when the element is multiline
  176. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
  177. 'react/jsx-first-prop-new-line': [ 'error', 'multiline' ],
  178. // Enforce spacing around jsx equals signs
  179. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
  180. 'react/jsx-equals-spacing': [ 'error', 'never' ],
  181. // Enforce JSX indentation
  182. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
  183. 'react/jsx-indent': [ 'error', 2 ],
  184. // Disallow target="_blank" on links
  185. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
  186. 'react/jsx-no-target-blank': 'error',
  187. // only .jsx files may have JSX
  188. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
  189. 'react/jsx-filename-extension': [ 'error', { extensions: [ '.jsx' ] }],
  190. // prevent accidental JS comments from being injected into JSX as text
  191. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
  192. 'react/jsx-no-comment-textnodes': 'error',
  193. // disallow using React.render/ReactDOM.render's return value
  194. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
  195. 'react/no-render-return-value': 'error',
  196. // require a shouldComponentUpdate method, or PureRenderMixin
  197. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-optimization.md
  198. 'react/require-optimization': [ 'off', { allowDecorators: [] }],
  199. // warn against using findDOMNode()
  200. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md
  201. 'react/no-find-dom-node': 'error',
  202. // Forbid certain props on Components
  203. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md
  204. 'react/forbid-component-props': [ 'off', { forbid: [] }],
  205. // Prevent problem with children and props.dangerouslySetInnerHTML
  206. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
  207. 'react/no-danger-with-children': 'error',
  208. // Prevent unused propType definitions
  209. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
  210. 'react/no-unused-prop-types': [ 'error', {
  211. customValidators: [
  212. ],
  213. skipShapeProps: true,
  214. }],
  215. // Require style prop value be an object or var
  216. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md
  217. 'react/style-prop-object': 'error',
  218. // Prevent invalid characters from appearing in markup
  219. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
  220. 'react/no-unescaped-entities': 'error',
  221. // Prevent passing of children as props
  222. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
  223. 'react/no-children-prop': 'error',
  224. // Validate whitespace in and around the JSX opening and closing brackets
  225. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md
  226. 'react/jsx-tag-spacing': [ 'error', {
  227. closingSlash: 'never',
  228. beforeSelfClosing: 'always',
  229. afterOpening: 'never',
  230. }],
  231. // Prevent usage of Array index in keys
  232. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
  233. 'react/no-array-index-key': 'error',
  234. // Enforce a defaultProps definition for every prop that is not a required prop
  235. // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
  236. 'react/require-default-props': 'off',
  237. },
  238. settings: {
  239. 'import/resolver': {
  240. node: {
  241. extensions: [ '.js', '.jsx', '.json' ],
  242. },
  243. },
  244. react: {
  245. pragma: 'React',
  246. version: '0.14',
  247. },
  248. },
  249. };