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

@daben/dead-code-checker

v1.0.1

Published

CLI tool to check for dead code in JavaScript and TypeScript files

Downloads

8

Readme

Dead Code Checker

一个基于ESLint的命令行工具,用于检查JavaScript和TypeScript项目中的死代码。

功能特点

  • 检测未使用的变量、导入和函数
  • 检测不可达代码
  • 检测无用的条件表达式
  • 检测空代码块
  • 支持JavaScript和TypeScript文件(.js, .jsx, .ts, .tsx)
  • 递归分析指定目录下的所有符合条件的文件
  • 生成详细的分析报告,包含问题位置的精确坐标
  • 支持多种输出格式(文本和JSON)

安装

npm install -g dead-code-checker

或者在项目中本地安装:

npm install --save-dev dead-code-checker

使用方法

命令行使用

# 检查指定目录
dcc ./src

# 生成JSON格式的报告并输出到文件
dcc ./src --format json --output report.json

# 忽略特定文件或目录
dcc ./src --ignore "**/*.test.js,**/__tests__/**"

命令行选项

  • <directory>: 要检查的目录路径(必需)
  • -o, --output <file>: 输出报告的文件路径(可选)
  • -f, --format <format>: 输出格式,支持 textjson(默认:text
  • -i, --ignore <patterns>: 忽略的文件模式,用逗号分隔(可选)
  • -v, --version: 显示版本号
  • -h, --help: 显示帮助信息

报告示例

文本格式

死代码检查报告

总结:
  检查的文件数: 3
  发现的问题数: 19

src/analyzer.js
  [未使用的变量或参数] src/analyzer.js:106

examples/test-files/example.js
  [未使用的变量或参数] examples/test-files/example.js:4
  [未使用的变量或参数] examples/test-files/example.js:5
  [未使用的变量或参数] examples/test-files/example.js:8
  [未使用的变量或参数] examples/test-files/example.js:11
  [不可达代码] examples/test-files/example.js:20
  [常量条件] examples/test-files/example.js:24
  [未使用的变量或参数] examples/test-files/example.js:25
  [未使用的变量或参数] examples/test-files/example.js:28
  [未使用的变量或参数] examples/test-files/example.js:34
  [未使用的变量或参数] examples/test-files/example.js:37

examples/test-files/a.jsx
  [未使用的变量或参数] examples/test-files/a.jsx:36
  [未使用的表达式] examples/test-files/a.jsx:132
  [未使用的变量或参数] examples/test-files/a.jsx:196
  [未使用的变量或参数] examples/test-files/a.jsx:256
  [未使用的变量或参数] examples/test-files/a.jsx:285
  [未使用的变量或参数] examples/test-files/a.jsx:288
  [常量条件] examples/test-files/a.jsx:301
  [不可达代码] examples/test-files/a.jsx:336

JSON格式

{
  "summary": {
    "totalFiles": 3,
    "totalIssues": 5
  },
  "files": [
    {
      "filePath": "/path/to/project/src/components/Button.jsx",
      "issues": [
        {
          "ruleId": "unused-imports/no-unused-vars",
          "message": "'onClick' is defined but never used.",
          "location": {
            "startLine": 5,
            "endLine": 5,
            "startColumn": 12,
            "endColumn": 19
          },
          "severity": "warning"
        },
        {
          "ruleId": "no-unused-expressions",
          "message": "Expected an assignment or function call and instead saw an expression.",
          "location": {
            "startLine": 15,
            "endLine": 15,
            "startColumn": 3,
            "endColumn": 28
          },
          "severity": "warning"
        }
      ]
    },
    {
      "filePath": "/path/to/project/src/utils/helpers.js",
      "issues": [
        {
          "ruleId": "no-unreachable",
          "message": "Unreachable code.",
          "location": {
            "startLine": 8,
            "endLine": 10,
            "startColumn": 3,
            "endColumn": 4
          },
          "severity": "error"
        },
        {
          "ruleId": "unused-imports/no-unused-imports",
          "message": "'lodash' import is unused.",
          "location": {
            "startLine": 1,
            "endLine": 1,
            "startColumn": 1,
            "endColumn": 24
          },
          "severity": "warning"
        }
      ]
    }
  ]
}

许可证

MIT