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

code-quality-checker

v1.2.0

Published

A Node.js code quality checker tool

Readme

Code Quality Checker

一个功能强大的基于Node.js的代码质量检查工具,用于全面扫描、分析和评估JavaScript/TypeScript代码质量,帮助团队保持代码一致性并提高代码可维护性。

🌟 项目简介

Code Quality Checker 是一个一站式代码质量解决方案,它集成了多种代码分析工具和规则,能够快速识别代码中的问题、评估代码质量并提供改进建议。

主要价值

  • 提高代码质量:自动检测潜在问题,减少bug和技术债务
  • 保持团队一致性:强制执行统一的代码规范和最佳实践
  • 节省审查时间:自动化检查减轻人工代码审查负担
  • 持续改进:通过质量评分和等级追踪项目质量变化

🚀 功能特性

  • 全面的文件扫描:递归扫描指定目录下的所有代码文件,支持多种文件类型
  • 严格的代码规范检查:集成ESLint和自定义规则,全面检查代码问题
  • 深度代码质量分析:计算代码复杂度、可维护性评分和总体质量等级
  • 多格式报告输出:支持控制台、JSON和HTML三种格式的详细报告
  • 高度自定义配置:通过配置文件灵活调整检查规则和质量阈值
  • 性能优化:高效扫描和分析算法,快速处理大型代码库
  • Vue支持:特别优化了对Vue.js文件的检查和分析

📦 安装

全局安装

适合在多个项目中使用或作为独立工具:

npm install -g code-quality-checker

项目内安装

适合集成到特定项目的开发流程中:

npm install --save-dev code-quality-checker

📋 使用方法

基本使用场景

1. 快速检查当前项目

# 检查当前目录
code-checker .

2. 检查特定源代码目录

# 检查src目录
code-checker ./src

3. 使用自定义配置

# 使用项目根目录下的配置文件
code-checker ./src --config ./code-checker.config.js

4. 生成HTML报告

# 生成详细的HTML报告
code-checker ./src --output html

5. 排除特定目录

# 排除node_modules和测试目录
code-checker ./src --exclude node_modules,test

6. 显示详细信息

# 启用详细输出模式
code-checker ./src --verbose

命令行选项详解

Usage: code-checker [options] <directory>

Arguments:
  directory               要扫描的目标目录(必填)

Options:
  -V, --version           输出版本号
  -c, --config <path>     自定义配置文件路径
  -o, --output <format>   输出格式(console, json, html),默认值: "console"
  -e, --exclude <patterns> 要排除的模式(逗号分隔)
  --verbose               显示详细信息
  -h, --help              显示帮助信息

⚙️ 配置文件

创建一个 code-checker.config.js 文件来自定义工具行为,配置示例:

module.exports = {
  // 支持的文件扩展名
  fileExtensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  
  // 排除的目录和文件
  defaultExcludes: ['node_modules', 'dist', 'build', '.git', 'coverage'],
  
  // ESLint 配置
  eslint: {
    enable: true,
    config: {
      rules: {
        'no-console': 'warn',
        'indent': ['error', 2],
        'semi': ['error', 'always'],
        'quotes': ['error', 'single'],
        'no-unused-vars': 'warn',
        'no-trailing-spaces': 'error',
        'object-curly-spacing': ['error', 'always']
      }
    }
  },
  
  // 代码复杂度配置
  complexity: {
    enable: true,
    maxCyclomaticComplexity: 10,
    maxHalsteadVolume: 100
  },
  
  // 质量等级配置
  qualityGrades: {
    A: { minScore: 90, maxErrors: 0, maxWarnings: 5 },
    B: { minScore: 80, maxErrors: 0, maxWarnings: 15 },
    C: { minScore: 70, maxErrors: 2, maxWarnings: 25 },
    D: { minScore: 60, maxErrors: 5, maxWarnings: 40 },
    F: { minScore: 0, maxErrors: Infinity, maxWarnings: Infinity }
  },
  
  // Vue特定配置
  vue: {
    enable: true,
    templateRules: {
      'no-unescaped': 'error',
      'no-v-html': 'warn'
    }
  },
  
  // 报告配置
  report: {
    showFileSummary: true,
    showDetailedIssues: true,
    highlightErrorLines: true
  }
};

关键配置项说明

  • fileExtensions: 指定要检查的文件扩展名列表
  • defaultExcludes: 默认排除的目录和文件模式
  • eslint.config.rules: 自定义ESLint规则,格式为 规则名: 严重程度
  • complexity.maxCyclomaticComplexity: 最大循环复杂度阈值
  • qualityGrades: 自定义质量等级的评分标准
  • vue: Vue文件的特定检查配置

📊 质量等级说明

工具根据多维度指标对代码质量进行综合评分(0-100分),并划分为以下等级:

| 等级 | 描述 | 评分范围 | 错误限制 | 警告限制 | |------|------|----------|----------|----------| | A级 | 优秀 | 90-100 | 0 | 最多5个 | | B级 | 良好 | 80-89 | 0 | 最多15个 | | C级 | 一般 | 70-79 | 最多2个 | 最多25个 | | D级 | 较差 | 60-69 | 最多5个 | 最多40个 | | F级 | 不合格 | 0-59 | 无限制 | 无限制 |

🔍 检查内容

1. 语法和潜在错误

  • 语法错误和解析问题
  • 未定义变量和引用
  • 类型错误和不一致
  • 不安全的操作和方法

2. 代码风格和规范

  • 缩进和格式化问题
  • 命名规范和一致性
  • 空格、分号、引号使用
  • 代码块结构和嵌套

3. 最佳实践

  • 避免使用已废弃的API
  • 防止内存泄漏的模式
  • 避免常见的反模式
  • 安全编码实践

4. 性能优化

  • 潜在的性能瓶颈
  • 不必要的计算和操作
  • 资源利用效率
  • 异步操作优化

5. 复杂度和可维护性

  • 循环复杂度分析
  • 函数长度和参数数量
  • 代码重复度检测
  • 注释率和文档完整性

📈 报告解读

控制台报告

控制台报告提供简洁的质量摘要和问题列表,适合快速检查。

主要包含:

  • 总体质量评分和等级
  • 问题总数和分类统计
  • 文件级别的问题列表
  • 每个问题的位置、类型和描述

HTML报告

HTML报告是最详细的报告格式,提供交互式的质量分析结果:

主要特点:

  • 项目路径和扫描摘要信息
  • 可视化的质量指标仪表板
  • 详细的文件质量列表
  • 问题的代码上下文和高亮显示
  • 可折叠/展开的详细信息
  • 美观的样式和用户友好的界面

💡 使用场景

CI/CD集成

将代码质量检查集成到持续集成流程中:

# 示例: GitHub Actions 配置
name: Code Quality
on: [push, pull_request]
jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
      - name: Install dependencies
        run: npm install
      - name: Install code-checker
        run: npm install -g code-quality-checker
      - name: Run code quality check
        run: code-checker ./src --output html
      - name: Upload report
        uses: actions/upload-artifact@v2
        with:
          name: quality-report
          path: code-quality-report.html

开发工作流集成

将代码检查添加到开发工作流中:

// package.json 脚本配置
{
  "scripts": {
    "lint": "code-checker ./src",
    "lint:report": "code-checker ./src --output html",
    "precommit": "code-checker ./src --verbose"
  }
}

🛠️ 故障排除

常见问题和解决方案

1. 检查速度慢

  • 减少扫描范围,只检查关键目录
  • 增加排除模式,跳过大型依赖目录
  • 禁用不需要的检查规则

2. 误报问题

  • 在配置文件中调整特定规则的严重程度
  • 对于无法避免的问题,可以在代码中添加特定注释禁用检查

3. 自定义规则不生效

  • 确保配置文件格式正确
  • 检查规则名称和参数是否正确
  • 验证配置文件路径是否正确

4. 内存不足错误

  • 对于大型项目,可以分批检查不同目录
  • 增加Node.js内存限制:node --max-old-space-size=4096 $(which code-checker) ./src

🤝 贡献指南

欢迎贡献代码!请按照以下步骤:

  1. Fork 仓库
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开 Pull Request

📝 许可证

MIT © 2023 Code Quality Checker

📝 更新日志

v1.2.0

  • 内存优化:实现了全面的内存管理优化策略
  • 资源按需加载:优化模块加载机制,减少不必要的内存占用
  • 缓存机制改进:实现LRU缓存,提高资源使用效率
  • 性能监控增强:添加内存使用监控和分析功能
  • 内存泄漏检测:集成内存泄漏检测工具,提高系统稳定性

📞 支持

如有问题或建议,请在GitHub仓库提交Issue或联系项目维护者。