@cldmv/fix-headers 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,17 +14,18 @@ Headers stay correct without hand-editing: `@Date` follows the file's real creat
14
14
 
15
15
  ## ✨ What's New
16
16
 
17
- ### Latest: v2.2.2 (October 2026)
17
+ ### Latest: v2.2.4 (October 2026)
18
18
 
19
- - **Dependency refresh, nothing the package ships changed** — only `package-lock.json` moves: `ignore` 7.0.10 → 7.0.12 inside its existing range, and development tooling including `@cldmv/vitest-runner` 1.5.3 (which brings `chalk` 6 and a Node.js 22.12 floor), `vitest` 5.0.3, `eslint` 10.12.0 and `globals` 17.13.0. No `package.json` range, API, CLI option or header format changed ([#134](https://github.com/CLDMV/fix-headers/pull/134), [#135](https://github.com/CLDMV/fix-headers/pull/135), [#137](https://github.com/CLDMV/fix-headers/pull/137), [#138](https://github.com/CLDMV/fix-headers/pull/138)).
20
- - [View full v2.2.2 Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.2.md)
19
+ - **One header per file** — stacked copies of a header are merged into one whatever their first line is, repeated fields are dropped, and a stale `@Copyright` for the same holder goes away while one naming another holder is kept and reported in `copyrightWarnings` and as a CLI warning. Only lines that must stay at the top of a file (a shebang, a Python encoding line, `#cloud-config`, `@charset`, Go build constraints, `<?php`, front matter, a Vim modeline) stay above the header, and files where an earlier version wrote the header above one are repaired. `#` headers are found in CRLF and byte-order-mark files. Expect a one-time diff in affected files; review it with `--dry-run --diff` ([#162](https://github.com/CLDMV/fix-headers/issues/162), [#166](https://github.com/CLDMV/fix-headers/pull/166)).
20
+ - **Packaging and hardening** — entry files are `src/index.mjs` and `src/index.cjs`, a source checkout run without the `fix-headers-dev` condition stops with a clear message, the Node.js floor is 22.13.0, and two ReDoS-prone regular expressions are now linear-time scans ([#157](https://github.com/CLDMV/fix-headers/issues/157), [#158](https://github.com/CLDMV/fix-headers/issues/158), [#165](https://github.com/CLDMV/fix-headers/pull/165)).
21
+ - [View full v2.2.4 Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.4.md)
21
22
 
22
23
  ### Recent Releases
23
24
 
25
+ - **v2.2.3** (October 2026) — text inside an existing header that is not a header field is kept instead of deleted, moved to its own block below the header by default (`strictHeaderBlock`), plus a dependency refresh ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.3.md))
26
+ - **v2.2.2** (October 2026) — dependency refresh with nothing the package ships changed: `ignore` 7.0.12 within its range, plus `@cldmv/vitest-runner` 1.5.3, `vitest` 5.0.3, `eslint` 10.12.0 and `globals` 17.13.0 ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.2.md))
24
27
  - **v2.2.1** (October 2026) — development-setup patch: the repository's own `fix:headers` run moves to `@cldmv/configs` 1.2.4, whose shared config no longer forces author updates; nothing the package ships changed ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.1.md))
25
28
  - **v2.2.0** (October 2026) — `@Last modified by` names whoever last edited the file's content: a run that only rewrites a header keeps the recorded editor instead of writing the run's identity ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.0.md))
26
- - **v2.1.4** (October 2026) — strict JSON, Markdown named with `--input` and files with no or an unhandled extension are skipped and reported instead of getting a JavaScript comment; `--input` is repeatable; dependency folders are never walked; `require()` fails clearly where Node.js cannot load ES modules ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.1.4.md))
27
- - **v2.1.3** (October 2026) — CI and development-dependency maintenance with no runtime change: a skipped PR run can no longer satisfy `✅ Required PR Check` and let a pull request merge before its tests finish ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.1.3.md))
28
29
 
29
30
  📚 For complete release notes, see the [docs/changelog/](https://github.com/CLDMV/fix-headers/tree/master/docs/changelog/) folder.
30
31
 
@@ -50,7 +51,7 @@ Headers stay correct without hand-editing: `@Date` follows the file's real creat
50
51
 
51
52
  ### Requirements
52
53
 
53
- - **Node.js 22.12.0 or later** (`engines.node` is `>=22.12.0`).
54
+ - **Node.js 22.13.0 or later** (`engines.node` is `>=22.13.0`).
54
55
  - The package is an ES module and loads with `import` on every supported version. `require("@cldmv/fix-headers")` loads the ES module build synchronously, which needs Node.js ^20.19.0 or >=22.12.0; on older Node.js, use `import()` instead.
55
56
 
56
57
  ### Install
@@ -116,6 +117,7 @@ Common CLI options:
116
117
  - `--check` - validate header dates without writing; exits `1` on date drift (see [Date checks](#-date-checks))
117
118
  - `--fix-created-date`
118
119
  - `--strict-created-date`
120
+ - `--strict-header-block [true|false]` / `--no-strict-header-block` - set `strictHeaderBlock` (on by default); `--no-strict-header-block` (or `--strict-header-block false`) keeps text found in a header that is not a header field inside the header, after the fields, instead of moving it to its own block below (see [Text in the header block](#text-in-the-header-block))
119
121
  - `--normalize-date-format`
120
122
  - `--timezone <name>` - write new header dates in an IANA time zone (see [Time zone](#-time-zone))
121
123
  - `--convert-timezone` - with `--timezone`, also rewrite existing header dates into that zone
@@ -157,6 +159,7 @@ Important options:
157
159
  - `check?: boolean` - validate each existing header's dates and write nothing (implies `dryRun`). Each result entry gets `dateIssues`, and the result gets `filesWithDateDrift` and `dateAdvisories`. See [Date checks](#-date-checks)
158
160
  - `fixCreatedDate?: boolean` - move an existing `@Date` back to the oldest of itself, the file's git first commit, and its filesystem creation time (see [Creation date](#-creation-date)). It only ever moves `@Date` earlier. Off by default: an existing `@Date` is kept as written
159
161
  - `strictCreatedDate?: boolean` - with `check`, count a `@Date` later than the file's git first commit or filesystem creation time as drift (fails the run). Off by default, where it is an advisory
162
+ - `strictHeaderBlock?: boolean` - the header block holds only header fields. On by default: text in an existing header that is not a header field (a description, an unknown `@Tag:` line) is moved, verbatim and in order, to its own comment block directly below the header. `false` keeps it inside the header, after the fields. It is never deleted either way. See [Text in the header block](#text-in-the-header-block)
160
163
  - `normalizeDateFormat?: boolean` - write every header date in the git `%aI` form (`2026-03-01T17:59:32-08:00`), keeping each date's offset and instant. Off by default; the first run rewrites (and restamps) every managed file whose dates use the space form (`2026-03-01 17:59:32 -08:00`)
161
164
  - `timezone?: string` - an IANA time zone name (`America/Los_Angeles`, `UTC`, `Asia/Kolkata`, ...). Every date fix-headers writes (a new header's `@Date`, and `@Last modified time`) is expressed in that zone; the instant and its epoch never change. Unset (the default): dates are written as today. An unknown zone name throws. See [Time zone](#-time-zone)
162
165
  - `convertTimezone?: boolean` - with `timezone`, also rewrite the existing `@Date` and `@Last modified time` values of every header into that zone, keeping each instant. Throws when `timezone` is not set. See [Time zone](#-time-zone)
@@ -185,6 +188,8 @@ Important options:
185
188
  - `spacing?: number` - empty comment lines just inside the header's opening and just before its closing. Default `1`, see [Header layout](#-header-layout)
186
189
  - `margin?: number` - blank lines between the header and the file's next content. Default `2`, see [Header layout](#-header-layout)
187
190
 
191
+ The result's `copyrightWarnings` lists every additional `@Copyright` line a header keeps, as `{ file, copyright }`, and each file's entry in `changes` carries its own as `extraCopyrights` (see [Additional `@Copyright` lines](#additional-copyright-lines)). It is always present, empty when there is nothing to report.
192
+
188
193
  Example:
189
194
 
190
195
  ```js
@@ -421,6 +426,66 @@ With `spacing: 0, margin: 1` the header is compact, with no empty comment lines
421
426
 
422
427
  An existing header is restyled in place to match, so changing either option rewrites the layout of every header on the next run, and a run with unchanged options finds nothing to update. A line-comment header always keeps at least one blank line after it, even with `margin: 0`, so a comment that follows the file's header is not read as part of it.
423
428
 
429
+ The header is written in the file's own line ending: a CRLF file keeps CRLF throughout, header included, and a header an earlier version wrote with `\n` line endings into a CRLF file is rewritten with CRLF. A UTF-8 byte order mark stays at the very start of the file, ahead of the header (and of a shebang), so an existing header after it is found and updated in place rather than a second header being added above it.
430
+
431
+ ### What stays above the header
432
+
433
+ The header is the first thing in the file. A line stays above it only when it is already at the very top of the file (the first line, or part of an unbroken run of such lines from the first line) and moving it below the header would break the file or how its tooling reads it. Nothing further down is ever moved up: a shebang or directive that is not already at the top stays where it is, and the header goes on line 1. Earlier fix-headers versions wrote the header above some of these lines; such a file is repaired. The top of the file is read as one run: the lines already kept at the top (possibly none), then file headers (comments with a `@Project:` or `@Filename:` line) with blank lines between them, then lines that would be kept at the top if they directly followed the first ones. Those lines move up to join the first ones, in order, and the header is rewritten below them, exactly as for a file that had them first (stacked copies merged, text moved, duplicates dropped). So `#!/usr/bin/env python3`, header, `# -*- coding: utf-8 -*-` becomes shebang, coding line, header, and a modeline left below the header after a kept shebang or front matter moves up the same way. A byte order mark an earlier version left below the header goes back to byte 0 the same way. Any other comment or code before those lines means they are not at the top, and nothing is moved.
434
+
435
+ | File type | Kept above the header | Why |
436
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
437
+ | JavaScript / TypeScript | a `#!` shebang on line 1 (any interpreter) | a hashbang is only valid as the first characters of the file |
438
+ | Python | a `#!` shebang on line 1; a PEP 263 encoding declaration (`# -*- coding: utf-8 -*-`) on line 1, or line 2 after line 1 was kept | Python reads the encoding declaration only on the first two lines |
439
+ | Rust | a `#!` shebang on line 1 that is not an inner attribute (`#![...]`), as in cargo scripts | Rust skips such a first line; anywhere else it is a syntax error |
440
+ | YAML | `#cloud-config` on line 1 | cloud-init reads a user-data file as cloud-config only when its first line says so |
441
+ | CSS | `@charset "...";` on line 1 | `@charset` is only read as the very first bytes of a style sheet |
442
+ | Go | `//go:build` / `// +build` constraint lines at the top, with the blank line after them | an old-style `// +build` line only counts before any other kind of comment and when a blank line follows it |
443
+ | PHP | the `<?php` opening tag's line | everything before `<?php` is output as text |
444
+ | Markdown (forced) | YAML front matter (`---` … `---`) | static site generators read front matter only at the top |
445
+ | every type | a vi/Vim/ex modeline (`# vim: set ts=4 sw=4:`, `// vim: ts=2 sw=2 et`, `/* vim: set ts=2: */`, `<!-- vim: set ts=2: -->`) | Vim reads modelines only in the first and last few lines of a file (`modelines`, default 5), so one below the header stops working |
446
+
447
+ A modeline is `vi:`, `vim:` (or `vim600:` and the other version forms), `Vim:` or `ex:` after the comment opener and white space, followed by Vim's own option grammar: `set` / `se` options ending in `:`, or options to the end of the line, where at least one option is `opt=val` or a common boolean such as `et` or `noexpandtab`. Prose such as `# vi: is the editor we use` is not a modeline. Other comment lines at the top, such as a `yaml-language-server` comment (which works anywhere in the file), are header text when they are part of the header's comment, and otherwise stay below the header. A UTF-8 byte order mark is not a line and always stays at byte 0.
448
+
449
+ ### Text in the header block
450
+
451
+ A file has one header. A comment is a file header when it holds a `@Project:` or a `@Filename:` field line (either is enough), and the file's header is its first comment, after what stays above it (see [What stays above the header](#what-stays-above-the-header)), when that comment is a file header. Every file header stacked directly after it (separated only by blank lines) is another copy of it and is merged into it, whatever its first line is and whatever project or file its fields name: its field lines are dropped, the regenerated fields replace them, and its other text is handled like the header's own, in order.
452
+
453
+ The header block is only a header. A line in an existing header (or a copy of it) that is not one of the fields fix-headers writes (`@Project`, `@Filename`, `@Date`, `@Author`, `@Email`, `@Last modified by`, `@Last modified time`, `@Copyright`), a `-----` separator next to a field or an empty comment line is kept, never deleted. A repeated field tag (a second `@Project`, `@Date` or `@Author` line) is a duplicate of the field and is dropped, and so is a `-----` line next to it. A dash line among text is text, and so is a line that wraps a field's value: fix-headers never deletes text it did not write. With `strictHeaderBlock` (the default) those lines move to a comment block of their own directly below the regenerated header, written as they were (comment prefix included) and in their original order, in the file's comment style (`/** … */`, `<!-- … -->`, or `#` lines). Blank lines between two pieces of text are kept, unless a dropped field sat between them. The margin separates the header, that block and the rest of the file:
454
+
455
+ ```text
456
+ /**
457
+ *
458
+ * @Project: @cldmv/example
459
+ * ...
460
+ * @Copyright: Copyright (c) 2026-2026 Example Inc. All rights reserved.
461
+ *
462
+ * What this module does.
463
+ */
464
+ ```
465
+
466
+ becomes
467
+
468
+ ```text
469
+ /**
470
+ *
471
+ * @Project: @cldmv/example
472
+ * ...
473
+ * @Copyright: Copyright (c) 2026-2026 Example Inc. All rights reserved.
474
+ *
475
+ */
476
+
477
+
478
+ /**
479
+ * What this module does.
480
+ */
481
+ ```
482
+
483
+ The moved block holds no `@Project:` or `@Filename:` line (every such line is a field), so it is not a file header and the next run leaves it alone. fix-headers 2.2.3 wrote a lead line, `Moved out of the file header by fix-headers:`, above a moved block that started with a `@Project:` line; such a block still holds that line, so it is merged as a copy of the header and the lead line is dropped with its fields. A lead-line block with no `@Project:` or `@Filename:` line is ordinary text after the header and is left alone. With `"strictHeaderBlock": false` in the config file (CLI `--no-strict-header-block` or `--strict-header-block false`) the lines stay inside the header instead, after an empty comment line below the fields. The moved block uses the file's own line ending, like the header. In `--diff` and `--sample-output` the new value covers the header and the block moved below it, so moved text shows as moved rather than deleted. Moving the text is not a content edit, so it keeps the recorded `@Last modified by`.
484
+
485
+ #### Additional `@Copyright` lines
486
+
487
+ The header's first `@Copyright` line is its own and is rewritten. Any other `@Copyright` line in the header or in a copy of it is compared with the regenerated one by holder: the value without the leading `Copyright`, `(c)` / `©`, the year or year range and a trailing `All rights reserved.`, with white space and case ignored. One naming the same holder (a stale `Copyright (c) 2013-2025 Example Inc. All rights reserved.` next to the new `2013-2026` line) is a duplicate and is dropped. One naming another holder (`Copyright (c) 2010 Mozilla Foundation`) is kept as an additional `@Copyright` field directly under the header's own, in its original order, and reported as a warning: in the result's `copyrightWarnings` (`{ file, copyright }` per line) and the file's `extraCopyrights`, and on the CLI as `warning: <file> keeps an additional @Copyright: <value>` with `warnings=<n>` in the summary. The warning repeats on every run that finds the line, writes nothing on its own and never changes the exit code. A `@Copyright` line in a comment that is not a file header is ordinary text and is left alone.
488
+
424
489
  ---
425
490
 
426
491
  ## ✅ Date checks
@@ -510,6 +575,7 @@ Every other file is skipped and left byte-for-byte unchanged, including when you
510
575
 
511
576
  - **Strict JSON (`.json`)** has no comment syntax, so it never gets a header. A comment would make `package.json` and every other JSON file invalid.
512
577
  - **Files with no extension, or an extension no enabled detector handles** (`.txt`, `.toml`, a disabled detector's extensions, …) are skipped instead of being given a guessed comment.
578
+ - **A PHP file that does not open with `<?php`** (a template starting with HTML) is skipped: a comment at the top would be output as text. A file where only a fix-headers header (and blank lines) comes before `<?php` is not skipped: an earlier version wrote that header there, and it is moved back below `<?php` (see [What stays above the header](#what-stays-above-the-header)).
513
579
  - **Markdown** is skipped unless the `markdown` detector is forced with `--force-detector markdown` (`forcedDetectors: ["markdown"]` in the API or a config file). Naming a `.md` file with `--input` does not force it. A forced header is an HTML comment, which Markdown renderers do not display; it goes below any YAML front matter (`---` … `---`), and later runs update it in place. Forcing applies to discovery too, so a repo-wide run with the option also stamps `README.md` and changelogs; to stamp one file, pass the option together with `--input <file>`. `.mdx` is not covered, because MDX does not accept HTML comments.
514
580
 
515
581
  A skipped file is listed in the result's `skipped` array as `{ file, reason }` and counted in `filesSkipped`, not in `filesScanned` or `changes`. The CLI adds `skipped=<n>` to its summary and prints one `skipped: <file> (<reason>)` line per file: