vscode基础eslint +prettier配置

项目根目录下的eslintrc.js文件是eslint检查项,prettier是一个代码格式化工具,需要先设置检查项,再按照检查项编辑prettier工具的配置;也就是先确定产品的标准,再按此标准生产制作产品的工具的意思:

产品:代码
标准:eslint配置
工具:prettier

eslintrc.js配置

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ['plugin:vue/essential', 'eslint:recommended', '@vue/prettier'],
  parserOptions: {
    parser: 'babel-eslint'
  },
  rules: {
    'prettier/prettier': [
      process.env.NODE_ENV === 'production' ? 'off' : 'error',
      //prettier 规则配置
      {
        printWidth: 100, // 一行代码超过这个值换行
        endOfLine: 'auto', // 换行cr检查
        singleQuote: true, // 使用单引号
        arrowParens: 'always',   (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号,always:始终有括号
        semi: false, // 语句结尾无分号
        trailingComma: 'none' // 对象最后一个属性不加添加逗号
      }
    ],
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  },
  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)'
      ],
      env: {
        jest: true
      }
    }
  ]
}


settings.json配置(安装Prettier - Code formatter插件)

{
    "editor.formatOnSave": true,	//保存自动格式化
    "terminal.integrated.automationShell.windows": "C:\\Windows\\System32\\cmd.exe",
    "editor.fontSize": 18,
    "[vue]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "eslint.codeAction.showDocumentation": {
        "enable": true
    },
	
	//下面具体格式化项按照上面的eslint标准配置

    "prettier.semi": false,
    "prettier.singleQuote": true,
    "prettier.trailingComma": "none", // 对象最后一个属性不加添加逗号
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "prettier.endOfLine": "auto",
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值