vscode编辑设置

vscode 安装 eslint、prettier插件
  • 在settings文件中将以下代码替换
  • 文件-->首选项-->设置
    image.png

    {
      "workbench.colorTheme": "Dracula Soft",
      "security.workspace.trust.untrustedFiles": "open",
      "bracketPairColorizer.depreciation-notice": false,
      "[vue]": {
          "editor.defaultFormatter": "octref.vetur"
      },
      "[html]": {
          "editor.defaultFormatter": "vscode.html-language-features"
      },
      "diffEditor.ignoreTrimWhitespace": false,
      "editor.codeActionsOnSave": {
          "source.fixAll.eslint": true
      },
      "eslint.format.enable": true,
      //autoFix默认开启,只需输入字符串数组即可
      "eslint.validate": ["javascript", "vue", "html"]
    }

    .eslintrc.js 文件配置

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module',
  },
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  extends: ['plugin:vue/recommended', 'eslint:recommended'],
  rules: {
    semi:['error','always'], // 末尾增加分号
    'vue/max-attributes-per-line': [
      2,
      {
        singleline: 10,
        multiline: {
          max: 1,
          allowFirstLine: false,
        },
      },
    ],
    'vue/singleline-html-element-content-newline': 'off',
    'vue/multiline-html-element-content-newline': 'off',
    'vue/name-property-casing': ['error', 'PascalCase'],
    'vue/no-v-html': 'off',
    'vue/html-self-closing': 'off'
  },
  // add your custom rules here
  //it is base on https://github.com/vuejs/eslint-config-vue
};
  • 项目添加 .prettierrc.js 格式化文档配置,将格式化规则固定到项目
module.exports = {
  trailingComma: 'es5',
  tabWidth: 2,
  semi: true,
  singleQuote: true,
  bracketSpacing: true, // 花括号添加空格
  endOfLine: 'lf', // 换行符
  printWidth: 150, // 行宽,超过换行
  vueIndentScriptAndStyle: false,
};

菜鸟前端
10 声望0 粉丝