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

@farisabujolban/stale-comment-guard

v0.1.1

Published

Prevent stale comments by checking Git staged diffs

Readme

stale-comment-guard

A pre-commit hook that blocks commits when code under a leading comment changes but the comment itself does not.

Keeps your comments honest — if the code they describe has changed, the comment must be updated or explicitly approved before the commit goes through.

The problem

// Validates user input and returns true if valid
function processPayment(amount, cardNumber) {  // ← this changed, comment didn't
  ...
}

This commit would be blocked. Either update the comment or run approve to acknowledge the change.

Installation

npm install --save-dev @farisabujolban/stale-comment-guard

Setup

With Husky

npm install --save-dev husky
npx husky init
echo "npx stale-comment-guard check" > .husky/pre-commit

Manual

Add to .git/hooks/pre-commit:

#!/bin/sh
npx stale-comment-guard check

Commands

stale-comment-guard check

Scans staged diffs for stale comments. Exits with code 1 if any are found, blocking the commit.

STALE COMMENT: src/auth.ts:12
  Comment: "// Validates user input and returns true if valid"
  Code changed at line(s) 14–18 but comment was not updated.
  → Run: stale-comment-guard approve src/auth.ts 12

stale-comment-guard approve <file> <line>

Records that you've reviewed the comment and acknowledged the code change. The approval is stored in .commentguard/approvals.json and is invalidated automatically if the comment or its owned code changes again.

stale-comment-guard approve src/auth.ts 12

Configuration

Create .commentguard.json in your project root:

{
  "maxOwnershipDistance": 3,
  "exclude": ["dist/**", "*.generated.ts"]
}

| Option | Default | Description | |--------|---------|-------------| | maxOwnershipDistance | 3 | Max blank lines between a comment and the code it owns | | exclude | [] | Glob patterns for files to skip |

How it works

  • Only checks .js, .jsx, .ts, .tsx files
  • Supports //, /* */, and /** */ comment styles
  • A comment "owns" the code block immediately following it
  • Approvals are tied to a hash of the comment text and the owned code — any change invalidates them

GitHub Actions

Add as a CI check to catch commits that bypassed the local hook:

name: stale-comment-guard
on: [push, pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2
      - run: npx stale-comment-guard check

Commit approvals to git?

Yes — commit .commentguard/approvals.json so your team shares the same approval state.

Add to .gitignore only if you want each developer to manage approvals independently.