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 🙏

© 2025 – Pkg Stats / Ryan Hefner

comment-analysis

v1.0.1

Published

Code comment rate analysis tool with multi-language support

Downloads

10

Readme

代码注释率统计工具

一个用于统计代码文件中注释率的命令行工具,支持多种编程语言和文件格式。

功能特性

  • 🎯 支持多种文件类型:Vue、JavaScript、TypeScript、JSX、TSX、Python、HTML、CSS、SCSS、LESS、Go、Rust、Java
  • 📊 统计多种注释类型:单行注释、多行注释、行内注释
  • 📈 生成详细的统计表格,包含文件类型、文件数目、注释行数、空行、总行数、注释率
  • 🎨 美观的彩色输出,使用 chalk 库美化
  • 📁 支持递归分析文件夹及其子文件夹
  • 🌍 多语言支持(英文/中文)

安装

方式一:从源码安装

  1. 克隆或下载项目到本地
  2. 安装依赖:
pnpm install

方式二:全局安装(推荐)

npm install -g comment-analysis

使用方法

基本用法

# 分析指定文件夹
comment-analysis /path/to/your/project

# 或者从源码运行
node index.js /path/to/your/project
pnpm start /path/to/your/project

语言选项

# 使用英文(默认)
comment-analysis /path/to/your/project

# 使用中文
comment-analysis /path/to/your/project --lang zh-CN
comment-analysis /path/to/your/project -l zh-CN

示例

# 分析当前目录
comment-analysis .

# 分析特定项目文件夹
comment-analysis /home/user/my-project

# 分析相对路径
comment-analysis ./src

# 使用中文输出分析
comment-analysis . --lang zh-CN

输出示例

开始分析文件夹: /path/to/project
正在分析 3 个文件...

╔═══════════════╤════════════╤════════════╤══════════╤════════════╤═══════════════╗
║ 文件类型      │ 文件数目   │ 注释行数   │ 空行     │ 总行数     │ 注释率        ║
╟───────────────┼────────────┼────────────┼──────────┼────────────┼───────────────╢
║ Vue           │ 1          │ 24         │ 19       │ 141        │ 17.02%        ║
╟───────────────┼────────────┼────────────┼──────────┼────────────┼───────────────╢
║ Python        │ 1          │ 90         │ 33       │ 172        │ 52.33%        ║
╟───────────────┼────────────┼────────────┼──────────┼────────────┼───────────────╢
║ JavaScript    │ 1          │ 25         │ 11       │ 70         │ 35.71%        ║
╟───────────────┼────────────┼────────────┼──────────┼────────────┼───────────────╢
║ 总计          │ 3          │ 139        │ 63       │ 383        │ 36.29%        ║
╚═══════════════╧════════════╧════════════╧══════════╧════════════╧═══════════════╝

注释率说明: 优秀 (>30%) | 良好 (15-30%) | 需要改进 (<15%)

支持的文件类型

| 文件类型 | 扩展名 | 支持的注释类型 | | ---------- | ------ | ------------------------------------------------- | | Vue | .vue | // 单行注释、/* */ 多行注释、 HTML 注释 | | JavaScript | .js | // 单行注释、/* */ 多行注释 | | TypeScript | .ts | // 单行注释、/* */ 多行注释 | | JSX | .jsx | // 单行注释、/* */ 多行注释、{/* */} JSX 注释 | | TSX | .tsx | // 单行注释、/* */ 多行注释、{/* */} JSX 注释 | | Python | .py | # 单行注释、""" """ 多行注释、''' ''' 多行注释 | | HTML | .html | HTML 注释 | | CSS | .css | // 单行注释、/* */ 多行注释 | | SCSS | .scss | // 单行注释、/* */ 多行注释 | | LESS | .less | // 单行注释、/* */ 多行注释 | | Go | .go | // 单行注释、/* */ 多行注释 | | Rust | .rs | // 单行注释、/* */ 多行注释 | | Java | .java | // 单行注释、/* */ 多行注释、/** */ 文档注释 |

统计说明

  • 文件数目: 该类型文件的总数量
  • 注释行数: 包含注释的行数(包括单行注释、多行注释、行内注释)
  • 空行: 完全为空或只包含空白字符的行数
  • 总行数: 文件的总行数
  • 注释率: 注释行数占总行数的百分比

项目结构

comment-analysis/
├── index.js          # 主程序文件
├── package.json      # 项目配置和依赖
├── README.md         # 英文文档
├── README.zh-CN.md   # 中文文档
├── .gitignore        # Git忽略文件配置
└── tests/            # 测试文件文件夹
    ├── README.md     # 测试文件说明
    ├── test-example.js   # JavaScript测试文件
    ├── test-example.vue  # Vue测试文件
    ├── test-example.py   # Python测试文件
    ├── test-example.go   # Go测试文件
    ├── test-example.rs   # Rust测试文件
    └── test-example.java # Java测试文件

依赖项

  • commander: 命令行参数解析
  • glob: 文件模式匹配
  • chalk: 终端颜色输出
  • cli-table3: 美观的表格输出

许可证

MIT License