create-zybx-linter

1.1.2 • Public • Published

简介

在任意前端项目中安装本插件,即可自动集成eslint、prettier、commitlint、yorkie,并通过lint-staged进行commit时的代码校验

安装

npm init zybx-linter

支持校验的文件

  • js
  • vue
  • json

开始使用

npm init zybx-linter

问题

  • 请注意当前本地的node版本,不要过低,需大于v14,node过低会出现执行错误

发布

  • package.json中的version版本号变更后,执行以下命令
npm login  “(如已登陆不需要)”
npm publish

说明

  • 通过执行npm init zybx-linter时,自动执行该插件package.json中的bin命令,也就是执行main.js文件
  • 通过cross-spawn将eslint、prettier、commitlint、lint-staged、yorkie等依赖写入目标项目package.json中,并执行install
  • 通过node中的fs模块将eslint、prettier、commitlint、lint-staged、yorkie的配置写入目标项目package.json中

commitlint

限制了只能用如下参数进行提交
  • Feature: 新功能、新需求
  • Fix: 修补bug
  • Release: 发布
  • Reverts: 回滚提交

prettier

module.exports = {
  printWidth: 160,
  tabWidth: 2,
  useTabs: false,
  semi: true,
  singleQuote: true,
  bracketSpacing: true,
  arrowParens: "avoid",
  eslintIntegration: true,
  trailingComma: "none",
  endOfLine: "auto",
};

more refer:https://www.prettier.cn/

eslint

// npm install babel-eslint --save
module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ['plugin:vue/essential', '@vue/prettier', 'plugin:prettier/recommended'],
  parserOptions: {
    parser: 'babel-eslint'
  },
  plugins: ['vue'],
  rules: {
    //'off'或'0':关闭   'warn'或'1':警告   "error"或者"2":报错
    // 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'error',
    'no-console': 'off',
    'no-debugger': 'off',
    'prettier/prettier': 'error'
  }
};

more refer:http://eslint.cn/

packageList

const packageList = [
  '@commitlint/cli@^17.7.1',
  '@commitlint/config-conventional@^17.7.0',
  'cz-git@^1.7.1',
  'babel-eslint@^10.1.0',
  'commitizen@^4.3.0',
  'eslint@^8.48.0',
  'eslint-config-prettier@^9.0.0',
  'eslint-plugin-prettier@^5.0.0',
  'eslint-plugin-vue@^9.17.0',
  'lint-staged@^10.5.4',
  'prettier@^3.0.2',
  'yorkie@^2.0.0'
];

package.json

"lint-staged": {
  "*.{js,vue,json}": [
    "prettier -w"
  ]
},
"config": {
  "commitizen": {
    "path": "node_modules/cz-git"
  }
},
"gitHooks": {
  "pre-commit": "lint-staged",
  "commit-msg": "npx commitlint --edit $1"
}

Package Sidebar

Install

npm i create-zybx-linter

Weekly Downloads

2

Version

1.1.2

License

ISC

Unpacked Size

7.64 kB

Total Files

3

Last publish

Collaborators

  • wangmingzhe