UNPKG

@mikey-pro/eslint-config

Version:

Mikey Pro ESLint configuration - Ultimate coding style guide for excellence

624 lines (597 loc) 21.1 kB
// Modern ESLint rules for Mikey Pro // Ultimate coding style guide for excellence export const baseRules = { // === CORE ESLINT RULES === // Best Practices 'accessor-pairs': 'error', 'array-callback-return': 'error', 'block-scoped-var': 'error', // === BOUNDARIES RULES === 'boundaries/element-types': [ 'warn', { default: 'disallow', rules: [ { allow: ['utils'], from: 'utils' }, { allow: ['features', 'shared', 'utils'], from: 'features' }, { allow: ['shared', 'utils'], from: 'shared' }, ], }, ], 'class-methods-use-this': 'off', // Handled by TypeScript rules // === COMPAT RULES === 'compat/compat': 'warn', complexity: ['error', { max: 15 }], 'consistent-return': 'error', 'css-modules/no-undef-class': 'warn', // === CSS MODULES RULES === 'css-modules/no-unused-class': 'warn', curly: ['error', 'all'], 'default-case': 'error', 'default-case-last': 'error', 'default-param-last': 'error', 'dot-notation': 'warn', eqeqeq: ['error', 'always', { null: 'ignore' }], 'filenames/match-exported': 'off', // === FILENAMES RULES === 'filenames/match-regex': 'off', 'filenames/no-index': 'off', 'grouped-accessor-pairs': 'error', 'guard-for-in': 'error', // === IMPORT/EXPORT RULES === 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'], 'import/default': 'off', 'import/export': 'error', 'import/extensions': [ 'error', 'ignorePackages', { ts: 'never', tsx: 'never' }, ], 'import/first': 'error', 'import/named': 'off', 'import/namespace': 'off', 'import/newline-after-import': 'error', 'import/no-absolute-path': 'error', 'import/no-cycle': ['error', { ignoreExternal: true, maxDepth: 1 }], 'import/no-default-export': 'off', 'import/no-deprecated': 'warn', 'import/no-duplicates': ['error', { 'prefer-inline': true }], 'import/no-dynamic-require': 'error', 'import/no-empty-named-blocks': 'error', 'import/no-extraneous-dependencies': [ 'error', { devDependencies: ['**/*.test.{js,ts}', '**/*.spec.{js,ts}', '**/test/**'], }, ], 'import/no-import-module-exports': 'error', 'import/no-internal-modules': 'off', 'import/no-mutable-exports': 'error', 'import/no-named-as-default': 'off', 'import/no-named-as-default-member': 'off', 'import/no-named-default': 'error', 'import/no-namespace': 'error', 'import/no-nodejs-modules': 'off', 'import/no-relative-packages': 'error', 'import/no-relative-parent-imports': [ 'error', { ignore: ['@/components', '@/utils', '@/types'] }, ], 'import/no-restricted-paths': 'off', 'import/no-self-import': 'error', 'import/no-unassigned-import': 'off', 'import/no-unresolved': [ 'error', { amd: true, commonjs: true, ignore: ['^node:'] }, ], 'import/no-unused-modules': 'off', 'import/no-useless-path-segments': 'error', 'import/no-webpack-loader-syntax': 'error', 'import/order': [ 'error', { alphabetize: { order: 'asc' }, 'newlines-between': 'always', pathGroups: [ { group: 'builtin', pattern: 'node:*', position: 'before', }, { group: 'external', pattern: '@*', position: 'after', }, { group: 'internal', pattern: '@/**', position: 'after', }, ], pathGroupsExcludedImportTypes: ['builtin'], }, ], 'import/prefer-default-export': 'off', 'import/unambiguous': 'off', // === VARIABLES === 'init-declarations': 'off', // Handled by TypeScript rules // === JEST-DOM RULES === 'jest-dom/prefer-checked': 'error', 'jest-dom/prefer-enabled-disabled': 'error', 'jest-dom/prefer-focus': 'error', 'jest-dom/prefer-required': 'error', 'jest-dom/prefer-to-have-attribute': 'error', // === JEST RULES === 'jest/expect-expect': 'warn', 'jest/no-disabled-tests': 'warn', 'jest/no-focused-tests': 'error', 'jest/no-identical-title': 'error', 'jest/prefer-to-have-length': 'warn', 'jest/valid-expect': 'error', 'max-classes-per-file': ['error', 1], 'max-depth': ['error', 4], 'max-lines': [ 'error', { max: 500, skipBlankLines: true, skipComments: true }, ], 'max-lines-per-function': [ 'error', { max: 50, skipBlankLines: true, skipComments: true }, ], 'max-params': ['error', 4], 'max-statements': ['error', 30], 'max-statements-per-line': ['error', { max: 1 }], // === N RULES === 'n/no-unsupported-features/es-syntax': [ 'error', { ignores: ['modules', 'dynamicImport'], version: '>=18.0.0', }, ], 'new-cap': 'off', // Handled by @stylistic 'no-alert': 'warn', 'no-array-constructor': 'error', // === POSSIBLE ERRORS === 'no-async-promise-executor': 'error', 'no-await-in-loop': 'warn', 'no-bitwise': 'error', 'no-caller': 'warn', 'no-case-declarations': 'error', 'no-compare-neg-zero': 'error', 'no-cond-assign': 'error', 'no-console': 'off', 'no-constant-condition': 'error', 'no-constructor-return': 'error', 'no-continue': 'error', 'no-control-regex': 'error', 'no-debugger': 'warn', 'no-delete-var': 'warn', 'no-div-regex': 'error', 'no-dupe-args': 'error', 'no-dupe-keys': 'error', 'no-duplicate-case': 'error', 'no-duplicate-imports': 'error', 'no-else-return': 'warn', 'no-empty': 'off', 'no-empty-character-class': 'error', 'no-empty-function': 'off', // Handled by TypeScript rules 'no-empty-pattern': 'off', 'no-eq-null': 'error', 'no-eval': 'error', 'no-ex-assign': 'error', 'no-extend-native': 'error', 'no-extra-bind': 'warn', 'no-extra-boolean-cast': 'error', 'no-extra-label': 'error', 'no-extra-parens': 'off', // Handled by @stylistic 'no-extra-semi': 'error', 'no-fallthrough': 'error', 'no-floating-decimal': 'warn', 'no-func-assign': 'error', 'no-global-assign': 'error', 'no-implicit-coercion': [ 'error', { boolean: false, number: true, string: true }, ], 'no-implicit-globals': 'error', 'no-implied-eval': 'error', 'no-import-assign': 'error', 'no-inner-declarations': 'error', 'no-invalid-regexp': 'error', 'no-invalid-this': 'off', // Handled by TypeScript rules 'no-irregular-whitespace': 'error', 'no-iterator': 'warn', 'no-label-var': 'error', 'no-label-var': 'error', 'no-labels': 'error', 'no-lone-blocks': 'error', 'no-lonely-if': 'warn', 'no-loop-func': 'error', 'no-loss-of-precision': 'error', 'no-magic-numbers': 'off', // Handled by TypeScript rules 'no-misleading-character-class': 'error', 'no-mixed-operators': 'error', 'no-multi-assign': 'error', 'no-multi-str': 'warn', 'no-new': 'error', 'no-new-func': 'error', 'no-new-object': 'error', 'no-new-wrappers': 'warn', 'no-nonoctal-decimal-escape': 'error', 'no-obj-calls': 'error', 'no-octal': 'error', 'no-octal-escape': 'error', // === NO-ONLY-TESTS RULES === 'no-only-tests/no-only-tests': 'warn', 'no-param-reassign': 'warn', 'no-plusplus': 'off', 'no-proto': 'warn', 'no-prototype-builtins': 'error', 'no-redeclare': 'warn', 'no-regex-spaces': 'error', 'no-restricted-exports': 'off', 'no-restricted-globals': 'error', 'no-restricted-globals': 'error', 'no-restricted-imports': 'off', 'no-restricted-properties': 'off', 'no-restricted-syntax': [ 'warn', { message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', selector: 'ForInStatement', }, { message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', selector: 'LabeledStatement', }, { message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', selector: 'WithStatement', }, { message: 'Provide initialValue to reduce', selector: "CallExpression[callee.property.name='reduce'][arguments.length<2]", }, { message: 'Use for...of instead', selector: "CallExpression[callee.property.name='forEach']", }, ], 'no-return-assign': 'error', 'no-return-await': 'error', 'no-script-url': 'error', // === NO-SECRETS RULES === 'no-secrets/no-secrets': ['warn', { tolerance: 4.5 }], 'no-self-assign': 'error', 'no-self-compare': 'error', 'no-sequences': 'error', 'no-setter-return': 'error', 'no-shadow': 'off', // Handled by TypeScript rules 'no-shadow-restricted-names': 'warn', 'no-sparse-arrays': 'error', 'no-template-curly-in-string': 'error', 'no-this-before-super': 'warn', 'no-throw-literal': 'error', 'no-undef': 'error', 'no-undef-init': 'warn', 'no-undefined': 'off', 'no-undefined': 'off', 'no-underscore-dangle': 'off', 'no-unexpected-multiline': 'error', 'no-unmodified-loop-condition': 'error', 'no-unreachable': 'error', 'no-unreachable-loop': 'error', 'no-unsafe-finally': 'error', 'no-unsafe-negation': 'error', 'no-unsafe-optional-chaining': 'error', 'no-unused-expressions': 'error', 'no-unused-labels': 'error', 'no-unused-private-class-members': 'warn', 'no-unused-vars': [ 'warn', { args: 'after-used', argsIgnorePattern: '^_', caughtErrors: 'all', caughtErrorsIgnorePattern: '^_', ignoreRestSiblings: true, vars: 'all', varsIgnorePattern: '^_', }, ], 'no-use-before-define': 'off', // Handled by TypeScript rules 'no-use-before-define': 'off', // Handled by TypeScript rules 'no-useless-backreference': 'error', 'no-useless-call': 'warn', 'no-useless-catch': 'error', 'no-useless-computed-key': 'warn', 'no-useless-concat': 'warn', 'no-useless-constructor': 'warn', 'no-useless-escape': 'warn', 'no-useless-rename': 'warn', 'no-useless-return': 'warn', 'no-var': 'error', 'no-void': 'error', 'no-warning-comments': 'warn', 'no-with': 'warn', 'object-shorthand': 'warn', 'one-var': ['error', 'never'], 'one-var-declaration-per-line': ['error', 'always'], 'operator-assignment': ['error', 'always'], // === OPTIMIZE-REGEX RULES === 'optimize-regex/optimize-regex': 'warn', // === PERFECTIONIST RULES === 'perfectionist/sort-named-imports': [ 'error', { ignoreCase: true, order: 'asc', type: 'natural', }, ], 'perfectionist/sort-objects': [ 'error', { order: 'asc', type: 'natural', }, ], 'prefer-arrow-callback': 'warn', 'prefer-const': 'warn', 'prefer-destructuring': ['warn', { array: false, object: true }], 'prefer-exponentiation-operator': 'error', 'prefer-named-capture-group': 'warn', 'prefer-numeric-literals': 'error', 'prefer-object-has-own': 'error', 'prefer-promise-reject-errors': 'error', 'prefer-regex-literals': 'error', 'prefer-rest-params': 'warn', 'prefer-spread': 'warn', 'prefer-template': 'warn', // === PROMISE RULES === 'promise/always-return': 'warn', 'promise/avoid-new': 'off', 'promise/catch-or-return': 'warn', 'promise/no-callback-in-promise': 'warn', 'promise/no-multiple-resolved': 'error', 'promise/no-nesting': 'warn', 'promise/no-new-statics': 'error', 'promise/no-promise-in-callback': 'warn', 'promise/no-return-in-finally': 'warn', 'promise/no-return-wrap': 'warn', 'promise/param-names': 'warn', 'promise/prefer-await-to-callbacks': 'warn', 'promise/prefer-await-to-then': 'warn', 'promise/valid-params': 'warn', radix: 'warn', // === REGEXP RULES === 'regexp/no-missing-g-flag': 'error', 'regexp/no-useless-flag': 'error', 'regexp/prefer-d': 'error', 'regexp/prefer-plus-quantifier': 'error', 'regexp/prefer-question-quantifier': 'error', 'regexp/prefer-star-quantifier': 'error', 'require-atomic-updates': ['error', { allowProperties: false }], 'require-await': 'off', // Handled by TypeScript rules 'require-unicode-regexp': 'error', 'require-yield': 'error', // === SECURITY RULES === 'security/detect-buffer-noassert': 'error', 'security/detect-child-process': 'warn', 'security/detect-disable-mustache-escape': 'error', 'security/detect-eval-with-expression': 'error', 'security/detect-new-buffer': 'error', 'security/detect-no-csrf-before-method-override': 'error', 'security/detect-non-literal-fs-filename': 'error', 'security/detect-non-literal-regexp': 'error', 'security/detect-non-literal-require': 'error', 'security/detect-object-injection': 'warn', 'security/detect-possible-timing-attacks': 'error', 'security/detect-pseudoRandomBytes': 'error', 'security/detect-unsafe-regex': 'error', // === SIMPLE-IMPORT-SORT RULES === 'simple-import-sort/exports': 'error', 'simple-import-sort/imports': 'error', // === SONARJS RULES === 'sonarjs/cognitive-complexity': ['warn', 15], 'sonarjs/max-switch-cases': ['warn', 10], 'sonarjs/no-all-duplicated-branches': 'warn', 'sonarjs/no-collapsible-if': 'warn', 'sonarjs/no-collection-size-mischeck': 'warn', 'sonarjs/no-duplicate-string': ['warn', { threshold: 5 }], 'sonarjs/no-duplicated-branches': 'warn', 'sonarjs/no-duplicated-keys': 'warn', 'sonarjs/no-element-overwrite': 'warn', 'sonarjs/no-extra-arguments': 'warn', 'sonarjs/no-greedy-assertion': 'warn', 'sonarjs/no-identical-conditions': 'warn', 'sonarjs/no-identical-expressions': 'warn', 'sonarjs/no-ignored-return': 'warn', 'sonarjs/no-inverted-boolean-check': 'warn', 'sonarjs/no-nested-switch': 'warn', 'sonarjs/no-nested-template-literals': 'warn', 'sonarjs/no-one-iteration-loop': 'warn', 'sonarjs/no-redundant-boolean': 'warn', 'sonarjs/no-redundant-jump': 'warn', 'sonarjs/no-same-line-conditional': 'warn', 'sonarjs/no-small-switch': 'warn', 'sonarjs/no-unused-collection': 'warn', 'sonarjs/no-use-of-empty-return-value': 'warn', 'sonarjs/no-useless-catch': 'warn', 'sonarjs/prefer-immediate-return': 'warn', 'sonarjs/prefer-object-literal': 'warn', 'sonarjs/prefer-single-boolean-return': 'warn', 'sonarjs/prefer-while': 'warn', // === SORT-DESTRUCTURE-KEYS RULES === 'sort-destructure-keys/sort-destructure-keys': 'warn', 'sort-imports': 'off', // Handled by simple-import-sort 'sort-keys': 'off', // Handled by perfectionist 'sort-vars': 'warn', 'spaced-comment': ['warn', 'always'], strict: ['error', 'never'], 'symbol-description': 'error', // === TESTING-LIBRARY RULES === 'testing-library/await-async-query': 'error', 'testing-library/no-await-sync-query': 'error', 'testing-library/no-debugging-utils': 'warn', 'testing-library/no-dom-import': 'error', 'testing-library/no-manual-cleanup': 'error', 'testing-library/no-render-in-setup': 'error', 'testing-library/no-unnecessary-act': 'error', 'testing-library/prefer-explicit-assert': 'warn', 'testing-library/prefer-find-by': 'error', 'testing-library/prefer-presence-queries': 'error', 'testing-library/prefer-query-by-disappearance': 'error', 'testing-library/prefer-screen-queries': 'error', 'testing-library/render-result-naming-convention': 'error', // === UNICORN RULES === 'unicorn/better-regex': 'error', 'unicorn/catch-error-name': ['error', { name: 'error' }], 'unicorn/consistent-destructuring': 'error', 'unicorn/consistent-function-scoping': 'error', 'unicorn/custom-error-definition': 'error', 'unicorn/empty-brace-spaces': 'error', 'unicorn/error-message': 'error', 'unicorn/escape-case': 'error', 'unicorn/expiring-todo-comments': 'off', 'unicorn/explicit-length-check': 'error', 'unicorn/filename-case': [ 'error', { cases: { camelCase: true, pascalCase: true }, ignore: ['.*.md'], }, ], 'unicorn/import-style': 'error', 'unicorn/new-for-builtins': 'error', 'unicorn/no-abusive-eslint-disable': 'error', 'unicorn/no-array-callback-reference': 'off', 'unicorn/no-array-for-each': 'error', 'unicorn/no-array-method-this-argument': 'error', 'unicorn/no-array-push-push': 'error', 'unicorn/no-array-reduce': 'error', 'unicorn/no-await-expression-member': 'error', 'unicorn/no-console-spaces': 'error', 'unicorn/no-document-cookie': 'error', 'unicorn/no-empty-file': 'error', 'unicorn/no-for-loop': 'error', 'unicorn/no-hex-escape': 'error', 'unicorn/no-instanceof-array': 'error', 'unicorn/no-invalid-remove-event-listener': 'error', 'unicorn/no-keyword-prefix': 'off', 'unicorn/no-lonely-if': 'error', 'unicorn/no-nested-ternary': 'error', 'unicorn/no-new-array': 'error', 'unicorn/no-new-buffer': 'error', 'unicorn/no-null': 'off', 'unicorn/no-object-as-default-parameter': 'error', 'unicorn/no-process-exit': 'error', 'unicorn/no-static-only-class': 'error', 'unicorn/no-thenable': 'error', 'unicorn/no-typeof-undefined': 'error', 'unicorn/no-unnecessary-await': 'error', 'unicorn/no-unreadable-array-destructuring': 'error', 'unicorn/no-unreadable-iife': 'error', 'unicorn/no-unused-properties': 'error', 'unicorn/no-useless-fallback-in-spread': 'error', 'unicorn/no-useless-length-check': 'error', 'unicorn/no-useless-promise-resolve-reject': 'error', 'unicorn/no-useless-spread': 'error', 'unicorn/no-useless-undefined': ['error', { checkArguments: true }], 'unicorn/no-zero-fractions': 'error', 'unicorn/number-literal-case': 'error', 'unicorn/numeric-separators-style': 'error', 'unicorn/prefer-add-event-listener': 'error', 'unicorn/prefer-array-find': 'error', 'unicorn/prefer-array-flat': ['error', { functions: ['flatten'] }], 'unicorn/prefer-array-flat-map': 'error', 'unicorn/prefer-array-index-of': 'error', 'unicorn/prefer-array-some': 'error', 'unicorn/prefer-at': 'error', 'unicorn/prefer-blob-reading-methods': 'error', 'unicorn/prefer-code-point': 'error', 'unicorn/prefer-date-now': 'error', 'unicorn/prefer-default-parameters': 'error', 'unicorn/prefer-dom-node-append': 'error', 'unicorn/prefer-dom-node-dataset': 'error', 'unicorn/prefer-dom-node-remove': 'error', 'unicorn/prefer-dom-node-text-content': 'error', 'unicorn/prefer-export-from': 'error', 'unicorn/prefer-includes': 'error', 'unicorn/prefer-json-parse-buffer': 'error', 'unicorn/prefer-keyboard-event-key': 'error', 'unicorn/prefer-logical-operator-over-ternary': 'error', 'unicorn/prefer-math-trunc': 'error', 'unicorn/prefer-modern-dom-apis': 'error', 'unicorn/prefer-modern-math-apis': 'error', 'unicorn/prefer-module': 'error', 'unicorn/prefer-native-coercion-functions': 'error', 'unicorn/prefer-negative-index': 'error', 'unicorn/prefer-node-protocol': 'error', 'unicorn/prefer-number-properties': 'error', 'unicorn/prefer-object-from-entries': 'error', 'unicorn/prefer-optional-catch-binding': 'error', 'unicorn/prefer-prototype-methods': 'error', 'unicorn/prefer-query-selector': 'error', 'unicorn/prefer-reflect-apply': 'error', 'unicorn/prefer-regexp-test': 'error', 'unicorn/prefer-set-has': 'error', 'unicorn/prefer-set-size': 'error', 'unicorn/prefer-spread': 'error', 'unicorn/prefer-string-replace-all': 'error', 'unicorn/prefer-string-slice': 'error', 'unicorn/prefer-string-starts-ends-with': 'error', 'unicorn/prefer-string-trim-start-end': 'error', 'unicorn/prefer-switch': 'error', 'unicorn/prefer-ternary': 'error', 'unicorn/prefer-top-level-await': 'error', 'unicorn/prefer-type-error': 'error', 'unicorn/prevent-abbreviations': [ 'warn', { allowList: { e2e: true, params: true, props: true, ref: true }, ignore: [/e2e/], }, ], 'unicorn/relative-url-style': 'error', 'unicorn/require-array-join-separator': 'error', 'unicorn/require-number-to-fixed-digits-argument': 'error', 'unicorn/require-post-message-target-origin': 'error', 'unicorn/string-content': 'off', 'unicorn/switch-case-braces': 'error', 'unicorn/text-encoding-identifier-case': 'error', 'unicorn/throw-new-error': 'error', 'use-isnan': 'error', 'valid-typeof': 'error', 'vars-on-top': 'error', // === WRITE-GOOD-COMMENTS RULES === 'write-good-comments/write-good-comments': 'warn', 'yml/block-mapping': 'error', // === YML RULES === 'yml/block-mapping-question-indicator-newline': 'error', 'yml/block-sequence': 'error', 'yml/block-sequence-hyphen-indicator-newline': 'error', 'yml/flow-mapping-curly-newline': 'error', 'yml/flow-mapping-curly-spacing': 'error', 'yml/flow-sequence-bracket-newline': 'error', 'yml/flow-sequence-bracket-spacing': 'error', 'yml/indent': ['error', 2], 'yml/key-spacing': 'error', 'yml/no-empty-document': 'error', 'yml/no-empty-key': 'error', 'yml/no-empty-mapping-value': 'error', 'yml/no-empty-sequence-entry': 'error', 'yml/no-irregular-whitespace': 'error', 'yml/no-tab-indent': 'error', 'yml/quotes': ['warn', { avoidEscape: true, prefer: 'double' }], 'yml/require-string-key': 'error', 'yml/sort-keys': 'off', 'yml/vue-custom-block/no-parsing-error': 'error', yoda: 'error', };