.eslintrc.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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/first': 'off',
  8. 'import/newline-after-import': 'off',
  9. 'import/no-cycle': 'off',
  10. 'import/no-extraneous-dependencies': 'off',
  11. 'import/no-unresolved': ['error', { ignore: ['jquery'] }],
  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. '@typescript-eslint/explicit-function-return-type': 'off',
  64. '@typescript-eslint/explicit-member-accessibility': 'off',
  65. '@typescript-eslint/explicit-module-boundary-types': 'off',
  66. '@typescript-eslint/no-explicit-any': 'off',
  67. '@typescript-eslint/no-use-before-define': ['error'],
  68. 'import/extensions': [
  69. 'error',
  70. 'always',
  71. {
  72. ignorePackages: true,
  73. pattern: {
  74. js: 'never',
  75. jsx: 'never',
  76. ts: 'never',
  77. tsx: 'never',
  78. },
  79. },
  80. ],
  81. // note you must disable the base rule as it can report incorrect errors
  82. 'no-use-before-define': 'off',
  83. 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }],
  84. 'no-underscore-dangle': [
  85. 'error',
  86. { allow: ['__REDUX_DEVTOOLS_EXTENSION__'] },
  87. ],
  88. },
  89. settings: {
  90. 'import/resolver': {
  91. node: {
  92. extensions: ['.js', '.ts', '.tsx'],
  93. },
  94. },
  95. },
  96. overrides: [
  97. // Legacy Code - remove from `files` when adopting desired rules in new code progressively
  98. {
  99. files: [
  100. 'client/src/components/**',
  101. 'client/src/entrypoints/**',
  102. 'client/src/utils/**',
  103. '**/documents/static_src/wagtaildocs/js/add-multiple.js',
  104. '**/images/static_src/wagtailimages/js/add-multiple.js',
  105. '**/images/static_src/wagtailimages/js/focal-point-chooser.js',
  106. '**/snippets/static_src/wagtailsnippets/js/snippet-multiple-select.js',
  107. ],
  108. rules: legacyCode,
  109. },
  110. {
  111. // Rules we don’t want to enforce for test and tooling code.
  112. files: [
  113. 'client/extract-translatable-strings.js',
  114. 'client/tests/**',
  115. 'webpack.config.js',
  116. 'tailwind.config.js',
  117. 'storybook/**/*',
  118. '*.test.ts',
  119. '*.test.tsx',
  120. '*.test.js',
  121. '*.stories.js',
  122. '*.stories.tsx',
  123. ],
  124. rules: {
  125. '@typescript-eslint/no-empty-function': 'off',
  126. '@typescript-eslint/no-var-requires': 'off',
  127. 'import/no-extraneous-dependencies': 'off',
  128. 'react/function-component-definition': 'off',
  129. 'react/jsx-props-no-spreading': 'off',
  130. },
  131. },
  132. {
  133. files: ['docs/_static/**'],
  134. globals: { $: 'readonly' },
  135. },
  136. {
  137. files: [
  138. 'wagtail/**/**',
  139. 'client/src/entrypoints/documents/document-chooser-modal.js',
  140. 'client/src/entrypoints/images/image-chooser-modal.js',
  141. ],
  142. globals: {
  143. $: 'readonly',
  144. addMessage: 'readonly',
  145. buildExpandingFormset: 'readonly',
  146. cancelSpinner: 'readonly',
  147. escapeHtml: 'readonly',
  148. jQuery: 'readonly',
  149. jsonData: 'readonly',
  150. ModalWorkflow: 'readonly',
  151. DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  152. EMBED_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  153. IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  154. QUERY_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  155. SNIPPET_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  156. },
  157. rules: {
  158. '@typescript-eslint/no-unused-vars': 'off',
  159. '@typescript-eslint/no-use-before-define': 'off',
  160. 'camelcase': [
  161. 'error',
  162. {
  163. allow: [
  164. '__unused_webpack_module',
  165. '__webpack_modules__',
  166. '__webpack_require__',
  167. ],
  168. properties: 'never',
  169. },
  170. ],
  171. 'consistent-return': 'off',
  172. 'func-names': 'off',
  173. 'id-length': 'off',
  174. 'indent': 'off',
  175. 'key-spacing': 'off',
  176. 'new-cap': 'off',
  177. 'newline-per-chained-call': 'off',
  178. 'no-param-reassign': 'off',
  179. 'no-underscore-dangle': 'off',
  180. 'object-shorthand': 'off',
  181. 'prefer-arrow-callback': 'off',
  182. 'quote-props': 'off',
  183. 'space-before-function-paren': 'off',
  184. 'vars-on-top': 'off',
  185. },
  186. },
  187. ],
  188. };