npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kyfe/kye-crm-gitlint

v1.0.4

Published

git 相关 hook 阶段对代码进行规范性检测以及自动化功能

Downloads

5

Readme

GITLint

GITLint 是一款在代码提交时对变更进行一部分场景检测;代码推送时的一些自动化功能。其中内置了部分检测通用场景,并且提供配置入口供用户自定义功能以及规则。它们是在 pre-commit hookpre-push hook 中执行。

安装和使用

npm install @kyfe/kye-crm-gitlint

代码检测

pre-commit hook 中针对本次变更代码进行一些规范检测

框架已在项目内的 pre-commit hook 中集成了 eslint 校验,我们只需将自定义检测规则添加进去,进入文件 base/packages/lint-staged/index.js 引入并调用即可。

const GITLint = require('@kyfe/kye-crm-gitlint')

...
// 要放在代码最后调用,先进行 eslint 检测,通过后再进行自定义校验
GITLint.start()

自动合并

pre-push hook 中针对相同 commit message 进行自动合并

此功能无需单独引用,GITLint 安装时会自动在项目的子仓库中创建 git pre-push hook 文件并进行引用。

配置

运行 npm install @kyfe/kye-crm-gitlint 成功后,项目根目录下将会生成一个 .gitlintrc 文件,在其中会有一些规则配置如下:

{
  root: true,
  extend: {
    commit: {
      xxx: require('./xxx.js')
    }
  },
  rules: {
    commit: {
      'auth': 'error',
      'css': 'error',
      'complexity': 'error',
    },
    push: {
      'auto-merge-commit': 1
    }
  }
}

配置说明

| 字段 | 字段说明 | 类型 | | -------- | -------- | ------ | | root | 整个功能的开启或关闭 | string、boolean | | extend | 自定扩展功能 | object | | rules | 错误级别以及开启、关闭 | object |

extend 内可以自定义各种检测功能,GITLint 会提供对应的解析函数已经其他内部方法辅助,配置规则:

  1. 项目内任意位置内建新文件处理自定义检测,并在入口文件导出方法,module.exports = checkFun
  2. .gitlintrc 文件内 extend 中对应 hook 下引入,checkFun: require('../xx.js')
  3. GITLint 会在对应 hook 中会拉取配置文件,注册对应事件。

rules 内对各功能可自定义错误级别以及开启、关闭规则:

  • error:强校验,规则不通过拒绝执行下一步;
  • warning:警告,规则不通过仅提示,不阻止执行一下;
  • 1:规则开启;
  • 0:规则关闭;

内置功能

rules.commit.auth

按钮权限检测,kye-buttonel-buttonquery-table 中按钮是否有配置 auth 字段。示例如下

触发校验

<kye-button type="text">新增</kye-button>
<kye-button type="text" auth="">新增</kye-button>

// query-table tools
{
    label: '新增',
    icon: 'plus',
    func: () => {}
}
{
    label: '新增',
    icon: 'plus',
    auth: '',
    func: () => {}
}

不触发校验

// 无需权限按钮可添加 git_ignore_auth 属性进行豁免
<kye-button type="text" git_ignore_auth>新增</kye-button>
<kye-button type="text" auth="BTo2Q1kDyEVJ">新增</kye-button>

// query-table tools
{
   label: '新增',
   icon: 'plus',
   git_ignore_auth: true,
   func: () => {}
}
{
   label: '新增',
   icon: 'plus',
   auth: 'BTo2Q1kDyEVJ',
   func: () => {}
}

rules.commit.css

css 规范检测,根元素 class 命名、style 标签编写规范等(同框架内 css 检测规则)。示例如下:

触发校验

<template>
    <div class="container"></div>
</template>

<style lang="scss">
</style>

<style lang="scss" scoped>
</style>
<style lang="scss">
</style>

不触发校验

<template>
    <div class="crm-kye-price"></div>
</template>


<style lang="scss" scoped>
</style>

rules.commot.complexity

<<<<<<< HEAD

单文件代码认知复杂度检测,检测本次提交代码中单文件复杂度是否超过设置的阈值,暂时内置最大为 150;

push

pre-push hook 中针对 commit 记录自动合并功能

rules.push.auto-merge-commit

======= 单文件代码认知复杂度检测,检测本次提交代码中单文件复杂度是否超过设置的阈值,暂时内置最大为 150;

push

pre-push hook 中针对 commit 记录自动合并功能 push 代码时会自动检测相同的 commit message,将相同的记录自动合并成一个再 push。事例如下:

合并前

合并后

常见问题

安装

1.npm ERR! network request to https://registry.npmjs.org xxx failed, reason: connect ETIMEDOUT xxxx

切换 npm 镜像

npm config set registry https://registry.npmmirror.com

2.rollbackFailedOptional: verb npm-session xxx

是因为上一步安装失败后 npm 正在回滚之前的安装依赖项

// 可先清除 npm 缓存
npm cache clean --force

// 再重新安装
npm install @kyfe/kye-crm-gitlint