AgentLint 实测验证 100/100基于 259 个 JavaScript 开源仓库统计

    JavaScript CLAUDE.md & AGENTS.md 模板

    ESM/CJS 卫生、Node 原生测试运行器与零冗余依赖纪律,提炼自 259 个 JavaScript 仓库。

    # JavaScript Project — JavaScript Harness
    
    Node.js 22 ESM project tested with `node --test` / Vitest and linted with ESLint.
    
    ## Commands
    
    - Install cleanly: `npm ci`
    - Fast single test: `node --test test/target.test.js`
    - Full suite: `npm test`
    - Lint: `npm run lint`
    
    ## Rules
    
    - Don't use `require()` inside browser-targeted ESM modules. Instead use static ES `import`. Because Vite/Rollup leaks `require` into browser bundles and crashes at runtime.
    - Don't add new runtime dependencies without justification. Instead use Node 22 built-ins (`fetch`, `node:test`, `node:fs/promises`). Because extra packages widen supply-chain risk.
    - When changing CLI arguments, read `docs/cli-spec.md` before editing parsers.
    
    ## Continuity
    
    - Keep `.env` and `CLAUDE.local.md` in `.gitignore` and update `HANDOFF.md` at milestones.

    JavaScript 开源生态中最常采用的工程规则

    基于 4,533 仓库研究中 259 个公开 JavaScript 仓库的实测统计:

    npm工具链

    npm package manager

    43.2%112 个仓库
    react框架

    React for UI

    35.1%91 个仓库
    error-handling代码规范

    Proper error handling with context

    30.5%79 个仓库
    unit-tests测试

    Write unit tests for all changes

    28.6%74 个仓库
    nodejs框架

    Node.js runtime

    27.8%72 个仓库
    docker工具链

    Docker for containerization

    25.1%65 个仓库
    conventional-commits工作流

    Use conventional commit messages

    24.3%63 个仓库
    ci-cd工具链

    CI/CD pipeline must pass

    20.1%52 个仓库
    必写验证命令(对应规则 W1 与 W7)
    安装依赖
    npm ci
    快速单测(秒级迭代)
    node --test test/unit.test.js
    全量测试
    npm test
    Lint 与静态检查
    npm run lint
    生产构建
    npm run build
    JavaScript 项目中 AI 代理常见踩坑
    • 01在浏览器端 ESM 模块里混入 require(),打包后线上运行时报错。
    • 02执行 npm install 而非 npm ci 导致锁文件频繁抖动。

    更多实证验证模板