2021-12-23 04:18:04 +01:00
|
|
|
|
module.exports = {
|
|
|
|
|
extends: [
|
|
|
|
|
'@wagtail/eslint-config-wagtail',
|
|
|
|
|
'plugin:@typescript-eslint/recommended',
|
|
|
|
|
],
|
2021-03-05 17:54:11 +01:00
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
|
plugins: ['@typescript-eslint'],
|
2016-06-17 15:48:33 +02:00
|
|
|
|
env: {
|
2021-12-23 04:18:04 +01:00
|
|
|
|
jest: true,
|
|
|
|
|
browser: true,
|
2019-04-23 16:02:53 +02:00
|
|
|
|
},
|
|
|
|
|
rules: {
|
2021-03-05 17:54:11 +01:00
|
|
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
2022-05-20 17:08:13 +02:00
|
|
|
|
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2021-12-23 04:18:04 +01:00
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
2022-05-20 17:08:13 +02:00
|
|
|
|
'@typescript-eslint/no-use-before-define': ['error'],
|
2022-12-09 08:33:28 +01:00
|
|
|
|
// it is often helpful to pull out logic to class methods that may not use `this`
|
|
|
|
|
'class-methods-use-this': 'off',
|
2021-12-23 04:18:04 +01:00
|
|
|
|
'import/extensions': [
|
|
|
|
|
'error',
|
|
|
|
|
'always',
|
|
|
|
|
{
|
|
|
|
|
ignorePackages: true,
|
|
|
|
|
pattern: {
|
|
|
|
|
js: 'never',
|
|
|
|
|
jsx: 'never',
|
|
|
|
|
ts: 'never',
|
|
|
|
|
tsx: 'never',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-05-31 23:47:50 +02: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 12:58:56 +02:00
|
|
|
|
// allow no lines between single line members (e.g. static declarations)
|
|
|
|
|
'lines-between-class-members': [
|
|
|
|
|
'error',
|
|
|
|
|
'always',
|
|
|
|
|
{ exceptAfterSingleLine: true },
|
|
|
|
|
],
|
2022-12-09 08:14:49 +01:00
|
|
|
|
'max-classes-per-file': 'off',
|
2022-05-20 17:08:13 +02: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 12:32:33 +02:00
|
|
|
|
// this rule can be confusing as it forces some non-intuitive code for variable assignment
|
|
|
|
|
'prefer-destructuring': 'off',
|
2022-05-20 17:08:13 +02:00
|
|
|
|
},
|
|
|
|
|
settings: {
|
2022-06-01 08:51:35 +02:00
|
|
|
|
'import/core-modules': ['jquery'],
|
|
|
|
|
'import/resolver': { node: { extensions: ['.js', '.ts', '.tsx'] } },
|
2020-10-21 01:51:09 +02:00
|
|
|
|
},
|
|
|
|
|
overrides: [
|
2022-06-23 14:14:04 +02:00
|
|
|
|
// Rules that we are ignoring currently due to legacy code in React components only
|
|
|
|
|
{
|
|
|
|
|
files: ['client/src/components/**'],
|
|
|
|
|
rules: {
|
|
|
|
|
'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',
|
2022-12-17 15:32:55 +01:00
|
|
|
|
'no-restricted-syntax': 'off',
|
2022-06-23 14:14:04 +02:00
|
|
|
|
'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-08-23 12:43:35 +02:00
|
|
|
|
// Rules we want to enforce or change for Stimulus Controllers
|
|
|
|
|
{
|
|
|
|
|
files: ['*Controller.ts'],
|
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/member-ordering': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
classes: {
|
|
|
|
|
memberTypes: ['signature', 'field', 'method'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'@typescript-eslint/naming-convention': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
selector: 'method',
|
|
|
|
|
format: ['camelCase'],
|
|
|
|
|
custom: {
|
|
|
|
|
// Use connect or initialize instead of constructor, avoid generic 'render' or 'update' methods and instead be more specific.
|
|
|
|
|
regex: '^(constructor|render|update)$',
|
|
|
|
|
match: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
selector: 'property',
|
|
|
|
|
format: ['camelCase'],
|
|
|
|
|
custom: {
|
|
|
|
|
// Use Stimulus values where possible for internal state, avoid a generic state object as these are not reactive.
|
|
|
|
|
regex: '^(state)$',
|
|
|
|
|
match: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'no-restricted-properties': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
object: 'window',
|
|
|
|
|
property: 'Stimulus',
|
|
|
|
|
message:
|
|
|
|
|
"Please import the base Controller or only access the Stimulus instance via the controller's `this.application` attribute.",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-06-01 08:51:35 +02:00
|
|
|
|
// Rules we don’t want to enforce for test and tooling code.
|
2020-10-21 01:51:09 +02:00
|
|
|
|
{
|
2022-02-18 17:07:09 +01:00
|
|
|
|
files: [
|
2022-05-20 17:08:13 +02:00
|
|
|
|
'client/extract-translatable-strings.js',
|
|
|
|
|
'client/tests/**',
|
|
|
|
|
'webpack.config.js',
|
|
|
|
|
'tailwind.config.js',
|
|
|
|
|
'storybook/**/*',
|
2022-02-18 17:07:09 +01:00
|
|
|
|
'*.test.ts',
|
|
|
|
|
'*.test.tsx',
|
|
|
|
|
'*.test.js',
|
|
|
|
|
'*.stories.js',
|
|
|
|
|
'*.stories.tsx',
|
|
|
|
|
],
|
2021-03-05 17:54:11 +01:00
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2022-06-01 10:53:05 +02:00
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
2021-03-05 17:54:11 +01:00
|
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
2022-06-01 10:53:05 +02:00
|
|
|
|
'global-require': 'off',
|
2022-06-23 13:21:33 +02:00
|
|
|
|
'import/first': 'off',
|
2022-05-20 17:08:13 +02:00
|
|
|
|
'import/no-extraneous-dependencies': 'off',
|
2022-06-01 10:53:05 +02:00
|
|
|
|
'no-unused-expressions': 'off',
|
2022-05-20 17:08:13 +02:00
|
|
|
|
'react/function-component-definition': 'off',
|
|
|
|
|
'react/jsx-props-no-spreading': 'off',
|
2021-03-05 17:54:11 +01:00
|
|
|
|
},
|
2021-09-23 14:39:38 +02:00
|
|
|
|
},
|
2022-06-01 08:51:35 +02:00
|
|
|
|
// Files that use jquery via a global
|
2021-09-23 14:39:38 +02:00
|
|
|
|
{
|
2022-06-01 08:51:35 +02:00
|
|
|
|
files: [
|
|
|
|
|
'docs/_static/**',
|
|
|
|
|
'wagtail/contrib/modeladmin/static_src/wagtailmodeladmin/js/prepopulate.js',
|
2022-10-28 00:26:12 +02:00
|
|
|
|
'wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js',
|
2022-06-01 08:51:35 +02:00
|
|
|
|
'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 14:39:38 +02:00
|
|
|
|
},
|
2022-06-01 08:51:35 +02:00
|
|
|
|
// Files that use other globals or legacy/vendor code that is unable to be easily linted
|
2021-09-23 14:39:38 +02:00
|
|
|
|
{
|
2022-05-12 15:10:59 +02:00
|
|
|
|
files: ['wagtail/**/**'],
|
2021-09-23 14:39:38 +02:00
|
|
|
|
globals: {
|
|
|
|
|
buildExpandingFormset: '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',
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
|
|
|
'@typescript-eslint/no-use-before-define': 'off',
|
|
|
|
|
'camelcase': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
allow: [
|
|
|
|
|
'__unused_webpack_module',
|
|
|
|
|
'__webpack_modules__',
|
|
|
|
|
'__webpack_require__',
|
|
|
|
|
],
|
|
|
|
|
properties: 'never',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'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',
|
|
|
|
|
},
|
2020-10-21 01:51:09 +02:00
|
|
|
|
},
|
|
|
|
|
],
|
2016-02-24 11:44:14 +01:00
|
|
|
|
};
|