.eslintrc.js 6.8 KB

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