ratchapong

Reorganize eslint react

Mar 15th, 2022
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const supported = `
  2. react/boolean-prop-naming\tEnforces consistent naming for boolean props
  3. react/button-has-type\tForbid "button" element without an explicit "type" attribute
  4. react/default-props-match-prop-types\tEnforce all defaultProps are defined and not "required" in propTypes.
  5. react/destructuring-assignment\tEnforce consistent usage of destructuring assignment of props, state, and context
  6. ✔\t\treact/display-name\tPrevent missing displayName in a React component definition
  7. react/forbid-component-props\tForbid certain props on components
  8. react/forbid-dom-props\tForbid certain props on DOM Nodes
  9. react/forbid-elements\tForbid certain elements
  10. react/forbid-foreign-prop-types\tForbid using another component's propTypes
  11. react/forbid-prop-types\tForbid certain propTypes
  12. 🔧\treact/function-component-definition\tStandardize the way function component get defined
  13. react/hook-use-state\tEnsure symmetric naming of useState hook value and setter variables
  14. react/iframe-missing-sandbox\tEnforce sandbox attribute on iframe elements
  15. react/no-access-state-in-setstate\tReports when this.state is accessed within setState
  16. react/no-adjacent-inline-elements\tPrevent adjacent inline elements not separated by whitespace.
  17. react/no-array-index-key\tPrevent usage of Array index in keys
  18. 🔧\treact/no-arrow-function-lifecycle\tLifecycle methods should be methods on the prototype, not class fields
  19. \t\treact/no-children-prop\tPrevent passing of children as props.
  20. react/no-danger\tPrevent usage of dangerous JSX props
  21. \t\treact/no-danger-with-children\tReport when a DOM element is using both children and dangerouslySetInnerHTML
  22. \t\treact/no-deprecated\tPrevent usage of deprecated methods
  23. react/no-did-mount-set-state\tPrevent usage of setState in componentDidMount
  24. react/no-did-update-set-state\tPrevent usage of setState in componentDidUpdate
  25. \t\treact/no-direct-mutation-state\tPrevent direct mutation of this.state
  26. \t\treact/no-find-dom-node\tPrevent usage of findDOMNode
  27. 🔧\treact/no-invalid-html-attribute\tForbid attribute with an invalid values\`
  28. \t\treact/no-is-mounted\tPrevent usage of isMounted
  29. react/no-multi-comp\tPrevent multiple component definition per file
  30. react/no-namespace\tEnforce that namespaces are not used in React elements
  31. react/no-redundant-should-component-update\tFlag shouldComponentUpdate when extending PureComponent
  32. \t\treact/no-render-return-value\tPrevent usage of the return value of React.render
  33. react/no-set-state\tPrevent usage of setState
  34. \t\treact/no-string-refs\tPrevent string definitions for references and prevent referencing this.refs
  35. react/no-this-in-sfc\tReport "this" being used in stateless components
  36. react/no-typos\tPrevent common typos
  37. \t\treact/no-unescaped-entities\tDetect unescaped HTML entities, which might represent malformed tags
  38. \t🔧\treact/no-unknown-property\tPrevent usage of unknown DOM property
  39. react/no-unsafe\tPrevent usage of unsafe lifecycle methods
  40. react/no-unstable-nested-components\tPrevent creating unstable components inside components
  41. react/no-unused-class-component-methods\tPrevent declaring unused methods of component class
  42. react/no-unused-prop-types\tPrevent definitions of unused prop types
  43. react/no-unused-state\tPrevent definition of unused state fields
  44. react/no-will-update-set-state\tPrevent usage of setState in componentWillUpdate
  45. react/prefer-es6-class\tEnforce ES5 or ES6 class for React Components
  46. react/prefer-exact-props\tPrefer exact proptype definitions
  47. 🔧\treact/prefer-read-only-props\tRequire read-only props.
  48. react/prefer-stateless-function\tEnforce stateless components to be written as a pure function
  49. \t\treact/prop-types\tPrevent missing props validation in a React component definition
  50. \t\treact/react-in-jsx-scope\tPrevent missing React when using JSX
  51. react/require-default-props\tEnforce a defaultProps definition for every prop that is not a required prop.
  52. react/require-optimization\tEnforce React components to have a shouldComponentUpdate method
  53. \t\treact/require-render-return\tEnforce ES5 or ES6 class for returning value in render function
  54. 🔧\treact/self-closing-comp\tPrevent extra closing tags for components without children
  55. react/sort-comp\tEnforce component methods order
  56. react/sort-prop-types\tEnforce propTypes declarations alphabetical sorting
  57. react/state-in-constructor\tState initialization in an ES6 class component should be in a constructor
  58. react/static-property-placement\tDefines where React component static properties should be positioned.
  59. react/style-prop-object\tEnforce style prop value is an object
  60. react/void-dom-elements-no-children\tPrevent passing of children to void DOM elements (e.g. <br />).
  61. `;
  62. const JSXspecificrule = `
  63. 🔧\treact/jsx-boolean-value\tEnforce boolean attributes notation in JSX
  64. react/jsx-child-element-spacing\tEnsures inline tags are not rendered without spaces between them
  65. 🔧\treact/jsx-closing-bracket-location\tValidate closing bracket location in JSX
  66. 🔧\treact/jsx-closing-tag-location\tValidate closing tag location for multiline JSX
  67. 🔧\treact/jsx-curly-brace-presence\tDisallow unnecessary JSX expressions when literals alone are sufficient or enfore JSX expressions on literals in JSX children or attributes
  68. 🔧\treact/jsx-curly-newline\tEnforce consistent line breaks inside jsx curly
  69. 🔧\treact/jsx-curly-spacing\tEnforce or disallow spaces inside of curly braces in JSX attributes
  70. 🔧\treact/jsx-equals-spacing\tDisallow or enforce spaces around equal signs in JSX attributes
  71. react/jsx-filename-extension\tRestrict file extensions that may contain JSX
  72. 🔧\treact/jsx-first-prop-new-line\tEnsure proper position of the first property in JSX
  73. 🔧\treact/jsx-fragments\tEnforce shorthand or standard form for React fragments
  74. react/jsx-handler-names\tEnforce event handler naming conventions in JSX
  75. 🔧\treact/jsx-indent\tValidate JSX indentation
  76. 🔧\treact/jsx-indent-props\tValidate props indentation in JSX
  77. \t\treact/jsx-key\tReport missing key props in iterators/collection literals
  78. react/jsx-max-depth\tValidate JSX maximum depth
  79. 🔧\treact/jsx-max-props-per-line\tLimit maximum of props on a single line in JSX
  80. 🔧\treact/jsx-newline\tRequire or prevent a new line after jsx elements and expressions.
  81. react/jsx-no-bind\tPrevents usage of Function.prototype.bind and arrow functions in React component props
  82. \t\treact/jsx-no-comment-textnodes\tComments inside children section of tag should be placed inside braces
  83. react/jsx-no-constructed-context-values\tPrevents JSX context provider values from taking values that will cause needless rerenders.
  84. \t\treact/jsx-no-duplicate-props\tEnforce no duplicate props
  85. react/jsx-no-literals\tPrevent using string literals in React component definition
  86. react/jsx-no-script-url\tForbid javascript: URLs
  87. \t🔧\treact/jsx-no-target-blank\tForbid target="_blank" attribute without rel="noreferrer"
  88. \t\treact/jsx-no-undef\tDisallow undeclared variables in JSX
  89. 🔧\treact/jsx-no-useless-fragment\tDisallow unnecessary fragments
  90. 🔧\treact/jsx-one-expression-per-line\tLimit to one expression per line in JSX
  91. react/jsx-pascal-case\tEnforce PascalCase for user-defined JSX components
  92. 🔧\treact/jsx-props-no-multi-spaces\tDisallow multiple spaces between inline JSX props
  93. react/jsx-props-no-spreading\tPrevent JSX prop spreading
  94. react/jsx-sort-default-props\tEnforce default props alphabetical sorting
  95. 🔧\treact/jsx-sort-props\tEnforce props alphabetical sorting
  96. 🔧\treact/jsx-space-before-closing\tValidate spacing before closing bracket in JSX
  97. 🔧\treact/jsx-tag-spacing\tValidate whitespace in and around the JSX opening and closing brackets
  98. \t\treact/jsx-uses-react\tPrevent React to be marked as unused
  99. \t\treact/jsx-uses-vars\tPrevent variables used in JSX to be marked as unused
  100. 🔧\treact/jsx-wrap-multilines\tPrevent missing parentheses around multilines JSX
  101. `;
  102.  
  103. const headingForList = {
  104.  supported: {},
  105.  jsx: {},
  106. };
  107. JSXspecificrule.split('\n').forEach((l) => {
  108.  if (l) {
  109.    l.trim().split('\t').forEach((c) => {
  110.      if (c.startsWith('react/')) {
  111.        headingForList.jsx[c] = 'Waiting...';
  112.      }
  113.    });
  114.  }
  115. });
  116. supported.split('\n').forEach((l) => {
  117.  if (l) {
  118.    l.trim().split('\t').forEach((c) => {
  119.      if (c.startsWith('react/')) {
  120.        headingForList.supported[c] = 'Waiting...';
  121.      }
  122.    });
  123.  }
  124. });
  125. const allRules = {
  126.  ...require('./jsx-specific').rules,
  127.  ...require('./supported').rules,
  128. };
  129. Object.keys(allRules).forEach((key) => {
  130.  Object.keys(headingForList).forEach((heading) => {
  131.    if (headingForList[heading][key]) {
  132.      headingForList[heading][key] = allRules[key];
  133.      delete allRules[key];
  134.    }
  135.  });
  136. });
  137. console.log(JSON.stringify(headingForList, null, 2));
  138.  
Advertisement
Add Comment
Please, Sign In to add comment