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

1.模块包

  • vue创建项目时,选择 eslint 和 standar 包
  • 是在 项目 运行编译时 起作用!
    eslint编译时检查语法并报错

2.配置文件

  • 配置文件:.eslintrc.js

  • @vue/standard 规范:https://blog.csdn.net/qq_15307457/article/details/81135204

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 来格式化修复 不同区域的 代码

  • 为 prettier 设置 规则配置文件

    • .prettierrc.js
// prettier.config.js or .prettierrc.js
module.exports = {
    trailingComma: "none",
    // tabWidth: 4,
    semi: false,
    singleQuote: true,
};
  • 关闭 eslint 中 pritter改不了的 规范
    关闭 eslint 中 pritter改不了的 规范
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹伯通_AI智造

研究源码,写文章,录制视频挺好

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值