husky(7.0.0+)+pretty-quick+eslint+commitlint

yarn add @commitlint/config-conventional

yarn add @commitlint/cli

yarn add husky

yarn add pretty-quick

yarn add prettier

注意:最新版husky配置跟旧版本有差别~~~~~~~~~~~~~

https://www.npmjs.com/package/husky

package.json

"scripts":{
 "lintfix": "eslint --config .eslintrc.js --fix --ext .js,.vue ./../pchome --ignore-path .gitignore",
    "prepare": "husky install",
    "pretty": "pretty-quick --staged",
    "commitlint": "commitlint --config .commitlint.config.js -e -V"
}
yarn prepare
npx husky add .husky/pre-commit "yarn pretty"  //每次提交前执行pretty命令
git add .husky/pre-commit
npx husky add .husky/commit-msg "yarn commitlint"  //提交信息拦截
git add .husky/commit-msg

https://www.npmjs.com/package/pretty-quick

.commitlint.config.js

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      [
        'build',
        'ci',
        'chore',
        'docs',
        'feat',
        'fix',
        'perf',
        'refactor',
        'revert',
        'style',
        'test'
      ]
    ]
    // 'subject-full-stop': [0, 'never'],
    // 'subject-case': [0, 'never']
  }
}
//   build:主要目的是修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交
//   ci:主要目的是修改项目继续集成流程(例如 Travis,Jenkins,GitLab CI,Circle等)的提交
//   docs:文档更新
//   feat:新增功能
//   fix:bug 修复
//   perf:性能优化
//   refactor:重构代码(既没有新增功能,也没有修复 bug)
//   style:不影响程序逻辑的代码修改(修改空白字符,补全缺失的分号等)
//   test:新增测试用例或是更新现有测试
//   revert:回滚某个更早之前的提交
//   chore:不属于以上类型的其他类型
/**
 * demo
 * feat: 新增功能
 * */

.editorconfig

# https://editorconfig.org
#此文件的作用是为了防止团队协作时大家所用ide不同导致代码规范不同
# 每次合并代码时带来大量的并没有变化的代码合并和不必要的冲突。
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

.eslintignore

coverage
debug.log
error.log
static
.DS_Store
node_modules/
dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.nuxt

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln

.eslintrc.js

module.exports = {
  root: true,
  plugins: ['vue'],
  env: {
    browser: true,
    node: true,
    commonjs: true,
    jquery: true,
    es6: true
  },
  globals: {
    EASY_ENV_IS_PROD: true,
    EASY_ENV_IS_NODE: true,
    EASY_ENV_IS_BROWSER: true,
    EASY_ENV_IS_DEV: true,
    wx: true,
    uni: true,
    _: true
  },
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    parser: 'babel-eslint'
  },
  extends: [
    'eslint:recommended',
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/recommended',
    'plugin:prettier/recommended'
  ],
  rules: {
    'default-case': 2, //switch语句最后必须有default
    'no-var': 0, //禁用var,用let和const代替
    'no-undef': 1, //不能有未定义的变量
    'no-spaced-func': 2, //函数调用时 函数名与()之间不能有空格
    'no-return-assign': 1, //return 语句中不能有赋值表达式
    'no-script-url': 0, //禁止使用javascript:void(0)
    'no-self-compare': 2, //不能比较自身
    'no-redeclare': 2, //禁止重复声明变量
    'no-multiple-empty-lines': [1, { max: 2 }], //空行最多不能超过2行
    'no-multi-spaces': 1, //不能用多余的空格
    'no-lone-blocks': 2, //禁止不必要的嵌套块
    'no-func-assign': 2, //禁止重复的函数声明
    'no-fallthrough': 1, //禁止switch穿透
    'no-eval': 1, //禁止使用eval
    'no-else-return': 2, //如果if语句里面有return,后面不能跟else语句
    'no-duplicate-case': 2, //switch中的case标签不能重复
    'no-dupe-args': 2, //函数参数不能重复
    eqeqeq: 2, //必须使用全等
    'no-const-assign': 2, //禁止修改const声明的变量
    'max-params': [0, 3], //函数最多只能有3个参数
    'max-statements': [0, 10], //函数内最多有几个声明
    'max-depth': [0, 4], //嵌套块深度
    'new-cap': 2, //函数名首行大写必须使用new方式调用,首行小写必须用不带new方式调用
    'prefer-const': 0, //首选const
    'no-prototype-builtins': 'off',
    'no-debugger': 'off',
    'no-console': 'off',
    // 允许 !! 运算,原本不允许
    'no-extra-boolean-cast': 'off',
    'prettier/prettier': 'off',
    // // 2空格缩进
    indent: ['warn', 2],
    // v-for当中要是用v-if,只能使用for的元素作为条件
    'vue/no-use-v-if-with-v-for': [
      'error',
      {
        allowUsingIterationVar: true // default: false
      }
    ],
    // 忽略 template 中的三元运算符使用小于号(<)时报错
    'vue/no-parsing-error': [
      2,
      {
        'x-invalid-end-tag': false,
        'invalid-first-character-of-tag-name': false
      }
    ],
    // 下面2个都要求是error的,但是暂时没办法改,所以先妥协
    'vue/no-side-effects-in-computed-properties': 'warn',
    'vue/no-async-in-computed-properties': 'warn'
  }
  // "parser": "babel-eslint"
}

.prettierignore

logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
.vscode/
run/
.DS_Store
*.sw*
*.un~
config.json


.prettierrc.js

module.exports = {
  printWidth: 80,
  endOfLine: 'lf',
  // tab缩进大小,默认为2
  tabWidth: 2,
  // 使用tab缩进,默认false
  useTabs: false,
  // 使用分号, 默认true
  semi: false,
  // 使用单引号, 默认false(在jsx中配置无效, 默认都是双引号)
  singleQuote: true,
  // 行尾逗号,默认none,可选 none|es5|all
  // es5 包括es5中的数组、对象
  // all 包括函数对象等所有可选
  trailingComma: 'none',
  // 对象中的空格 默认true
  // true: { foo: bar }
  // false: {foo: bar}
  bracketSpacing: true,
  // JSX标签闭合位置 默认false
  // false: <div
  //          className=""
  //          style={{}}
  //       >
  // true: <div
  //          className=""
  //          style={{}} >
  // 箭头函数参数括号 默认avoid 可选 avoid| always
  // avoid 能省略括号的时候就省略 例如x => x
  // always 总是有括号
  arrowParens: 'avoid'
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值