2021-12-23 03:18:04 +00:00
|
|
|
|
// Rules which have been enforced in configuration upgrades and flag issues in existing code.
|
|
|
|
|
// We need to consider whether to disable those rules permanently, or fix the issues.
|
|
|
|
|
const legacyCode = {
|
2022-02-04 11:57:55 +00:00
|
|
|
|
'class-methods-use-this': 'off',
|
|
|
|
|
'constructor-super': 'off',
|
|
|
|
|
'default-param-last': 'off',
|
|
|
|
|
'max-classes-per-file': 'off',
|
|
|
|
|
'no-continue': 'off',
|
|
|
|
|
'no-else-return': 'off',
|
|
|
|
|
'no-plusplus': 'off',
|
|
|
|
|
'no-prototype-builtins': 'off',
|
|
|
|
|
'no-restricted-syntax': 'off',
|
|
|
|
|
'no-this-before-super': 'off',
|
|
|
|
|
};
|
2021-12-23 03:18:04 +00:00
|
|
|
|
|
|
|
|
|
module.exports = {
|
2022-02-04 11:57:55 +00:00
|
|
|
|
extends: [
|
|
|
|
|
'@wagtail/eslint-config-wagtail',
|
|
|
|
|
'plugin:@typescript-eslint/recommended',
|
2021-12-23 03:18:04 +00:00
|
|
|
|
],
|
2022-02-04 11:57:55 +00:00
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
|
plugins: ['@typescript-eslint'],
|
|
|
|
|
env: {
|
|
|
|
|
jest: true,
|
|
|
|
|
browser: true,
|
2019-04-23 14:02:53 +00:00
|
|
|
|
},
|
2022-02-04 11:57:55 +00:00
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2022-02-04 11:57:55 +00:00
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
'@typescript-eslint/no-use-before-define': ['error'],
|
2021-12-23 03:18:04 +00:00
|
|
|
|
'import/extensions': [
|
2022-02-04 11:57:55 +00:00
|
|
|
|
'error',
|
2021-12-23 03:18:04 +00:00
|
|
|
|
'always',
|
|
|
|
|
{
|
|
|
|
|
ignorePackages: true,
|
|
|
|
|
pattern: {
|
|
|
|
|
js: 'never',
|
|
|
|
|
jsx: 'never',
|
|
|
|
|
ts: 'never',
|
|
|
|
|
tsx: 'never',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-05-31 21:47:50 +00:00
|
|
|
|
// does not align with the majority of legacy and newer code, some use named others use default exports
|
|
|
|
|
'import/prefer-default-export': 'off',
|
2022-06-23 10:58:56 +00:00
|
|
|
|
// allow no lines between single line members (e.g. static declarations)
|
|
|
|
|
'lines-between-class-members': [
|
|
|
|
|
'error',
|
|
|
|
|
'always',
|
|
|
|
|
{ exceptAfterSingleLine: true },
|
|
|
|
|
],
|
2022-05-20 15:08:13 +00:00
|
|
|
|
// note you must disable the base rule as it can report incorrect errors
|
|
|
|
|
'no-use-before-define': 'off',
|
|
|
|
|
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }],
|
|
|
|
|
'no-underscore-dangle': [
|
|
|
|
|
'error',
|
|
|
|
|
{ allow: ['__REDUX_DEVTOOLS_EXTENSION__'] },
|
|
|
|
|
],
|
2022-09-20 10:32:33 +00:00
|
|
|
|
// this rule can be confusing as it forces some non-intuitive code for variable assignment
|
|
|
|
|
'prefer-destructuring': 'off',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
},
|
|
|
|
|
settings: {
|
2022-06-01 06:51:35 +00:00
|
|
|
|
'import/core-modules': ['jquery'],
|
|
|
|
|
'import/resolver': { node: { extensions: ['.js', '.ts', '.tsx'] } },
|
2020-10-20 23:51:09 +00:00
|
|
|
|
},
|
2022-02-04 11:57:55 +00:00
|
|
|
|
overrides: [
|
2022-05-20 15:08:13 +00:00
|
|
|
|
// Legacy Code - remove from `files` when adopting desired rules in new code progressively
|
|
|
|
|
{
|
|
|
|
|
files: [
|
2022-09-20 10:32:54 +00:00
|
|
|
|
'client/src/entrypoints/admin/comments.js',
|
|
|
|
|
'client/src/entrypoints/admin/core.js',
|
|
|
|
|
'client/src/entrypoints/admin/expanding-formset.js',
|
|
|
|
|
'client/src/entrypoints/admin/filtered-select.js',
|
|
|
|
|
'client/src/entrypoints/admin/page-chooser.js',
|
|
|
|
|
'client/src/entrypoints/admin/page-editor.js',
|
|
|
|
|
'client/src/entrypoints/admin/telepath/widgets.js',
|
|
|
|
|
'client/src/entrypoints/contrib/table_block/table.js',
|
|
|
|
|
'client/src/entrypoints/contrib/typed_table_block/typed_table_block.js',
|
|
|
|
|
'client/src/entrypoints/images/image-chooser-modal.js',
|
|
|
|
|
'client/src/utils/actions.ts',
|
|
|
|
|
'client/src/utils/version.js',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
],
|
|
|
|
|
rules: legacyCode,
|
|
|
|
|
},
|
2022-06-23 12:14:04 +00:00
|
|
|
|
// Rules that we are ignoring currently due to legacy code in React components only
|
|
|
|
|
{
|
|
|
|
|
files: ['client/src/components/**'],
|
|
|
|
|
rules: {
|
|
|
|
|
...legacyCode,
|
|
|
|
|
'jsx-a11y/click-events-have-key-events': 'off',
|
|
|
|
|
'jsx-a11y/interactive-supports-focus': 'off',
|
|
|
|
|
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
|
|
|
|
'jsx-a11y/role-supports-aria-props': 'off',
|
|
|
|
|
'react-hooks/exhaustive-deps': 'off',
|
|
|
|
|
'react-hooks/rules-of-hooks': 'off',
|
|
|
|
|
'react/button-has-type': 'off',
|
|
|
|
|
'react/destructuring-assignment': 'off',
|
|
|
|
|
'react/forbid-prop-types': 'off',
|
|
|
|
|
'react/function-component-definition': 'off',
|
|
|
|
|
'react/jsx-props-no-spreading': 'off',
|
|
|
|
|
'react/no-danger': 'off',
|
|
|
|
|
'react/no-deprecated': 'off',
|
|
|
|
|
'react/require-default-props': 'off',
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-06-01 06:51:35 +00:00
|
|
|
|
// Rules we don’t want to enforce for test and tooling code.
|
2020-10-20 23:51:09 +00:00
|
|
|
|
{
|
2022-02-18 16:07:09 +00:00
|
|
|
|
files: [
|
2022-05-20 15:08:13 +00:00
|
|
|
|
'client/extract-translatable-strings.js',
|
|
|
|
|
'client/tests/**',
|
|
|
|
|
'webpack.config.js',
|
|
|
|
|
'tailwind.config.js',
|
|
|
|
|
'storybook/**/*',
|
2022-02-18 16:07:09 +00:00
|
|
|
|
'*.test.ts',
|
|
|
|
|
'*.test.tsx',
|
|
|
|
|
'*.test.js',
|
|
|
|
|
'*.stories.js',
|
|
|
|
|
'*.stories.tsx',
|
|
|
|
|
],
|
2022-02-04 11:57:55 +00:00
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2022-06-01 08:53:05 +00:00
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
2022-02-04 11:57:55 +00:00
|
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
2022-06-01 08:53:05 +00:00
|
|
|
|
'global-require': 'off',
|
2022-06-23 11:21:33 +00:00
|
|
|
|
'import/first': 'off',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
'import/no-extraneous-dependencies': 'off',
|
2022-06-01 08:53:05 +00:00
|
|
|
|
'no-unused-expressions': 'off',
|
2022-05-20 15:08:13 +00:00
|
|
|
|
'react/function-component-definition': 'off',
|
|
|
|
|
'react/jsx-props-no-spreading': 'off',
|
2022-02-04 11:57:55 +00:00
|
|
|
|
},
|
2021-09-23 12:39:38 +00:00
|
|
|
|
},
|
2022-06-01 06:51:35 +00:00
|
|
|
|
// Files that use jquery via a global
|
2021-09-23 12:39:38 +00:00
|
|
|
|
{
|
2022-06-01 06:51:35 +00:00
|
|
|
|
files: [
|
|
|
|
|
'docs/_static/**',
|
|
|
|
|
'wagtail/contrib/modeladmin/static_src/wagtailmodeladmin/js/prepopulate.js',
|
2022-10-27 22:26:12 +00:00
|
|
|
|
'wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js',
|
2022-06-01 06:51:35 +00:00
|
|
|
|
'wagtail/contrib/settings/static_src/wagtailsettings/js/site-switcher.js',
|
|
|
|
|
'wagtail/documents/static_src/wagtaildocs/js/add-multiple.js',
|
|
|
|
|
'wagtail/embeds/static_src/wagtailembeds/js/embed-chooser-modal.js',
|
|
|
|
|
'wagtail/images/static_src/wagtailimages/js/add-multiple.js',
|
|
|
|
|
'wagtail/images/static_src/wagtailimages/js/focal-point-chooser.js',
|
|
|
|
|
'wagtail/images/static_src/wagtailimages/js/image-url-generator.js',
|
|
|
|
|
'wagtail/search/static_src/wagtailsearch/js/query-chooser-modal.js',
|
|
|
|
|
'wagtail/search/templates/wagtailsearch/queries/chooser_field.js',
|
|
|
|
|
'wagtail/snippets/static_src/wagtailsnippets/js/snippet-multiple-select.js',
|
|
|
|
|
'wagtail/users/static_src/wagtailusers/js/group-form.js',
|
|
|
|
|
],
|
|
|
|
|
globals: { $: 'readonly', jQuery: 'readonly' },
|
2021-09-23 12:39:38 +00:00
|
|
|
|
},
|
2022-06-01 06:51:35 +00:00
|
|
|
|
// Files that use other globals or legacy/vendor code that is unable to be easily linted
|
2021-09-23 12:39:38 +00:00
|
|
|
|
{
|
2022-05-12 13:10:59 +00:00
|
|
|
|
files: ['wagtail/**/**'],
|
2022-02-04 11:57:55 +00:00
|
|
|
|
globals: {
|
|
|
|
|
addMessage: 'readonly',
|
|
|
|
|
buildExpandingFormset: 'readonly',
|
|
|
|
|
cancelSpinner: 'readonly',
|
|
|
|
|
escapeHtml: 'readonly',
|
|
|
|
|
jsonData: 'readonly',
|
|
|
|
|
ModalWorkflow: 'readonly',
|
|
|
|
|
DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
|
|
|
|
|
EMBED_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
|
|
|
|
|
IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
|
|
|
|
|
QUERY_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
|
|
|
|
|
SNIPPET_CHOOSER_MODAL_ONLOAD_HANDLERS: 'writable',
|
2021-09-23 12:39:38 +00:00
|
|
|
|
},
|
2022-02-04 11:57:55 +00:00
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
|
|
|
'@typescript-eslint/no-use-before-define': 'off',
|
|
|
|
|
'camelcase': [
|
|
|
|
|
'error',
|
2021-09-23 12:39:38 +00:00
|
|
|
|
{
|
2022-02-04 11:57:55 +00:00
|
|
|
|
allow: [
|
|
|
|
|
'__unused_webpack_module',
|
|
|
|
|
'__webpack_modules__',
|
|
|
|
|
'__webpack_require__',
|
2021-09-23 12:39:38 +00:00
|
|
|
|
],
|
2022-02-04 11:57:55 +00:00
|
|
|
|
properties: 'never',
|
|
|
|
|
},
|
2021-09-23 12:39:38 +00:00
|
|
|
|
],
|
2022-02-04 11:57:55 +00:00
|
|
|
|
'consistent-return': 'off',
|
|
|
|
|
'func-names': 'off',
|
|
|
|
|
'id-length': 'off',
|
|
|
|
|
'indent': 'off',
|
|
|
|
|
'key-spacing': 'off',
|
|
|
|
|
'new-cap': 'off',
|
|
|
|
|
'newline-per-chained-call': 'off',
|
|
|
|
|
'no-param-reassign': 'off',
|
|
|
|
|
'no-underscore-dangle': 'off',
|
|
|
|
|
'object-shorthand': 'off',
|
|
|
|
|
'prefer-arrow-callback': 'off',
|
|
|
|
|
'quote-props': 'off',
|
|
|
|
|
'space-before-function-paren': 'off',
|
|
|
|
|
'vars-on-top': 'off',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|