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 🙏

© 2026 – Pkg Stats / Ryan Hefner

git-code-check

v1.0.1

Published

在git commit提交代码的时候,检测提交文件的注释率、重复率

Downloads

305

Readme

git-code-check

在 git commit 提交代码时,检测提交文件的注释率重复率

  • 拦截对象是 git commit 改动的文件(git 暂存区),不做全量扫描
  • 路径参数仅用于限定检测范围:只检测暂存文件中位于这些路径下的改动
  • 注释率:JS 代码中注释行占比(默认要求 ≥ 15%)
  • 重复率:基于 token 级后缀数组 + LCP 算法的代码重复检测(默认 ≤ 10%)
  • 支持 .js / .jsx / .ts / .tsx / .vue;JSX 元素行不计入代码,vue 只统计 <script>

安装

# 方式一:本地项目依赖
npm install git-code-check

# 方式二:全局安装(可在任意目录使用 git-code 命令)
npm install -g git-code-check

# 本地开发时全局链接
npm link

使用

git-code check-comment [路径...] [选项]        # 检测注释率
git-code check-duplication [路径...] [选项]    # 检测重复率

| 子命令 | 路径(限定范围) | 选项 | | --- | --- | --- | | check-comment | 文件/目录,只检测其中 git 改动的文件;不传则检测全部改动文件 | -r, --rate <百分比>(默认 15) | | check-duplication | 同上 | -r, --max-rate <百分比>(默认 10)、-t, --min-token <数量>(默认 50)、-l, --min-lines <数量>(默认 5) |

各子命令详细用法:git-code check-comment --helpgit-code check-duplication --help

# 示例(均在 git 仓库内运行,检测的是暂存区改动的文件)
git-code check-comment                    # 检测全部改动文件
git-code check-comment src/               # 只检测 src/ 下的改动文件
git-code check-comment src/App.jsx -r 20  # 只检测该文件的改动
git-code check-duplication src/ -r 5 -t 30 -l 3

注意:非 git 仓库目录下运行会报错;未暂存(未 git add)的文件不会被检测。

不达标时命令以退出码 1 结束,可在 git hooks 中直接使用:

# .git/hooks/pre-commit
#!/bin/sh
git-code check-comment && git-code check-duplication

本地脚本

npm run check-comment -- src/            # 只检测 src/ 下 git 改动的文件
npm run check-duplication -- src/ -r 5
npm test                                 # 功能测试(临时 git 仓库 + example/ 示例)