美文网首页
VueJS & WebStorm 使用eslint格式化代码

VueJS & WebStorm 使用eslint格式化代码

作者: 李颖轩_LiYingxuan | 来源:发表于2019-03-28 17:19 被阅读0次

安装插件

yarn add @vue/eslint-config-prettier --dev
yarn add eslint --dev
yarn add eslint-config-prettier --dev
yarn add eslint-friendly-formatter --dev
yarn add eslint-plugin-html --dev
yarn add eslint-plugin-jest --dev

增加配置文件

在项目根目录增加文件.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: ["plugin:vue/essential", "@vue/prettier", "plugin:jest/recommended"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-unused-vars": "off",
    quotes: "off",
  },
  parserOptions: {
    parser: "babel-eslint",
  },
};

增加脚本命令

在./package.json中的scripts下增加

"lint": "eslint --ext .js,.vue src",
"fix": "eslint --ext .js,.vue src --fix",

运行格式化

yarn fix

The end.

相关文章

网友评论

      本文标题:VueJS & WebStorm 使用eslint格式化代码

      本文链接:https://www.haomeiwen.com/subject/mxdcbqtx.html