编辑器配置

1,237 阅读3分钟

vscode配置

  • 安装 eslint插件
  • 在设置中配置
{
    "files.exclude": { // 在编辑器中展示的文件、文件夹
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "**/tmp": true,
        "**/node_modules": false,
        "**/bower_components": true,
        // "**/dist": true
    },
    "files.watcherExclude": { // 编辑器忽略的文件文件夹
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/**": true,
        "**/tmp/**": true,
        "**/bower_components/**": true,
        "**/dist/**": true
    },
    //     // 皮肤
    "workbench.iconTheme": "vscode-icons",
    // "workbench.colorTheme": "One Dark Pro Vivid",
    // 窗口失去焦点自动保存
    // "files.autoSave": "onFocusChange",
    // 编辑粘贴自动格式化
    "editor.formatOnPaste": false,
    // 控制字体系列。
    "editor.fontFamily": "pingfang,Menlo, Monaco, 'Courier New', monospace",
    // 字体大小
    "editor.fontSize": 14,
    // 行高
    // "editor.lineHeight": 17,
    // 通过使用鼠标滚轮同时按住 Ctrl 可缩放编辑器的字体
    // 窗口失去焦点自动保存
    // 通过使用鼠标滚轮同时按住 Ctrl 可缩放编辑器的字体
    "editor.mouseWheelZoom": false,
    // 行太长自动换行
    "editor.wordWrap": "on",
    // eslint设置
    "eslint.options": [
        ".js",
        ".vue",
        ".ts",
        ".tsx"
    ],
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "javascript",
            "autoFix": true
        },
        {
            "language": "html",
            "autoFix": true
        },
        {
            "language": "vue",
            "autoFix": true
        },
        {
            "language": "typescript",
            "autoFix": true
        },
        {
            "language": "typescriptreact",
            "autoFix": true
        }
    ],
    // "prettier.eslintIntegration": true,
    // // 单引号
    // "prettier.singleQuote": true,
    // // 去掉结尾的分号
    // "prettier.semi": true,
    "minapp-vscode.prettier": {
        "printWidth": 120, //一行的字符数,如果超过会进行换行,默认为80
        "eslintIntegration": true,
        "tabWidth": 2, //一个tab代表几个空格数,默认为80
        "useTabs": false, //是否使用tab进行缩进,默认为false,表示用空格进行缩减
        "singleQuote": true, //字符串是否使用单引号,默认为false,使用双引号
        "semi": false, //行尾是否使用分号,默认为true
        "trailingComma": "none", //是否使用尾逗号,有三个可选值"<none|es5|all>"
        "bracketSpacing": true, //对象大括号直接是否有空格,默认为true,效果:{ foo: bar 
    },
    //保存自动修复
    "eslint.autoFixOnSave": true,
    // 保存自动格式化
    "editor.formatOnSave": true,
    // tab锁紧
    "editor.tabSize": 2,
    // 空格变成......
    "editor.renderWhitespace": "all",
    // formatter for <script> region
    "vetur.format.defaultFormatter.js": "vscode-typescript",
    // 启用或禁用 JavaScript 文件的语义检查。
    "javascript.implicitProjectConfig.experimentalDecorators": true,
    // 控制在差异编辑器中是否把前导空格或尾随空格的改动显示为差异
    "diffEditor.ignoreTrimWhitespace": false,
    // 启用或禁用在 VS Code 中重命名或移动文件时自动更新 import 语句的路径。
    "typescript.updateImportsOnFileMove.enabled": "always",
    // 控制是否在搜索中跟踪符号链接。解决VSCode启动后CPU高占用问题
    "search.followSymlinks": false,
    "terminal.integrated.fontSize": 14,
    // 格式化插件的配置
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
            // 属性强制折行对齐
            "wrap_attributes": "force-aligned"
        }
    },
    // 文件关联
    "files.associations": {
        // wepy 框架关联
        "*.vue": "vue",
        "*.wpy": "vue",
        "*.wxml": "html",
        "*.wxss": "css",
        // "*.cjson": "jsonc",
        // "*.wxs": "javascript"
    },
    "emmet.includeLanguages": {
        "vue-html": "html",
        "vue": "vue",
        "wxml": "html"
    },
    "files.autoSave": "off",
    "fileheader.configObj": {
        "createFileTime": true,
        "language": {
            "languagetest": {
                "head": "/?",
                "middle": " $ @",
                "end": " $/"
            }
        },
        "autoAdd": false,
        "autoAlready": true,
        "annotationStr": {
            "head": "/*",
            "middle": " * @",
            "end": " */",
            "use": false
        },
        "headInsertLine": {
            "php": 2
        },
        "beforeAnnotation": {},
        "afterAnnotation": {},
        "specialOptions": {},
        "switch": {
            "newlineAddAnnotation": true
        },
        "prohibitAutoAdd": [
            "json"
        ],
        "moveCursor": true,
        "dateFormat": "YYYY-MM-DD HH:mm:ss",
        "atSymbol": "@",
        "atSymbolObj": {},
        "colon": ": ",
        "colonObj": {}
    },
    "fileheader.customMade": {
        "Descripttion": "",
        "version": "",
        "Author": "GUOCHAO959",
        "Date": "Do not edit",
        "LastEditors": "GUOCHAO959",
        "LastEditTime": "Do not Edit"
    },
    "terminal.integrated.rendererType": "dom",
    "window.zoomLevel": 0,
    "workbench.startupEditor": "newUntitledFile",
}
  • elsint配置
// 项目根目录.eslintrc.js文件

module.exports = {
  root: true,
  env: {
    "node": true,
    "browser": true
  },
  extends: [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  globals: { // 一些全局声明的变量在此处列出,防止elsint报错
    "opts": true,
    "vue": true,
    "AMap": true
  },
  plugins: [
    'vue'
  ],
  rules: {
    // 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    // 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': 0,
    'handle-callback-err': 0,
    'no-unused-vars': process.env.NODE_ENV === 'production' ? 0 : 1, // 生产环境关闭
    'eqeqeq': 0, // 可以不使用全等
    'no-var': 2,
    'no-use-before-define': 2,
    "no-dupe-keys": 2,//在创建对象字面量时不允许键重复 {a:1,a:1}
    "no-alert": 2,//禁止使用alert confirm prompt
    "no-const-assign": 2,//禁止修改const声明的变量
    "default-case": 2,//switch语句最后必须有default
    // "indent": [2, 2],//缩进风格
    "use-isnan": 2, //禁止比较时使用NaN,只能用isNaN()
    "no-func-assign": 2,//禁止重复的函数声明
    "no-inner-declarations": [2, "functions"],//禁止在块语句中使用声明(变量或函数)
    "no-useless-return": 0, //允许没有任何内容的return
    "no-spaced-func": 2,//函数调用时 函数名与()之间不能有空格
    "space-before-function-paren": [0, "always"],//函数定义时括号前面要不要有空格
    "prefer-promise-reject-errors": [0],
    // "indent": ["error", 0]
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}