.eslintrc.js 7.0 KB

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