@cldmv/fix-headers
v1.2.2
Published
Multi-language project header normalizer with auto-detection and override support.
Maintainers
Readme
fix-headers
Multi-language source header normalizer for Node.js projects.
fix-headers scans project files, auto-detects project metadata (language, root, project name, git author/email), and inserts or updates standard file headers.
Features
- Auto-detects project type by marker files (
package.json,pyproject.toml,Cargo.toml,go.mod,composer.json) and YAML files (.yaml,.yml) - Auto-detects author and email from git config/commit history
- Supports per-run overrides for every detected value
- Supports folder inclusion and exclusion configuration
- Supports detector-based monorepo scanning with nearest config resolution per file
- Supports per-detector syntax overrides for line and block comment tokens
- Supports both ESM and CJS consumers
Install
npm i fix-headersUsage
ESM
import fixHeaders from "fix-headers";
const result = await fixHeaders({ dryRun: true });CLI
After install, use the package binary:
fix-headers --dry-run --include-folder src --exclude-folder distLocal development usage:
npm run cli -- --dry-run --jsonCommon CLI options:
--dry-run--json--sample-output--force-author-update--use-gpg-signer-author--cwd <path>--input <path>--include-folder <path>(repeatable)--exclude-folder <path>(repeatable)--include-extension <ext>(repeatable)--enable-detector <id>/--disable-detector <id>(repeatable)--project-name <name>--author-name <name>/--author-email <email>--company-name <name>--copyright-start-year <year>--config <json-file>
CommonJS
const fixHeaders = require("fix-headers");
const result = await fixHeaders({ dryRun: true });API
fixHeaders(options?)
Runs header normalization. Project/language/author/email metadata is auto-detected internally on each run.
Important options:
cwd?: string- start directory for project detectioninput?: string- explicit single file or folder path to processdryRun?: boolean- compute changes without writing filessampleOutput?: boolean- include previous/new header sample text for changed filesconfigFile?: string- load JSON options from file (resolved fromcwd)includeExtensions?: string[]- file extensions to processenabledDetectors?: string[]- detector ids to enable (defaults to all)disabledDetectors?: string[]- detector ids to disabledetectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>- override detector comment syntax tokensincludeFolders?: string[]- project-relative folders to scanexcludeFolders?: string[]- folder names or relative paths to excludeprojectName?: stringlanguage?: stringprojectRoot?: stringmarker?: string | nullauthorName?: stringauthorEmail?: stringcompany?: string- appends to@AuthorasName <Company>forceAuthorUpdate?: boolean- force update@Author/@Emailto detected or overridden current valuesuseGpgSignerAuthor?: boolean- use signed-commit UID (%GS) for detected@Author(includes signer comment when present)companyName?: string(default:Catalyzed Motivation Inc.)copyrightStartYear?: number(default: current year)
Example:
const result = await fixHeaders({
cwd: process.cwd(),
dryRun: false,
configFile: "fix-headers.config.json",
includeFolders: ["src", "scripts"],
excludeFolders: ["src/generated", "dist"],
detectorSyntaxOverrides: {
node: {
blockStart: "/*",
blockLinePrefix: " * ",
blockEnd: " */"
},
python: {
linePrefix: ";;",
lineSeparator: " "
}
},
projectName: "@scope/my-package",
companyName: "Catalyzed Motivation Inc.",
copyrightStartYear: 2013
});Notes
excludeFolderssupports both folder-name and nested path matching.- For monorepos, each file resolves metadata from the closest detector config in its parent tree.
- With
sampleOutputenabled, each changed file includespreviousValue,newValue, anddetectedValuesin results.
License
Apache-2.0
