相关Eslint配置文件

45 阅读5分钟

相关Eslint配置文件

相关规则解释->

module.exports = {
    env: {
        browser: true,
        commonjs: true,
        es6: true,
        node: true,
    },
    parser: '@typescript-eslint/parser',
    parserOptions: {
        parser: 'babel-eslint',
        ecmaFeatures: {
            experimentalObjectRestSpread: true,
            jsx: true,
            modules: true,
        },
        ecmaVersion: 6,
        sourceType: 'module',
    },
    plugins: ['react'],
    settings: {
        react: {
            version: 'detect',
        },
    },
    root: true,
    rules: {
        'accessor-pairs': [
            'error',
            {
                getWithoutSet: false,
                setWithoutGet: true,
            },
        ],
        'array-bracket-newline': 'off',
        'array-bracket-spacing': ['error', 'never'],
        'array-callback-return': 'off',
        'array-element-newline': 'off',
        'arrow-body-style': 'off',
        'arrow-parens': 'off',
        'arrow-spacing': [
            'error',
            {
                after: true,
                before: true,
            },
        ],
        'block-scoped-var': 'error',
        'block-spacing': ['error', 'always'],
        'brace-style': 'off',
        'callback-return': 'off',
        camelcase: 'off',
        'capitalized-comments': 'off',
        'class-methods-use-this': 'off',
        'comma-dangle': 'off',
        'comma-spacing': [
            'error',
            {
                after: true,
                before: false,
            },
        ],
        'comma-style': ['error', 'last'],
        'comment-ratio': 'off',
        complexity: [
            'error',
            {
                max: 20,
            },
        ],
        'computed-property-spacing': ['error', 'never'],
        'consistent-return': 'off',
        'consistent-this': 'off',
        'constructor-super': 'error',
        curly: ['error', 'multi-line', 'consistent'],
        'default-case': 'off',
        'dot-location': ['error', 'property'],
        'dot-notation': 'off',
        'eol-last': 'error',
        eqeqeq: [
            'error',
            'always',
            {
                null: 'ignore',
            },
        ],
        'for-direction': 'error',
        'func-call-spacing': ['error', 'never'],
        'func-id-match': 'off',
        'func-name-matching': [
            'error',
            'always',
            {
                includeCommonJSModuleExports: false,
            },
        ],
        'func-names': 'off',
        'func-style': 'off',
        'generator-star-spacing': [
            'error',
            {
                after: true,
                before: false,
            },
        ],
        'getter-return': [
            'error',
            {
                allowImplicit: false,
            },
        ],
        'global-require': 'off',
        'guard-for-in': 'error',
        'handle-callback-err': 'error',
        'id-blacklist': 'off',
        'id-length': 'off',
        'id-match': 'off',
        'init-declarations': 'off',
        'jsx-quotes': ['error', 'prefer-double'],
        'key-spacing': [
            'error',
            {
                afterColon: true,
                beforeColon: false,
                mode: 'strict',
            },
        ],
        'keyword-spacing': [
            'error',
            {
                after: true,
                before: true,
            },
        ],
        license: 'off',
        'line-comment-position': 'off',
        'linebreak-style': 'off',
        'lines-around-comment': 'off',
        'max-depth': ['error', 5],
        'max-len': 'off',
        'max-lines': 'off',
        'max-nested-callbacks': ['error', 3],
        'max-params': ['error', 7],
        'max-statements': 'off',
        'max-statements-per-line': 'off',
        'multiline-ternary': 'off',
        'new-cap': [
            'error',
            {
                capIsNew: false,
                newIsCap: true,
                properties: true,
            },
        ],
        'new-parens': 'error',
        'newline-per-chained-call': 'off',
        'no-alert': 'off',
        'no-array-constructor': 'error',
        'no-await-in-loop': 'off',
        'no-bitwise': 'off',
        'no-buffer-constructor': 'error',
        'no-caller': 'error',
        'no-case-declarations': 'error',
        'no-catch-shadow': 'off',
        'no-class-assign': 'error',
        'no-compare-neg-zero': 'error',
        'no-cond-assign': ['error', 'except-parens'],
        'no-confusing-arrow': 'error',
        'no-console': ['error', {allow: ['warn', 'error', 'debug']}],
        'no-const-assign': 'error',
        'no-constant-condition': [
            'error',
            {
                checkLoops: false,
            },
        ],
        'no-continue': 'off',
        'no-control-regex': 'error',
        'no-debugger': 'error',
        'no-delete-var': 'error',
        'no-div-regex': 'off',
        'no-dupe-args': 'error',
        'no-dupe-class-members': 'error',
        'no-dupe-keys': 'error',
        'no-duplicate-case': 'error',
        'no-duplicate-imports': 'error',
        'no-else-return': 'off',
        'no-empty': [
            'error',
            {
                allowEmptyCatch: true,
            },
        ],
        'no-empty-character-class': 'error',
        'no-empty-function': [
            'error',
            {
                allow: ['functions', 'arrowFunctions'],
            },
        ],
        'no-empty-pattern': 'error',
        'no-eq-null': 'off',
        'no-eval': 'error',
        'no-ex-assign': 'error',
        'no-extend-native': 'error',
        'no-extra-bind': 'error',
        'no-extra-boolean-cast': 'error',
        'no-extra-label': 'error',
        'no-extra-parens': 'off',
        'semi': 1,
        'no-extra-semi': 'error',
        'no-fallthrough': 'error',
        'no-floating-decimal': 'error',
        'no-func-assign': 'error',
        'no-global-assign': 'error',
        'no-implicit-coercion': 'off',
        'no-implicit-globals': 'error',
        'no-implied-eval': 'error',
        'no-inline-comments': 'off',
        'no-inner-declarations': ['error', 'both'],
        'no-invalid-regexp': 'error',
        'no-invalid-this': 'off',
        'no-irregular-whitespace': [
            'error',
            {
                skipComments: false,
                skipRegExps: true,
                skipStrings: true,
                skipTemplates: true,
            },
        ],
        'no-iterator': 'error',
        'no-label-var': 'error',
        'no-labels': 'error',
        'no-lone-blocks': 'error',
        'no-lonely-if': 'off',
        'no-loop-func': 'error',
        'no-magic-numbers': 'off',
        'no-mixed-operators': 'off',
        'no-mixed-requires': 'off',
        'no-mixed-spaces-and-tabs': 'error',
        'no-multi-assign': 'off',
        'no-multi-spaces': [
            'error',
            {
                exceptions: {
                    BinaryExpression: false,
                    ImportDeclaration: true,
                    Property: true,
                    VariableDeclarator: true,
                },
                ignoreEOLComments: true,
            },
        ],
        'no-multi-str': 'error',
        'no-multiple-empty-lines': [
            'error',
            {
                max: 3,
                maxBOF: 1,
                maxEOF: 1,
            },
        ],
        'no-negated-condition': 'off',
        'no-nested-ternary': 'off',
        'no-new': 'error',
        'no-new-func': 'error',
        'no-new-object': 'error',
        'no-new-require': 'error',
        'no-new-symbol': 'error',
        'no-new-wrappers': 'error',
        'no-obj-calls': 'error',
        'no-octal': 'error',
        'no-octal-escape': 'error',
        'no-param-reassign': 'off',
        'no-path-concat': 'error',
        'no-plusplus': 'off',
        'no-process-env': 'off',
        'no-process-exit': 'off',
        'no-proto': 'error',
        'no-prototype-builtins': 'off',
        'no-redeclare': 'error',
        'no-regex-spaces': 'error',
        'no-restricted-globals': 'off',
        'no-restricted-imports': 'off',
        'no-restricted-modules': 'off',
        'no-restricted-properties': 'off',
        'no-restricted-syntax': 'off',
        'no-return-assign': ['error', 'always'],
        'no-return-await': 'error',
        'no-script-url': 'off',
        'no-self-assign': 'error',
        'no-self-compare': 'error',
        'no-sequences': 'error',
        'no-shadow': [
            'error',
            {
                allow: ['resolve', 'reject', 'done', 'cb', 'callback', 'error', 'err', 'e'],
                builtinGlobals: false,
                hoist: 'functions',
            },
        ],
        'no-shadow-restricted-names': 'error',
        'no-sparse-arrays': 'error',
        'no-sync': 'off',
        'no-template-curly-in-string': 'error',
        'no-ternary': 'off',
        'no-this-before-super': 'error',
        'no-throw-literal': 'error',
        'no-trailing-spaces': 'error',
        'no-undef': 'off',
        'no-undef-init': 'error',
        'no-undefined': 'error',
        'no-underscore-dangle': 'off',
        'no-unexpected-multiline': 'error',
        'no-unmodified-loop-condition': 'error',
        'no-unneeded-ternary': 'off',
        'no-unreachable': 'error',
        'no-unsafe-finally': 'error',
        'no-unsafe-negation': 'error',
        'no-unused-expressions': [
            'error',
            {
                allowShortCircuit: true,
                allowTaggedTemplates: true,
                allowTernary: true,
            },
        ],
        'no-unused-labels': 'error',
        'no-unused-vars': [
            'error',
            {
                args: 'none',
                caughtErrors: 'none',
                vars: 'all',
            },
        ],
        'no-use-before-define': 'off',
        'no-useless-call': 'error',
        'no-useless-computed-key': 'error',
        'no-useless-concat': 'error',
        'no-useless-constructor': 'error',
        'no-useless-escape': 'off',
        'no-useless-rename': 'error',
        'no-useless-return': 'off',
        'no-var': 'off',
        'no-void': 'error',
        'no-warning-comments': 'off',
        'no-whitespace-before-property': 'error',
        'no-with': 'error',
        'nonblock-statement-body-position': [
            'error',
            'beside',
            {
                overrides: {
                    while: 'below',
                },
            },
        ],
        'object-curly-newline': [
            'error',
            {
                consistent: true,
                multiline: true,
            },
        ],
        'object-curly-spacing': [
            'error',
            'always',
            {
                arraysInObjects: true,
                objectsInObjects: false,
            },
        ],
        'object-property-newline': 'off',
        'object-shorthand': 'off',
        'one-var': ['error', 'never'],
        'one-var-declaration-per-line': ['error', 'always'],
        'operator-assignment': 'off',
        'operator-linebreak': 'off',
        'padded-blocks': 'off',
        'padding-line-between-statements': 'off',
        'prefer-arrow-callback': 'off',
        'prefer-const': 'error',
        'prefer-destructuring': 'off',
        'prefer-numeric-literals': 'off',
        'prefer-promise-reject-errors': 'error',
        'prefer-rest-params': 'off',
        'prefer-spread': 'off',
        'prefer-template': 'off',
        'quote-props': 'off',
        quotes: [
            'error',
            'single',
            {
                allowTemplateLiterals: true,
                avoidEscape: true,
            },
        ],
        radix: 'error',
        'require-await': 'off',
        'require-jsdoc': 'off',
        'require-yield': 'error',
        'rest-spread-spacing': ['error', 'never'],

        'sort-imports': 'off',
        'sort-keys': 'off',
        'sort-vars': 'off',
        'space-before-blocks': ['error', 'always'],
        'space-before-function-paren': [
            'error',
            {
                anonymous: 'ignore',
                asyncArrow: 'always',
                named: 'never',
            },
        ],
        'space-in-parens': ['error', 'never'],
        'space-indent': 'off',
        'space-infix-ops': 'error',
        'space-unary-ops': [
            'error',
            {
                nonwords: false,
                words: true,
            },
        ],
        'spaced-comment': [
            'error',
            'always',
            {
                block: {
                    balanced: true,
                    exceptions: ['*'],
                },
            },
        ],
        strict: ['error', 'never'],
        'switch-colon-spacing': [
            'error',
            {
                after: true,
                before: false,
            },
        ],
        'symbol-description': 'error',
        'template-curly-spacing': ['error', 'never'],
        'template-tag-spacing': ['error', 'never'],
        'unicode-bom': ['error', 'never'],
        'use-isnan': 'error',
        'valid-jsdoc': 'off',
        'valid-typeof': 'error',
        'vars-on-top': 'off',
        'wrap-iife': [
            'error',
            'inside',
            {
                functionPrototypeMethods: true,
            },
        ],
        'wrap-regex': 'off',
        'yield-star-spacing': ['error', 'after'],
        yoda: [
            'error',
            'never',
            {
                onlyEquality: true,
            },
        ],
        'react/boolean-prop-naming': 'off',
        'react/default-props-match-prop-types': 'off',
        'react/display-name': 'off',
        'react/forbid-component-props': 'off',
        'react/forbid-elements': 'off',
        'react/forbid-foreign-prop-types': 'off',
        'react/forbid-prop-types': 'off',
        'react/jsx-boolean-value': 'off',
        'react/jsx-closing-bracket-location': 'off',
        'react/jsx-closing-tag-location': 'off',
        'react/jsx-curly-spacing': 'off',
        'react/jsx-equals-spacing': 'off',
        'react/jsx-filename-extension': 'off',
        'react/jsx-first-prop-new-line': 'off',
        'react/jsx-handler-names': 'off',
        'react/jsx-indent': 'off',
        'react/jsx-indent-props': 'off',
        'react/jsx-key': 'error',
        'react/jsx-max-props-per-line': 'off',
        'react/jsx-no-bind': 'off',
        'react/jsx-no-comment-textnodes': 'error',
        'react/jsx-no-duplicate-props': 'error',
        'react/jsx-no-literals': 'off',
        'react/jsx-no-target-blank': 'off',
        'react/jsx-no-undef': 'off',
        'react/jsx-pascal-case': 'error',
        'react/jsx-sort-props': 'off',
        'react/jsx-tag-spacing': 'off',
        'react/jsx-uses-react': 'error',
        'react/jsx-uses-vars': 'error',
        'react/jsx-wrap-multilines': 'off',
        'react/no-array-index-key': 'off',
        'react/no-children-prop': 'error',
        'react/no-danger': 'off',
        'react/no-danger-with-children': 'error',
        'react/no-deprecated': 'error',
        'react/no-did-mount-set-state': 'off',
        'react/no-did-update-set-state': 'error',
        'react/no-direct-mutation-state': 'error',
        'react/no-find-dom-node': 'error',
        'react/no-is-mounted': 'error',
        'react/no-multi-comp': 'off',
        'react/no-redundant-should-component-update': 'error',
        'react/no-render-return-value': 'error',
        'react/no-set-state': 'off',
        'react/no-string-refs': 'error',
        'react/no-typos': 'error',
        'react/no-unescaped-entities': 'error',
        'react/no-unknown-property': 'error',
        'react/no-unused-prop-types': 'off',
        'react/no-unused-state': 'off',
        'react/no-will-update-set-state': 'error',
        'react/prefer-es6-class': 'off',
        'react/prefer-stateless-function': 'off',
        'react/prop-types': 'off',
        'react/react-in-jsx-scope': 'off',
        'react/require-default-props': 'off',
        'react/require-optimization': 'off',
        'react/require-render-return': 'error',
        'react/self-closing-comp': 'off',
        'react/sort-comp': 'off',
        'react/sort-prop-types': 'off',
        'react/style-prop-object': 'error',
        'react/void-dom-elements-no-children': 'error',
    },
}