vue项目配置eslint步骤总结

  1. 安装eslint
yarn add eslint@7 -D
yarn add eslint-plugin-vue eslint-plugin-prettier prettier -D
  1. 初始化ESLint配置
npx eslint --init
  1. 配置文件编辑
    手动调整.eslintrc.js
module.exports = {
    "env": {
        "browser": true,
        "es2021": true
    },
    "globals": {
        "uni": "readonly",
        "wx": "readonly",
    },
    "extends": [
        "eslint:recommended",
        "plugin:vue/essential",
        "plugin:prettier/recommended"
    ],
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "vue"
    ],
    "rules": {
        "vue/no-multiple-template-root": "off",
        "no-debugger": "off",
        "vue/multi-word-component-names": "off",
        "vue/no-v-model-argument": "off"
    }
};
  1. 配置文件编辑
    手动调整.prettierrc.js文件
module.exports = {
  printWidth: 80, // 80 每行代码长度
  tabWidth: 2, // 每个 tab 相当于多少个空格
  useTabs: false, // 是否使用 tab 进行缩进
  singleQuote: true// 是否使用单引号
  semi: true, // 声明结尾使用分号
  trailingComma: 'none', // 对象尾逗号
  bracketSpacing: true, // 对象字面量的大括号间使用空格
  jsxSingleQuote: false,
  jsxBracketSameLine: false, // false 多行 jsx 中的 > 放在最后一行,而不是另起一行
  arrowParens: 'avoid', // avoid 只有一个参数是否带圆括号
  vueIndentScriptAndStyle: true, // vue文件的script标签和Style标签下的内容需要缩进
  singleAttributePerLine: false, // 在 HTML、Vue 和 JSX 中每行强制执行单个属性
  embeddedLanguageFormatting: 'auto' // 控制 Prettier 是否格式化文件中嵌入的引用代码
};

  1. 在scripts中添加命令
"scripts": {
    "lint": "eslint . --ext .vue,.js,.ts,.jsx --fix",
    "prettier": "prettier --write \"./**/*.{html,vue,ts,js,json,md}\"",
  },

===
还可以集成到提交代码的钩子中。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值