.eslintrc.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. 'jsx-a11y/alt-text': 'off',
  15. 'jsx-a11y/anchor-is-valid': 'off',
  16. 'jsx-a11y/click-events-have-key-events': 'off',
  17. 'jsx-a11y/interactive-supports-focus': 'off',
  18. 'jsx-a11y/no-noninteractive-element-interactions': 'off',
  19. 'jsx-a11y/role-supports-aria-props': 'off',
  20. 'lines-between-class-members': 'off',
  21. 'max-classes-per-file': 'off',
  22. 'no-await-in-loop': 'off',
  23. 'no-continue': 'off',
  24. 'no-else-return': 'off',
  25. 'no-extra-boolean-cast': 'off',
  26. 'no-import-assign': 'off',
  27. 'no-lonely-if': 'off',
  28. 'no-plusplus': 'off',
  29. 'no-prototype-builtins': 'off',
  30. 'no-restricted-syntax': 'off',
  31. 'no-this-before-super': 'off',
  32. 'operator-assignment': 'off',
  33. 'prefer-destructuring': 'off',
  34. 'prefer-object-spread': 'off',
  35. 'prefer-promise-reject-errors': 'off',
  36. 'react-hooks/exhaustive-deps': 'off',
  37. 'react-hooks/rules-of-hooks': 'off',
  38. 'react/button-has-type': 'off',
  39. 'react/destructuring-assignment': 'off',
  40. 'react/forbid-prop-types': 'off',
  41. 'react/function-component-definition': 'off',
  42. 'react/jsx-curly-brace-presence': 'off',
  43. 'react/jsx-filename-extension': 'off',
  44. 'react/jsx-no-useless-fragment': 'off',
  45. 'react/jsx-props-no-spreading': 'off',
  46. 'react/no-danger': 'off',
  47. 'react/no-deprecated': 'off',
  48. 'react/require-default-props': 'off',
  49. };
  50. module.exports = {
  51. extends: [
  52. '@wagtail/eslint-config-wagtail',
  53. 'plugin:@typescript-eslint/recommended',
  54. ],
  55. parser: '@typescript-eslint/parser',
  56. plugins: ['@typescript-eslint'],
  57. env: {
  58. jest: true,
  59. browser: true,
  60. },
  61. rules: {
  62. '@typescript-eslint/explicit-function-return-type': 'off',
  63. '@typescript-eslint/explicit-member-accessibility': 'off',
  64. '@typescript-eslint/explicit-module-boundary-types': 'off',
  65. '@typescript-eslint/no-explicit-any': 'off',
  66. '@typescript-eslint/no-use-before-define': ['error'],
  67. 'import/extensions': [
  68. 'error',
  69. 'always',
  70. {
  71. ignorePackages: true,
  72. pattern: {
  73. js: 'never',
  74. jsx: 'never',
  75. ts: 'never',
  76. tsx: 'never',
  77. },
  78. },
  79. ],
  80. // does not align with the majority of legacy and newer code, some use named others use default exports
  81. 'import/prefer-default-export': 'off',
  82. // note you must disable the base rule as it can report incorrect errors
  83. 'no-use-before-define': 'off',
  84. 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }],
  85. 'no-underscore-dangle': [
  86. 'error',
  87. { allow: ['__REDUX_DEVTOOLS_EXTENSION__'] },
  88. ],
  89. },
  90. settings: {
  91. 'import/resolver': {
  92. node: {
  93. extensions: ['.js', '.ts', '.tsx'],
  94. },
  95. },
  96. },
  97. overrides: [
  98. // Legacy Code - remove from `files` when adopting desired rules in new code progressively
  99. {
  100. files: [
  101. 'client/src/components/**',
  102. 'client/src/entrypoints/**',
  103. 'client/src/utils/**',
  104. '**/documents/static_src/wagtaildocs/js/add-multiple.js',
  105. '**/images/static_src/wagtailimages/js/add-multiple.js',
  106. '**/images/static_src/wagtailimages/js/focal-point-chooser.js',
  107. '**/snippets/static_src/wagtailsnippets/js/snippet-multiple-select.js',
  108. ],
  109. rules: legacyCode,
  110. },
  111. {
  112. // Rules we don’t want to enforce for test and tooling code.
  113. files: [
  114. 'client/extract-translatable-strings.js',
  115. 'client/tests/**',
  116. 'webpack.config.js',
  117. 'tailwind.config.js',
  118. 'storybook/**/*',
  119. '*.test.ts',
  120. '*.test.tsx',
  121. '*.test.js',
  122. '*.stories.js',
  123. '*.stories.tsx',
  124. ],
  125. rules: {
  126. '@typescript-eslint/no-empty-function': 'off',
  127. '@typescript-eslint/no-var-requires': 'off',
  128. 'import/no-extraneous-dependencies': 'off',
  129. 'react/function-component-definition': 'off',
  130. 'react/jsx-props-no-spreading': 'off',
  131. },
  132. },
  133. {
  134. files: ['docs/_static/**'],
  135. globals: { $: 'readonly' },
  136. },
  137. {
  138. files: ['wagtail/**/**'],
  139. globals: {
  140. $: 'readonly',
  141. addMessage: 'readonly',
  142. buildExpandingFormset: 'readonly',
  143. cancelSpinner: 'readonly',
  144. escapeHtml: 'readonly',
  145. jQuery: 'readonly',
  146. jsonData: 'readonly',
  147. ModalWorkflow: 'readonly',
  148. DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  149. EMBED_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  150. IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  151. QUERY_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  152. SNIPPET_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
  153. },
  154. rules: {
  155. '@typescript-eslint/no-unused-vars': 'off',
  156. '@typescript-eslint/no-use-before-define': 'off',
  157. 'camelcase': [
  158. 'error',
  159. {
  160. allow: [
  161. '__unused_webpack_module',
  162. '__webpack_modules__',
  163. '__webpack_require__',
  164. ],
  165. properties: 'never',
  166. },
  167. ],
  168. 'consistent-return': 'off',
  169. 'func-names': 'off',
  170. 'id-length': 'off',
  171. 'indent': 'off',
  172. 'key-spacing': 'off',
  173. 'new-cap': 'off',
  174. 'newline-per-chained-call': 'off',
  175. 'no-param-reassign': 'off',
  176. 'no-underscore-dangle': 'off',
  177. 'object-shorthand': 'off',
  178. 'prefer-arrow-callback': 'off',
  179. 'quote-props': 'off',
  180. 'space-before-function-paren': 'off',
  181. 'vars-on-top': 'off',
  182. },
  183. },
  184. ],
  185. };