base-lint CLI
raw JSON →base-lint scans repositories for usage of modern Web Platform features and evaluates them against the Baseline dataset to ensure new features ship with fallbacks. Version 1.2.1 is current, with active maintenance and a GitHub Action for CI integration. Key differentiators include diff-mode analysis (default), Markdown and JSON reports, threshold-based enforcement (base-lint enforce), GitHub Checks annotation (base-lint annotate), and PR comment creation (base-lint comment). It relies on @typescript-eslint/typescript-estree for parsing TypeScript/JavaScript, requiring Node.js 18.17+ or 20.x LTS. Alternatives like Lighthouse or caniuse require external dataset integration, whereas base-lint provides an out-of-the-box CLI with built-in Baseline compliance tooling.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/base-lint/dist/index.js from /path/to/project/index.js not supported. ↓
error Error: Command 'scan' failed with exit code 1: No staged changes found. Use --mode=repo to scan the entire repository. ↓
error TypeScript Error: Cannot find module 'base-lint' or its corresponding type declarations. ↓
Warnings
breaking ESM-only since v1.2.0: package no longer supports CommonJS require(). ↓
deprecated base-lint init --action flag is deprecated; use --github-action instead. ↓
gotcha Diff mode (default) only scans staged changes; uncommitted files are ignored unless --mode=repo is passed. ↓
breakin Removed caching in v1.1.1 due to bundle size bloat; cache support no longer available. ↓
gotcha TypeScript parsing errors may occur with TS versions not supported by @typescript-eslint/typescript-estree. ↓
Install
npm install base-lint yarn add base-lint pnpm add base-lint Imports
- default wrong
const baseLint = require('base-lint')correctimport baseLint from 'base-lint' - scan wrong
const { scan } = require('base-lint')correctimport { scan } from 'base-lint' - enforce wrong
import enforce from 'base-lint/enforce'correctimport { enforce } from 'base-lint'
Quickstart
// Initialize a new base-lint configuration and run a diff scan
import { scan, init, clean } from 'base-lint';
import { writeFileSync, mkdirSync, existsSync } from 'fs';
import { resolve } from 'path';
async function main() {
// Step 1: Initialize config (scaffold .base-lintrc.json, .base-lintignore)
await init({ cwd: process.cwd() });
// Step 2: Scan the current diff (default mode) and get report
const result = await scan({
cwd: process.cwd(),
mode: 'diff', // or 'repo' for full scan
outputDir: '.base-lint-report',
});
console.log('Report generated at:', result.outputPath);
// Step 3: Enforce thresholds (e.g., max violations: 0)
const enforceResult = await enforce({
reportPath: resolve('.base-lint-report/report.json'),
thresholds: { errors: 0, warnings: 5 },
});
if (!enforceResult.passed) {
console.error('Enforcement failed:', enforceResult.violations);
process.exit(1);
}
// Step 4: Clean up report artifacts (optional)
await clean({ outputDir: '.base-lint-report' });
}
main().catch(console.error);