2019-07-29 12:55:39 +02:00
|
|
|
module.exports = {
|
2020-12-28 13:48:47 +02:00
|
|
|
'root': true,
|
2019-07-29 12:55:39 +02:00
|
|
|
'env': {
|
|
|
|
'browser': true,
|
|
|
|
'es6': true,
|
|
|
|
'node': true,
|
|
|
|
},
|
2020-08-05 00:00:11 +02:00
|
|
|
'parser': '@typescript-eslint/parser',
|
2019-07-30 09:35:42 +02:00
|
|
|
'extends': ['eslint:recommended'],
|
2020-08-05 00:00:11 +02:00
|
|
|
'settings': {
|
2020-01-29 20:03:55 +02:00
|
|
|
'react': {
|
|
|
|
'version': '16.12',
|
|
|
|
},
|
|
|
|
},
|
2019-07-29 12:55:39 +02:00
|
|
|
'globals': {
|
|
|
|
'Atomics': 'readonly',
|
2019-07-30 09:35:42 +02:00
|
|
|
'SharedArrayBuffer': 'readonly',
|
2024-08-02 15:51:49 +02:00
|
|
|
'BufferEncoding': 'readonly',
|
|
|
|
'AsyncIterable': 'readonly',
|
|
|
|
'FileSystemFileHandle': 'readonly',
|
|
|
|
'FileSystemDirectoryHandle': 'readonly',
|
|
|
|
'ReadableStreamDefaultReader': 'readonly',
|
|
|
|
'FileSystemCreateWritableOptions': 'readonly',
|
|
|
|
'FileSystemHandle': 'readonly',
|
2024-08-09 12:29:39 +02:00
|
|
|
'IDBTransactionMode': 'readonly',
|
2024-08-02 15:51:49 +02:00
|
|
|
|
|
|
|
// ServiceWorker
|
|
|
|
'ExtendableEvent': 'readonly',
|
|
|
|
'WindowClient': 'readonly',
|
|
|
|
'FetchEvent': 'readonly',
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2020-11-19 14:44:20 +02:00
|
|
|
// Jest variables
|
|
|
|
'test': 'readonly',
|
2019-07-30 09:35:42 +02:00
|
|
|
'expect': 'readonly',
|
|
|
|
'describe': 'readonly',
|
|
|
|
'it': 'readonly',
|
2020-02-22 13:25:16 +02:00
|
|
|
'beforeAll': 'readonly',
|
|
|
|
'afterAll': 'readonly',
|
2019-07-30 09:35:42 +02:00
|
|
|
'beforeEach': 'readonly',
|
2020-02-22 13:25:16 +02:00
|
|
|
'afterEach': 'readonly',
|
2020-12-01 20:05:24 +02:00
|
|
|
'jest': 'readonly',
|
2020-11-13 19:09:28 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
// React Native variables
|
|
|
|
'__DEV__': 'readonly',
|
|
|
|
|
|
|
|
// Clipper variables
|
|
|
|
'browserSupportsPromises_': true,
|
|
|
|
'chrome': 'readonly',
|
|
|
|
'browser': 'readonly',
|
2020-03-10 01:24:57 +02:00
|
|
|
|
2020-12-28 13:48:47 +02:00
|
|
|
// Server admin UI global variables
|
|
|
|
'onDocumentReady': 'readonly',
|
2021-07-11 16:04:01 +02:00
|
|
|
'setupPasswordStrengthHandler': 'readonly',
|
|
|
|
'$': 'readonly',
|
|
|
|
'zxcvbn': 'readonly',
|
2020-12-28 13:48:47 +02:00
|
|
|
|
2020-03-10 01:24:57 +02:00
|
|
|
'tinymce': 'readonly',
|
2023-07-06 20:18:43 +02:00
|
|
|
|
|
|
|
'JSX': 'readonly',
|
2019-07-29 12:55:39 +02:00
|
|
|
},
|
|
|
|
'parserOptions': {
|
|
|
|
'ecmaVersion': 2018,
|
2020-08-05 00:00:11 +02:00
|
|
|
'ecmaFeatures': {
|
|
|
|
'jsx': true,
|
|
|
|
},
|
|
|
|
'sourceType': 'module',
|
2019-07-29 12:55:39 +02:00
|
|
|
},
|
|
|
|
'rules': {
|
2019-09-30 00:01:10 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Code correctness
|
|
|
|
// -------------------------------
|
2020-08-05 00:00:11 +02:00
|
|
|
'react/jsx-uses-react': 'error',
|
|
|
|
'react/jsx-uses-vars': 'error',
|
2020-10-09 19:35:46 +02:00
|
|
|
'no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
|
|
|
|
'@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
|
|
|
|
'@typescript-eslint/explicit-member-accessibility': 'off',
|
2020-08-05 00:00:11 +02:00
|
|
|
'no-constant-condition': 0,
|
|
|
|
'no-prototype-builtins': 0,
|
2019-09-30 00:01:10 +02:00
|
|
|
// This error is always a false positive so far since it detects
|
|
|
|
// possible race conditions in contexts where we know it cannot happen.
|
2020-08-05 00:00:11 +02:00
|
|
|
'require-atomic-updates': 0,
|
|
|
|
'prefer-const': ['error'],
|
|
|
|
'no-var': ['error'],
|
|
|
|
'no-new-func': ['error'],
|
|
|
|
'import/prefer-default-export': ['error'],
|
2024-04-25 14:32:37 +02:00
|
|
|
'prefer-promise-reject-errors': ['error', {
|
|
|
|
allowEmptyReject: true,
|
|
|
|
}],
|
|
|
|
'no-throw-literal': ['error'],
|
2020-12-30 13:51:43 +02:00
|
|
|
|
|
|
|
// This rule should not be enabled since it matters in what order
|
|
|
|
// imports are done, in particular in relation to the shim.setReact
|
|
|
|
// call, which should be done first, but this rule might move it down.
|
|
|
|
// 'import/first': ['error'],
|
|
|
|
|
2020-08-05 00:00:11 +02:00
|
|
|
'no-array-constructor': ['error'],
|
|
|
|
'radix': ['error'],
|
2022-07-23 09:31:32 +02:00
|
|
|
'eqeqeq': ['error', 'always'],
|
2023-02-16 12:55:24 +02:00
|
|
|
'no-console': ['error', { 'allow': ['warn', 'error'] }],
|
2020-01-29 19:54:25 +02:00
|
|
|
|
2020-08-06 01:16:51 +02:00
|
|
|
// Warn only for now because fixing everything would take too much
|
|
|
|
// refactoring, but new code should try to stick to it.
|
2021-05-16 15:21:55 +02:00
|
|
|
// 'complexity': ['warn', { max: 10 }],
|
2020-08-06 01:16:51 +02:00
|
|
|
|
2020-02-27 02:20:55 +02:00
|
|
|
// Checks rules of Hooks
|
2022-08-19 13:10:04 +02:00
|
|
|
'@seiyab/react-hooks/rules-of-hooks': 'error',
|
|
|
|
'@seiyab/react-hooks/exhaustive-deps': ['error', { 'ignoreThisDependency': 'props' }],
|
|
|
|
|
2020-02-27 02:20:55 +02:00
|
|
|
// Checks effect dependencies
|
2020-03-14 01:46:14 +02:00
|
|
|
// Disable because of this: https://github.com/facebook/react/issues/16265
|
|
|
|
// "react-hooks/exhaustive-deps": "warn",
|
2020-02-27 02:20:55 +02:00
|
|
|
|
2023-03-08 21:08:05 +02:00
|
|
|
'jest/require-top-level-describe': ['error', { 'maxNumberOfTopLevelDescribes': 1 }],
|
2023-03-08 21:23:49 +02:00
|
|
|
'jest/no-identical-title': ['error'],
|
|
|
|
'jest/prefer-lowercase-title': ['error', { 'ignoreTopLevelDescribe': true }],
|
2023-03-08 21:08:05 +02:00
|
|
|
|
2022-09-30 18:23:14 +02:00
|
|
|
'promise/prefer-await-to-then': 'error',
|
2023-02-21 19:10:53 +02:00
|
|
|
'no-unneeded-ternary': 'error',
|
2023-06-30 10:39:21 +02:00
|
|
|
'github/array-foreach': ['error'],
|
2022-09-30 18:23:14 +02:00
|
|
|
|
2024-04-01 16:34:22 +02:00
|
|
|
'no-restricted-properties': ['error',
|
|
|
|
{
|
|
|
|
'property': 'focus',
|
|
|
|
'message': 'Please use focusHandler::focus() instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'property': 'blur',
|
|
|
|
'message': 'Please use focusHandler::blur() instead',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
'@typescript-eslint/no-explicit-any': ['error'],
|
|
|
|
|
2019-09-30 00:01:10 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Formatting
|
|
|
|
// -------------------------------
|
2020-08-05 00:00:11 +02:00
|
|
|
'space-in-parens': ['error', 'never'],
|
|
|
|
'space-infix-ops': ['error'],
|
|
|
|
'curly': ['error', 'multi-line', 'consistent'],
|
|
|
|
'semi': ['error', 'always'],
|
|
|
|
'eol-last': ['error', 'always'],
|
|
|
|
'quotes': ['error', 'single'],
|
2023-07-06 20:17:41 +02:00
|
|
|
|
|
|
|
// Note that "indent" only applies to JavaScript files. See
|
|
|
|
// https://github.com/laurent22/joplin/issues/8360
|
2020-08-05 00:00:11 +02:00
|
|
|
'indent': ['error', 'tab'],
|
|
|
|
'comma-dangle': ['error', {
|
|
|
|
'arrays': 'always-multiline',
|
|
|
|
'objects': 'always-multiline',
|
|
|
|
'imports': 'always-multiline',
|
|
|
|
'exports': 'always-multiline',
|
2023-08-22 12:58:53 +02:00
|
|
|
'functions': 'always-multiline',
|
2020-08-05 00:00:11 +02:00
|
|
|
}],
|
2023-01-11 20:37:22 +02:00
|
|
|
'comma-spacing': ['error', { 'before': false, 'after': true }],
|
2020-08-05 00:00:11 +02:00
|
|
|
'no-trailing-spaces': 'error',
|
|
|
|
'linebreak-style': ['error', 'unix'],
|
|
|
|
'prefer-template': ['error'],
|
|
|
|
'template-curly-spacing': ['error', 'never'],
|
|
|
|
'object-curly-spacing': ['error', 'always'],
|
|
|
|
'array-bracket-spacing': ['error', 'never'],
|
|
|
|
'key-spacing': ['error', {
|
|
|
|
'beforeColon': false,
|
|
|
|
'afterColon': true,
|
|
|
|
'mode': 'strict',
|
2019-09-30 00:01:10 +02:00
|
|
|
}],
|
2020-08-05 00:00:11 +02:00
|
|
|
'block-spacing': ['error'],
|
|
|
|
'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
|
|
|
|
'no-spaced-func': ['error'],
|
|
|
|
'func-call-spacing': ['error'],
|
|
|
|
'space-before-function-paren': ['error', {
|
|
|
|
'anonymous': 'never',
|
|
|
|
'named': 'never',
|
|
|
|
'asyncArrow': 'always',
|
2019-10-09 21:24:07 +02:00
|
|
|
}],
|
2023-06-30 10:55:56 +02:00
|
|
|
'multiline-comment-style': ['error', 'separate-lines', { checkJSDoc: true }],
|
2020-08-05 00:00:11 +02:00
|
|
|
'space-before-blocks': 'error',
|
|
|
|
'spaced-comment': ['error', 'always'],
|
|
|
|
'keyword-spacing': ['error', { 'before': true, 'after': true }],
|
2021-01-23 17:51:19 +02:00
|
|
|
'no-multi-spaces': ['error'],
|
2023-06-01 13:02:36 +02:00
|
|
|
'prefer-object-spread': ['error'],
|
2023-07-03 18:11:12 +02:00
|
|
|
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
|
2023-02-16 12:55:24 +02:00
|
|
|
|
|
|
|
// Regarding the keyword blacklist:
|
|
|
|
// - err: We generally avoid using too many abbreviations, so it should
|
|
|
|
// be "error", not "err"
|
|
|
|
// - notebook: In code, it should always be "folder" (not "notebook").
|
|
|
|
// In user-facing text, it should be "notebook".
|
|
|
|
'id-denylist': ['error', 'err', 'notebook', 'notebooks'],
|
2023-02-20 17:02:29 +02:00
|
|
|
'prefer-arrow-callback': ['error'],
|
2023-11-15 22:18:31 +02:00
|
|
|
|
|
|
|
'no-constant-binary-expression': ['error'],
|
2019-07-29 12:55:39 +02:00
|
|
|
},
|
2020-08-05 00:00:11 +02:00
|
|
|
'plugins': [
|
|
|
|
'react',
|
|
|
|
'@typescript-eslint',
|
2022-08-19 13:10:04 +02:00
|
|
|
// Need to use a fork of the official rules of hooks because of this bug:
|
|
|
|
// https://github.com/facebook/react/issues/16265
|
|
|
|
'@seiyab/eslint-plugin-react-hooks',
|
|
|
|
// 'react-hooks',
|
2020-08-05 00:00:11 +02:00
|
|
|
'import',
|
2022-09-30 18:23:14 +02:00
|
|
|
'promise',
|
2023-03-08 21:08:05 +02:00
|
|
|
'jest',
|
2023-06-30 10:39:21 +02:00
|
|
|
'github',
|
2019-07-29 12:55:39 +02:00
|
|
|
],
|
2020-10-09 19:35:46 +02:00
|
|
|
'overrides': [
|
2023-02-16 12:55:24 +02:00
|
|
|
{
|
|
|
|
'files': [
|
|
|
|
'packages/tools/**',
|
|
|
|
'packages/app-mobile/tools/**',
|
|
|
|
'packages/app-desktop/tools/**',
|
|
|
|
],
|
|
|
|
'rules': {
|
|
|
|
'no-console': 'off',
|
|
|
|
},
|
|
|
|
},
|
2020-10-09 19:35:46 +02:00
|
|
|
{
|
|
|
|
// enable the rule specifically for TypeScript files
|
|
|
|
'files': ['*.ts', '*.tsx'],
|
2020-11-25 16:40:25 +02:00
|
|
|
'parserOptions': {
|
|
|
|
// Required for @typescript-eslint/no-floating-promises
|
|
|
|
'project': './tsconfig.eslint.json',
|
|
|
|
},
|
2020-10-09 19:35:46 +02:00
|
|
|
'rules': {
|
2023-07-06 20:17:41 +02:00
|
|
|
'@typescript-eslint/indent': ['error', 'tab', {
|
|
|
|
'ignoredNodes': [
|
|
|
|
// See https://github.com/typescript-eslint/typescript-eslint/issues/1824
|
|
|
|
'TSUnionType',
|
|
|
|
],
|
|
|
|
}],
|
2023-06-30 11:22:47 +02:00
|
|
|
'@typescript-eslint/ban-ts-comment': ['error'],
|
2023-06-30 11:30:29 +02:00
|
|
|
'@typescript-eslint/ban-types': 'error',
|
2023-03-06 16:22:01 +02:00
|
|
|
'@typescript-eslint/explicit-member-accessibility': ['error'],
|
2020-11-12 21:23:54 +02:00
|
|
|
'@typescript-eslint/type-annotation-spacing': ['error', { 'before': false, 'after': true }],
|
2023-06-30 10:16:08 +02:00
|
|
|
'@typescript-eslint/array-type': 'error',
|
2023-06-30 10:11:26 +02:00
|
|
|
'@typescript-eslint/no-inferrable-types': ['error'],
|
2020-11-12 21:23:54 +02:00
|
|
|
'@typescript-eslint/comma-dangle': ['error', {
|
|
|
|
'arrays': 'always-multiline',
|
|
|
|
'objects': 'always-multiline',
|
|
|
|
'imports': 'always-multiline',
|
|
|
|
'exports': 'always-multiline',
|
|
|
|
'enums': 'always-multiline',
|
|
|
|
'generics': 'always-multiline',
|
|
|
|
'tuples': 'always-multiline',
|
2023-08-22 12:58:53 +02:00
|
|
|
'functions': 'always-multiline',
|
2020-11-12 21:23:54 +02:00
|
|
|
}],
|
2023-02-16 11:23:19 +02:00
|
|
|
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
|
2020-11-12 21:29:22 +02:00
|
|
|
'@typescript-eslint/semi': ['error', 'always'],
|
|
|
|
'@typescript-eslint/member-delimiter-style': ['error', {
|
|
|
|
'multiline': {
|
|
|
|
'delimiter': 'semi',
|
|
|
|
'requireLast': true,
|
|
|
|
},
|
|
|
|
'singleline': {
|
|
|
|
'delimiter': 'semi',
|
|
|
|
'requireLast': false,
|
|
|
|
},
|
|
|
|
}],
|
2020-11-25 16:40:25 +02:00
|
|
|
'@typescript-eslint/no-floating-promises': ['error'],
|
2021-08-18 17:21:48 +02:00
|
|
|
'@typescript-eslint/naming-convention': ['error',
|
|
|
|
// Naming conventions over the codebase is very inconsistent
|
|
|
|
// unfortunately and fixing it would be way too much work.
|
|
|
|
// In general, we use "strictCamelCase" for variable names.
|
|
|
|
|
|
|
|
// {
|
|
|
|
// selector: 'default',
|
|
|
|
// format: ['StrictPascalCase', 'strictCamelCase', 'snake_case', 'UPPER_CASE'],
|
|
|
|
// leadingUnderscore: 'allow',
|
|
|
|
// trailingUnderscore: 'allow',
|
|
|
|
// },
|
2021-10-03 17:00:49 +02:00
|
|
|
|
|
|
|
// Each rule below is made of two blocks: first the rule we
|
|
|
|
// actually want, and below exceptions to the rule.
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// ENUM
|
|
|
|
// -----------------------------------
|
|
|
|
|
2021-08-18 17:21:48 +02:00
|
|
|
{
|
|
|
|
selector: 'enumMember',
|
|
|
|
format: ['StrictPascalCase'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'enumMember',
|
|
|
|
format: null,
|
|
|
|
'filter': {
|
2024-02-20 00:50:10 +02:00
|
|
|
'regex': '^(GET|POST|PUT|DELETE|PATCH|HEAD|SQLite|PostgreSQL|ASC|DESC|E2EE|OR|AND|UNION|INTERSECT|EXCLUSION|INCLUSION|EUR|GBP|USD|SJCL.*|iOS)$',
|
2021-08-18 17:21:48 +02:00
|
|
|
'match': true,
|
|
|
|
},
|
|
|
|
},
|
2024-10-26 22:15:10 +02:00
|
|
|
{
|
|
|
|
selector: 'enumMember',
|
|
|
|
format: null,
|
|
|
|
'filter': {
|
|
|
|
'regex': '^(sha1|sha256|sha384|sha512|AES_128_GCM|AES_192_GCM|AES_256_GCM)$',
|
|
|
|
'match': true,
|
|
|
|
},
|
|
|
|
},
|
2021-10-03 17:00:49 +02:00
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// INTERFACE
|
|
|
|
// -----------------------------------
|
|
|
|
|
2021-08-18 17:21:48 +02:00
|
|
|
{
|
|
|
|
selector: 'interface',
|
|
|
|
format: ['StrictPascalCase'],
|
|
|
|
},
|
2021-10-03 17:00:49 +02:00
|
|
|
{
|
|
|
|
selector: 'interface',
|
|
|
|
format: null,
|
|
|
|
'filter': {
|
|
|
|
'regex': '^(RSA|RSAKeyPair)$',
|
|
|
|
'match': true,
|
|
|
|
},
|
|
|
|
},
|
2021-08-18 17:21:48 +02:00
|
|
|
],
|
2020-10-09 19:35:46 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-02-22 13:25:16 +02:00
|
|
|
};
|