From f98f26b62888715de79d19a7be6287620bb481b5 Mon Sep 17 00:00:00 2001 From: Derek Croote Date: Thu, 18 Jul 2024 08:37:47 -0700 Subject: [PATCH] feat: add common exclusions (#20) --- src/jest.js | 8 ++------ src/universal.js | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/jest.js b/src/jest.js index 65864fd..8f9c17d 100644 --- a/src/jest.js +++ b/src/jest.js @@ -19,15 +19,11 @@ module.exports = { extends: ['plugin:jest/recommended', 'plugin:jest-formatting/recommended'], rules: { 'jest/max-expects': 'off', // Limiting expect statements is beneficial, but enforcing a strict count can be restrictive. - 'jest/no-hooks': [ - 'error', // We advocate for setup functions over beforeXXX hooks. However, afterXyz hooks are sometimes indispensable, like for resetting Jest timers. See: https://kentcdodds.com/blog/avoid-nesting-when-youre-testing#inline-it. - { - allow: ['afterEach', 'afterAll'], - }, - ], + 'jest/no-hooks': 'off', // Would be time consuming to implement in existing repos. 'jest/prefer-each': 'off', // We find traditional for-loops more readable in certain contexts. 'jest/prefer-expect-assertions': 'off', // While useful, enforcing this can lead to verbose tests. 'jest/prefer-importing-jest-globals': 'off', // This would be very bothersome for existing repos. + 'jest/prefer-todo': 'off', 'jest/require-top-level-describe': 'off', // Multiple top-level describe blocks or tests can be acceptable. 'jest/valid-title': 'off', // This restriction can prevent using titles like ".name". 'prefer-lowercase-title': 'off', // Sometimes we want to start the test with a capital letter and some words are all uppercase (e.g. AWS)., diff --git a/src/universal.js b/src/universal.js index f70f439..ffc9247 100644 --- a/src/universal.js +++ b/src/universal.js @@ -101,9 +101,11 @@ module.exports = { 'unicorn/no-nested-ternary': 'off', // This rule is smarter than the standard ESLint rule, but conflicts with prettier so it needs to be turned off. Nested ternaries are very unreadable so it's OK if all of them are flagged. 'unicorn/no-null': 'off', // We use both null and undefined for representing three state objects. We could use a string union instead, but using combination of null and undefined is less verbose. 'unicorn/no-object-as-default-parameter': 'off', // Too restrictive. TypeScript can ensure that the default value matches the type. + 'unicorn/no-process-exit': 'off', 'unicorn/no-useless-undefined': ['error', { checkArguments: false }], // We need to disable "checkArguments", because if a function expects a value of type "T | undefined" the undefined value needs to be passed explicitly. 'unicorn/prefer-module': 'off', // We use CJS for configuration files and tests. There is no rush to migrate to ESM and the configuration files are probably not yet ready for ESM yet. 'unicorn/prefer-string-raw': 'off', // We commonly escape \ in strings. + 'unicorn/prefer-top-level-await': 'off', 'unicorn/prevent-abbreviations': 'off', // This rule reports many false positives and leads to more verbose code. /* Rule overrides for "import" plugin */ @@ -129,11 +131,13 @@ module.exports = { fixStyle: 'inline-type-imports', }, ], + '@typescript-eslint/consistent-return': 'off', // Does not play with no useless undefined when function return type is "T | undefined" and does not have a fixer. '@typescript-eslint/explicit-function-return-type': 'off', // Prefer inferring types to explicit annotations. '@typescript-eslint/explicit-module-boundary-types': 'off', // We export lot of functions in order to test them. Typing them all is not a good idea. '@typescript-eslint/indent': 'off', // Conflicts with prettier. '@typescript-eslint/init-declarations': 'off', // Too restrictive, TS is able to infer if value is initialized or not. This pattern does not work with declaring a variable and then initializing it conditionally (or later). '@typescript-eslint/lines-around-comment': 'off', // Do not agree with this rule. + '@typescript-eslint/max-params': 'off', '@typescript-eslint/member-delimiter-style': 'off', // Conflicts with prettier. '@typescript-eslint/member-ordering': 'off', // Does not have a fixer. Also, sometimes it's beneficial to group related members together. '@typescript-eslint/naming-convention': 'off', @@ -143,6 +147,7 @@ module.exports = { ignoreArrowShorthand: true, // See: https://typescript-eslint.io/rules/no-confusing-void-expression/#ignorearrowshorthand. }, ], + '@typescript-eslint/no-dynamic-delete': 'off', '@typescript-eslint/no-empty-function': 'off', // Too restrictive, often false yields to more verbose code. '@typescript-eslint/no-explicit-any': 'off', // Using "any" is sometimes necessary. '@typescript-eslint/no-extra-parens': 'off', // Conflicts with prettier. @@ -168,6 +173,7 @@ module.exports = { '@typescript-eslint/no-unsafe-return': 'off', // Too restrictive, often false yields to more verbose code. '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', vars: 'all' }], '@typescript-eslint/no-use-before-define': 'off', // Too restrictive, does not have a fixer and is not important. + '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/object-curly-spacing': 'off', // Conflicts with prettier. '@typescript-eslint/prefer-nullish-coalescing': [ 'error', @@ -181,6 +187,7 @@ module.exports = { '@typescript-eslint/space-before-function-paren': 'off', // Conflicts with prettier. '@typescript-eslint/strict-boolean-expressions': 'off', // While the rule is reasonable, it is often convenient and intended to just check whether the value is not null or undefined. Enabling this rule would make the code more verbose. See: https://typescript-eslint.io/rules/strict-boolean-expressions/ '@typescript-eslint/unbound-method': 'off', // Reports issues for common patterns in tests (e.g. "expect(logger.warn)..."). Often the issue yields false positives. + '@typescript-eslint/use-unknown-in-catch-callback-variable': 'off', /* Rule overrides for "functional" plugin */ 'functional/no-classes': 'error', // Functions are all we need. @@ -191,7 +198,9 @@ module.exports = { /* Overrides for "lodash" plugin */ 'lodash/import-scope': ['error', 'member'], // We prefer member imports in node.js code. This is not recommended for FE projects, because lodash can't be tree shaken (written in CJS not ESM). This rule should be overridden for FE projects (and we do so in React ruleset). 'lodash/path-style': 'off', // Can potentially trigger TS errors. Both variants have use cases when they are more readable. + 'lodash/prefer-immutable-method': 'off', 'lodash/prefer-lodash-method': 'off', // Disagree with this rule. Using the native method is often simpler. + 'lodash/prop-shorthand': 'off', /* Rule overrides for other plugins and rules */ // This rule unfortunately does not detect deprecated properties. See: