.eslintrc.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Rules which have been enforced in configuration upgrades and flag issues in existing code.
  2. // We need to consider whether to disable those rules permanently, or fix the issues.
  3. const legacyCode = {
  4. 'class-methods-use-this': 'off',
  5. 'constructor-super': 'off',
  6. 'default-param-last': 'off',
  7. 'import/extensions': 'off',
  8. 'import/first': 'off',
  9. 'import/newline-after-import': 'off',
  10. 'import/no-extraneous-dependencies': 'off',
  11. 'import/no-unresolved': 'off',
  12. 'import/no-useless-path-segments': 'off',
  13. 'import/order': 'off',
  14. 'import/prefer-default-export': 'off',
  15. 'jsx-a11y/alt-text': 'off',
  16. 'jsx-a11y/anchor-is-valid': 'off',
  17. 'jsx-a11y/click-events-have-key-events': 'off',
  18. 'jsx-a11y/interactive-supports-focus': 'off',
  19. 'jsx-a11y/no-noninteractive-element-interactions': 'off',
  20. 'jsx-a11y/role-supports-aria-props': 'off',
  21. 'lines-between-class-members': 'off',
  22. 'max-classes-per-file': 'off',
  23. 'no-await-in-loop': 'off',
  24. 'no-continue': 'off',
  25. 'no-else-return': 'off',
  26. 'no-extra-boolean-cast': 'off',
  27. 'no-import-assign': 'off',
  28. 'no-lonely-if': 'off',
  29. 'no-plusplus': 'off',
  30. 'no-prototype-builtins': 'off',
  31. 'no-restricted-syntax': 'off',
  32. 'no-this-before-super': 'off',
  33. 'operator-assignment': 'off',
  34. 'prefer-destructuring': 'off',
  35. 'prefer-object-spread': 'off',
  36. 'prefer-promise-reject-errors': 'off',
  37. 'react-hooks/exhaustive-deps': 'off',
  38. 'react-hooks/rules-of-hooks': 'off',
  39. 'react/button-has-type': 'off',
  40. 'react/destructuring-assignment': 'off',
  41. 'react/forbid-prop-types': 'off',
  42. 'react/function-component-definition': 'off',
  43. 'react/jsx-curly-brace-presence': 'off',
  44. 'react/jsx-filename-extension': 'off',
  45. 'react/jsx-no-useless-fragment': 'off',
  46. 'react/jsx-props-no-spreading': 'off',
  47. 'react/no-danger': 'off',
  48. 'react/no-deprecated': 'off',
  49. 'react/require-default-props': 'off',
  50. };
  51. module.exports = {
  52. extends: [
  53. '@wagtail/eslint-config-wagtail',
  54. 'plugin:@typescript-eslint/recommended',
  55. ],
  56. parser: '@typescript-eslint/parser',
  57. plugins: ['@typescript-eslint'],
  58. env: {
  59. jest: true,
  60. browser: true,
  61. },
  62. rules: {
  63. 'no-underscore-dangle': [
  64. 'error',
  65. { allow: ['__REDUX_DEVTOOLS_EXTENSION__'] },
  66. ],
  67. // note you must disable the base rule as it can report incorrect errors
  68. 'no-use-before-define': 'off',
  69. '@typescript-eslint/no-use-before-define': ['error'],
  70. '@typescript-eslint/explicit-module-boundary-types': 'off',
  71. '@typescript-eslint/explicit-member-accessibility': 'off',
  72. '@typescript-eslint/explicit-function-return-type': 'off',
  73. '@typescript-eslint/no-explicit-any': 'off',
  74. 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }],
  75. 'import/extensions': [
  76. 'error',
  77. 'always',
  78. {
  79. ignorePackages: true,
  80. pattern: {
  81. js: 'never',
  82. jsx: 'never',
  83. ts: 'never',
  84. tsx: 'never',
  85. },
  86. },
  87. ],
  88. ...legacyCode,
  89. },
  90. overrides: [
  91. {
  92. // Rules we don’t want to enforce for test and tooling code.
  93. files: [
  94. '*.test.ts',
  95. '*.test.tsx',
  96. '*.test.js',
  97. 'webpack.config.js',
  98. 'tailwind.config.js',
  99. '*.stories.js',
  100. '*.stories.tsx',
  101. 'storybook/**/*',
  102. ],
  103. rules: {
  104. '@typescript-eslint/no-empty-function': 'off',
  105. '@typescript-eslint/no-var-requires': 'off',
  106. },
  107. },
  108. {
  109. files: ['docs/_static/**'],
  110. globals: { $: 'readonly' },
  111. },
  112. {
  113. files: ['wagtail/**/**'],
  114. globals: {
  115. $: 'readonly',
  116. addMessage: 'readonly',
  117. buildExpandingFormset: 'readonly',
  118. cancelSpinner: 'readonly',
  119. escapeHtml: 'readonly',
  120. insertRichTextDeleteControl: 'readonly',
  121. jQuery: 'readonly',
  122. jsonData: 'readonly',
  123. ModalWorkflow: 'readonly',
  124. DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  125. EMBED_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  126. IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  127. QUERY_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  128. SNIPPET_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  129. },
  130. rules: {
  131. '@typescript-eslint/no-unused-vars': 'off',
  132. '@typescript-eslint/no-use-before-define': 'off',
  133. 'camelcase': [
  134. 'error',
  135. {
  136. allow: [
  137. '__unused_webpack_module',
  138. '__webpack_modules__',
  139. '__webpack_require__',
  140. ],
  141. properties: 'never',
  142. },
  143. ],
  144. 'consistent-return': 'off',
  145. 'func-names': 'off',
  146. 'id-length': 'off',
  147. 'indent': 'off',
  148. 'key-spacing': 'off',
  149. 'new-cap': 'off',
  150. 'newline-per-chained-call': 'off',
  151. 'no-param-reassign': 'off',
  152. 'no-underscore-dangle': 'off',
  153. 'object-shorthand': 'off',
  154. 'prefer-arrow-callback': 'off',
  155. 'quote-props': 'off',
  156. 'space-before-function-paren': 'off',
  157. 'vars-on-top': 'off',
  158. },
  159. },
  160. ],
  161. };