【秒懂】图解 eslint+vetur+prettier修复代码

2022-03-29  本文已影响0人  前端老邹_伯通

1.模块包

eslint报错

2.配置文件

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  parserOptions: {
    parser: '@babel/eslint-parser'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    quotes: [2, 'single'], // 引号类型 `` "" ''
    'space-before-function-paren': ['error', 'never'] // 方法括号前面的 空格
  }
}
eslint配置文件

3.eslint扩展工具

eslint扩展工具

4.启用eslint扩展工具修复js文件

// 配置 vscode 保存时 使用 eslint扩展插件 来 检查和修复 js文件的语法规范错误
"editor.codeActionsOnSave": {
  "source.fixAll.eslint": true
},
启用eslint扩展工具修复js文件

5.使用Vetur格式化

设置 使用 prettier 来格式化修复 不同区域的 代码
// prettier.config.js or .prettierrc.js
module.exports = {
    trailingComma: "none",
    // tabWidth: 4,
    semi: false,
    singleQuote: true,
};
关闭 eslint 中 pritter改不了的 规范
上一篇 下一篇

猜你喜欢

热点阅读