.eslintrc.js 6.8 KB

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