0.0.3 • Published 2 years ago

xybot-front-standard v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

影刀规范配置项目

整合各个业务项目间的统一的规范配置文件,

业务项目配置方式

大前提,先安装xybot-front-standard

npm i xybot-front-standard -D

eslint

  1. 在项目根目录下新建 .eslintrc.js
  2. 配置如下

    const eslint = require('xybot-front-standard/lint/eslint');
    
    module.exports = {
        ...eslint,
    };
    // 干净的eslint规范
    // module.exports = {
    //   root: true,
    //   parser: '@typescript-eslint/parser',
    //   env: {
    //     browser: true,
    //     node: true,
    //     es6: true,
    //   },
    //   globals: {
    //     // Your global variables (setting to false means it's not allowed to be reassigned)
    //     //
    //     // myGlobal: false
    //   },
    //   rules: {
    //   },
    // };

stylelint

  1. 在项目根目录下新建 .stylelintrc.js
  2. 配置如下

    const stylelint = require('xybot-front-standard/lint/stylelint');
    
    module.exports = {
        ...stylelint,
    };

commitlint 与 pushlint

  1. pakage.json 中配置
      "husky":{
        "hooks":{
            "pre-commit": "lint-staged",
            "commit-msg": "node ./node_modules/xybot-front-standard/lint/commitlint"
        }
    },
    先不加入:"pre-push": "node ./node_modules/xybot-front-standard/lint/pushlint"
  2. pacage.json script中补充
    "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
    "lint-staged": "lint-staged",
    "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
    "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
    "lint:js": "cross-env TIMING=1 eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
    "lint:prettier": "prettier --check \"**/*\" --end-of-line auto",
    "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less"
  3. pacage.json 中补充
    "lint-staged": {
    "*.{md,json}": [
      "prettier --write",
      "git add"
    ],
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix --ext .js,.jsx,.ts,.tsx --format=pretty",
      "prettier --write",
      "git add"
    ],
    "*.{less,css}": [
      "stylelint --fix --syntax less",
      "prettier --write",
      "git add"
    ]}

注意