ESLint与VS Code的配置

284 阅读1分钟

1.package.json

 "rules": {
    semi: ['error', 'never'],
    'no-trailing-spaces': 1,
    'no-extra-parens': ['error', 'all', { nestedBinaryExpressions: false }],
    'no-var': 'error',
    indent: ['error', 4],
    'comma-dangle': ['error', 'never'],
    'comma-spacing': ['error', { before: false, after: true }],
    'array-bracket-spacing': ['error', 'never'],
    'implicit-arrow-linebreak': ['error', 'beside'],
    'lines-between-class-members': ['error', 'always'],
    'max-len': ['error', { code: 280 }],
    quotes: ['error', 'single', { allowTemplateLiterals: true }],
    'arrow-spacing': 'error',
    'no-use-before-define': ['error', { functions: false, classes: false }],
    'no-invalid-this': 'warn',
    eqeqeq: ['error', 'always'],
    curly: 'error',
    'object-curly-spacing': ['error', 'always'],
    'space-before-function-paren': 0,
    'handle-callback-err': 0,
    camelcase: 0,
    'no-explicit-any': 0,
    "@typescript-eslint/explicit-module-boundary-types": "off",
    "@typescript-eslint/no-explicit-any": "off"
    }

2.settings.json

{
    "eslint.format.enable": true,
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true,
    },
    "[typescript]": {
        "editor.codeActionsOnSave": {
            "source.fixAll.eslint": true
        },
        "editor.defaultFormatter": "dbaeumer.vscode-eslint"
    },
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur" // 使用 vetur 格式化规则
    },
    "vetur.format.defaultFormatterOptions": {
        "prettier": {
            "wrap_attributes": "force-aligned",
            "semi": false, //不加分号
            "trailingComma": "none", // 不加逗号
            "singleQuote": true, //用单引号
            "eslintIntegration": true, //开启 eslint 支持
        },
        "js-beautify-html": {
            // 属性强制折行对齐
            "wrap_line_length": 120,
            "wrap_attributes": "auto",
            "end_with_newline": false
        }
    },
    "vetur.format.options.tabSize": 4,
    "vetur.format.defaultFormatter.js": "vscode-typescript",
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "html",
        "vue",
        "typescript",
        "typescriptreact"
    ],
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.formatOnPaste": true,
    "prettier.arrowParens": "avoid",
    "prettier.trailingComma": "none",
    "prettier.vueIndentScriptAndStyle": true,
    "auto-rename-tag.activationOnLanguage": [

        "*"
    ]
}