index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. 'use strict';
  2. const fromEntries = require('object.fromentries');
  3. const entries = require('object.entries');
  4. /* eslint-disable global-require */
  5. const allRules = {
  6. 'boolean-prop-naming': require('./lib/rules/boolean-prop-naming'),
  7. 'button-has-type': require('./lib/rules/button-has-type'),
  8. 'default-props-match-prop-types': require('./lib/rules/default-props-match-prop-types'),
  9. 'destructuring-assignment': require('./lib/rules/destructuring-assignment'),
  10. 'display-name': require('./lib/rules/display-name'),
  11. 'forbid-component-props': require('./lib/rules/forbid-component-props'),
  12. 'forbid-dom-props': require('./lib/rules/forbid-dom-props'),
  13. 'forbid-elements': require('./lib/rules/forbid-elements'),
  14. 'forbid-foreign-prop-types': require('./lib/rules/forbid-foreign-prop-types'),
  15. 'forbid-prop-types': require('./lib/rules/forbid-prop-types'),
  16. 'function-component-definition': require('./lib/rules/function-component-definition'),
  17. 'jsx-boolean-value': require('./lib/rules/jsx-boolean-value'),
  18. 'jsx-child-element-spacing': require('./lib/rules/jsx-child-element-spacing'),
  19. 'jsx-closing-bracket-location': require('./lib/rules/jsx-closing-bracket-location'),
  20. 'jsx-closing-tag-location': require('./lib/rules/jsx-closing-tag-location'),
  21. 'jsx-curly-spacing': require('./lib/rules/jsx-curly-spacing'),
  22. 'jsx-curly-newline': require('./lib/rules/jsx-curly-newline'),
  23. 'jsx-equals-spacing': require('./lib/rules/jsx-equals-spacing'),
  24. 'jsx-filename-extension': require('./lib/rules/jsx-filename-extension'),
  25. 'jsx-first-prop-new-line': require('./lib/rules/jsx-first-prop-new-line'),
  26. 'jsx-handler-names': require('./lib/rules/jsx-handler-names'),
  27. 'jsx-indent': require('./lib/rules/jsx-indent'),
  28. 'jsx-indent-props': require('./lib/rules/jsx-indent-props'),
  29. 'jsx-key': require('./lib/rules/jsx-key'),
  30. 'jsx-max-depth': require('./lib/rules/jsx-max-depth'),
  31. 'jsx-max-props-per-line': require('./lib/rules/jsx-max-props-per-line'),
  32. 'jsx-newline': require('./lib/rules/jsx-newline'),
  33. 'jsx-no-bind': require('./lib/rules/jsx-no-bind'),
  34. 'jsx-no-comment-textnodes': require('./lib/rules/jsx-no-comment-textnodes'),
  35. 'jsx-no-constructed-context-values': require('./lib/rules/jsx-no-constructed-context-values'),
  36. 'jsx-no-duplicate-props': require('./lib/rules/jsx-no-duplicate-props'),
  37. 'jsx-no-literals': require('./lib/rules/jsx-no-literals'),
  38. 'jsx-no-script-url': require('./lib/rules/jsx-no-script-url'),
  39. 'jsx-no-target-blank': require('./lib/rules/jsx-no-target-blank'),
  40. 'jsx-no-useless-fragment': require('./lib/rules/jsx-no-useless-fragment'),
  41. 'jsx-one-expression-per-line': require('./lib/rules/jsx-one-expression-per-line'),
  42. 'jsx-no-undef': require('./lib/rules/jsx-no-undef'),
  43. 'jsx-curly-brace-presence': require('./lib/rules/jsx-curly-brace-presence'),
  44. 'jsx-pascal-case': require('./lib/rules/jsx-pascal-case'),
  45. 'jsx-fragments': require('./lib/rules/jsx-fragments'),
  46. 'jsx-props-no-multi-spaces': require('./lib/rules/jsx-props-no-multi-spaces'),
  47. 'jsx-props-no-spreading': require('./lib/rules/jsx-props-no-spreading'),
  48. 'jsx-sort-default-props': require('./lib/rules/jsx-sort-default-props'),
  49. 'jsx-sort-props': require('./lib/rules/jsx-sort-props'),
  50. 'jsx-space-before-closing': require('./lib/rules/jsx-space-before-closing'),
  51. 'jsx-tag-spacing': require('./lib/rules/jsx-tag-spacing'),
  52. 'jsx-uses-react': require('./lib/rules/jsx-uses-react'),
  53. 'jsx-uses-vars': require('./lib/rules/jsx-uses-vars'),
  54. 'jsx-wrap-multilines': require('./lib/rules/jsx-wrap-multilines'),
  55. 'no-access-state-in-setstate': require('./lib/rules/no-access-state-in-setstate'),
  56. 'no-adjacent-inline-elements': require('./lib/rules/no-adjacent-inline-elements'),
  57. 'no-array-index-key': require('./lib/rules/no-array-index-key'),
  58. 'no-children-prop': require('./lib/rules/no-children-prop'),
  59. 'no-danger': require('./lib/rules/no-danger'),
  60. 'no-danger-with-children': require('./lib/rules/no-danger-with-children'),
  61. 'no-deprecated': require('./lib/rules/no-deprecated'),
  62. 'no-did-mount-set-state': require('./lib/rules/no-did-mount-set-state'),
  63. 'no-did-update-set-state': require('./lib/rules/no-did-update-set-state'),
  64. 'no-direct-mutation-state': require('./lib/rules/no-direct-mutation-state'),
  65. 'no-find-dom-node': require('./lib/rules/no-find-dom-node'),
  66. 'no-is-mounted': require('./lib/rules/no-is-mounted'),
  67. 'no-multi-comp': require('./lib/rules/no-multi-comp'),
  68. 'no-set-state': require('./lib/rules/no-set-state'),
  69. 'no-string-refs': require('./lib/rules/no-string-refs'),
  70. 'no-redundant-should-component-update': require('./lib/rules/no-redundant-should-component-update'),
  71. 'no-render-return-value': require('./lib/rules/no-render-return-value'),
  72. 'no-this-in-sfc': require('./lib/rules/no-this-in-sfc'),
  73. 'no-typos': require('./lib/rules/no-typos'),
  74. 'no-unescaped-entities': require('./lib/rules/no-unescaped-entities'),
  75. 'no-unknown-property': require('./lib/rules/no-unknown-property'),
  76. 'no-unsafe': require('./lib/rules/no-unsafe'),
  77. 'no-unstable-nested-components': require('./lib/rules/no-unstable-nested-components'),
  78. 'no-unused-prop-types': require('./lib/rules/no-unused-prop-types'),
  79. 'no-unused-state': require('./lib/rules/no-unused-state'),
  80. 'no-will-update-set-state': require('./lib/rules/no-will-update-set-state'),
  81. 'prefer-es6-class': require('./lib/rules/prefer-es6-class'),
  82. 'prefer-read-only-props': require('./lib/rules/prefer-read-only-props'),
  83. 'prefer-stateless-function': require('./lib/rules/prefer-stateless-function'),
  84. 'prop-types': require('./lib/rules/prop-types'),
  85. 'react-in-jsx-scope': require('./lib/rules/react-in-jsx-scope'),
  86. 'require-default-props': require('./lib/rules/require-default-props'),
  87. 'require-optimization': require('./lib/rules/require-optimization'),
  88. 'require-render-return': require('./lib/rules/require-render-return'),
  89. 'self-closing-comp': require('./lib/rules/self-closing-comp'),
  90. 'sort-comp': require('./lib/rules/sort-comp'),
  91. 'sort-prop-types': require('./lib/rules/sort-prop-types'),
  92. 'state-in-constructor': require('./lib/rules/state-in-constructor'),
  93. 'static-property-placement': require('./lib/rules/static-property-placement'),
  94. 'style-prop-object': require('./lib/rules/style-prop-object'),
  95. 'void-dom-elements-no-children': require('./lib/rules/void-dom-elements-no-children')
  96. };
  97. /* eslint-enable */
  98. function filterRules(rules, predicate) {
  99. return fromEntries(entries(rules).filter((entry) => predicate(entry[1])));
  100. }
  101. function configureAsError(rules) {
  102. return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
  103. }
  104. const activeRules = filterRules(allRules, (rule) => !rule.meta.deprecated);
  105. const activeRulesConfig = configureAsError(activeRules);
  106. const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated);
  107. module.exports = {
  108. deprecatedRules,
  109. rules: allRules,
  110. configs: {
  111. recommended: {
  112. plugins: [
  113. 'react'
  114. ],
  115. parserOptions: {
  116. ecmaFeatures: {
  117. jsx: true
  118. }
  119. },
  120. rules: {
  121. 'react/display-name': 2,
  122. 'react/jsx-key': 2,
  123. 'react/jsx-no-comment-textnodes': 2,
  124. 'react/jsx-no-duplicate-props': 2,
  125. 'react/jsx-no-target-blank': 2,
  126. 'react/jsx-no-undef': 2,
  127. 'react/jsx-uses-react': 2,
  128. 'react/jsx-uses-vars': 2,
  129. 'react/no-children-prop': 2,
  130. 'react/no-danger-with-children': 2,
  131. 'react/no-deprecated': 2,
  132. 'react/no-direct-mutation-state': 2,
  133. 'react/no-find-dom-node': 2,
  134. 'react/no-is-mounted': 2,
  135. 'react/no-render-return-value': 2,
  136. 'react/no-string-refs': 2,
  137. 'react/no-unescaped-entities': 2,
  138. 'react/no-unknown-property': 2,
  139. 'react/no-unsafe': 0,
  140. 'react/prop-types': 2,
  141. 'react/react-in-jsx-scope': 2,
  142. 'react/require-render-return': 2
  143. }
  144. },
  145. all: {
  146. plugins: [
  147. 'react'
  148. ],
  149. parserOptions: {
  150. ecmaFeatures: {
  151. jsx: true
  152. }
  153. },
  154. rules: activeRulesConfig
  155. },
  156. 'jsx-runtime': {
  157. plugins: [
  158. 'react'
  159. ],
  160. parserOptions: {
  161. ecmaFeatures: {
  162. jsx: true
  163. }
  164. },
  165. rules: {
  166. 'react/react-in-jsx-scope': 0,
  167. 'react/jsx-uses-react': 0
  168. }
  169. }
  170. }
  171. };