Skip to content

fix(headers): text inside an existing header that isn't a header field moves to its own block below the header, never deleted (#160) - #161

Merged
Shinrai merged 5 commits into
nextfrom
fix/header-block-foreign-text
Oct 31, 2026
Merged

Shinrai merged 5 commits into
nextfrom
fix/header-block-foreign-text

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

No other changes

👥 Contributors

…d moves to its own block below the header, never deleted (#160)

A header rewrite replaced the whole matched comment, so description lines and any other non-field text in it were dropped. Those lines are now kept verbatim and in order: with the new strictHeaderBlock option (default true) they go to their own comment block directly below the header, in the file's comment style (block, HTML or # lines); with strictHeaderBlock: false (CLI --no-strict-header-block) they stay inside the header after the fields. Moving them is not a content edit, so @last modified by is kept.
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure type: documentation Relates to docs, README updates, guides, or inline code comments labels Oct 31, 2026
Comment thread src/header/parser.mjs Fixed
…s above a # header; diff covers the moved block (#160)

Review follow-up for the header-block text move:
- A managed tag is a field only the first time it appears in a header comment; a repeated @author or @copyright (a third-party notice) and a dash line among text are kept as text.
- A line directly after a field, indented further or without the comment prefix, is that field's wrapped value and is rewritten with it.
- In a # header, comment lines directly above the first field (coding line, #cloud-config, modelines) stay above the header.
- --diff / --sample-output compare against everything that replaced the old header, so moved text shows as moved, not deleted.
- --strict-header-block [true|false] joins --no-strict-header-block.
- The moved block uses the file's own line ending.
…ly directive lines stay above a # header (#160)

The continuation class deleted text fix-headers did not write (a star-less description, a co-author line, a licence line under @copyright). Every non-field line is now text: moved below the header in strict mode, kept inside it after the fields otherwise. Only directive-shaped lines at the top of a # header (coding declaration, #cloud-config, yaml-language-server and vim/vi/ex modelines) keep their place above it; any other comment line there is header text.
…o it on a later run (#160)

A comment after the header is only absorbed as a stacked header when its first non-empty line is @project:, and a moved block that would start with a @project: line is written with a lead line, so a second strict run no longer reads the moved lines as fields and drops them. Encoding declarations stay above a # header only on the file's first two lines and only as a PEP 263 coding word; vim/vi/ex modelines only at the start of the comment text, so prose such as 'Decoding: base64' or 'like vi: modal' is header text.
@Shinrai

Shinrai commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Ready to merge. Follow-ups are in #162.

@Shinrai
Shinrai merged commit e7f454e into next Oct 31, 2026
28 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/header-block-foreign-text branch October 31, 2026 21:03
cldmv-bot Bot added a commit that referenced this pull request Oct 31, 2026
# `@cldmv/fix-headers` v2.2.3 Changelog

**Release Date**: October 2026
**Release Type**: Patch
**Branch**: `release/2.2.3`

---

## Overview

Version 2.2.3 fixes data loss in a header rewrite. Until now, rewriting an existing header replaced the whole matched comment, so any text in it that was not a header field (a description under `@Copyright`, a co-author or licence line, a line wrapping a field's value) was deleted. A repository-wide run over 756 files removed about 68 such lines from 8 files ([#160](#160)). That text is now always kept, verbatim and in its original order.

By default the kept text moves out of the header into its own comment block directly below it, so the header block holds only header fields. Because there are two reasonable places for that text, the fix comes with a `strictHeaderBlock` setting to choose between them: turning it off (CLI `--no-strict-header-block`, or `--strict-header-block false`) keeps the text inside the header after the fields instead. Either way it is never deleted.

This changes what a run writes to files whose header carries extra text: the first run after upgrading moves that text below the header. Files whose header holds only fields are written exactly as before. The rest of the release is a dependency refresh, including `ignore` 7.0.14 within its existing range.

---

## 🐛 Bug Fixes

### Text inside an existing header is kept, never deleted ([#161](#161), fixes [#160](#160))

Any line in an existing header that is not one of the fields fix-headers writes (`@Project`, `@Filename`, `@Date`, `@Author`, `@Email`, `@Last modified by`, `@Last modified time`, `@Copyright`), a `-----` separator or an empty comment line is now header text, and header text is never dropped. In detail:

- **Text moves to its own block.** With `strictHeaderBlock` (the default), header text is written, comment prefix included, to a comment block directly below the regenerated header, in the file's comment style (`/** … */`, `<!-- … -->` or `#` lines) and with the file's own line ending. The configured `margin` separates the header, the moved block and the rest of the file.
- **Or stays in the header.** With `strictHeaderBlock` off (`"strictHeaderBlock": false` in the config file, `--no-strict-header-block` or `--strict-header-block false` on the CLI) the text stays inside the header after an empty comment line below the fields. The setting is in the `fixHeaders` options type and the `--help` text.
- **Only the first tag is a field.** A repeated `@Author` or `@Copyright` line (a third-party notice, for example) is kept as text instead of being merged into the field. A dash line among text, rather than next to a field, is text too.
- **Wrapped values are kept.** A line that continues a field's value used to be removed when the field was rewritten. Because fix-headers did not write it, it is now kept as text.
- **Directives stay above a `#` header.** Directive lines at the top of a `#` comment stay where they are: a PEP 263 encoding declaration (`# -*- coding: utf-8 -*-`) on the file's first or second line, `#cloud-config`, a `yaml-language-server` comment, and `vim:`/`vi:`/`ex:` modelines at the start of the comment text. Any other comment line there, including prose such as "Decoding: base64", is header text.
- **A second run leaves the moved block alone.** A comment after the header is only absorbed as a stacked copy of the header when its first non-empty line is `@Project:`. A moved block whose first line is itself a `@Project:` line is written with the lead line `Moved out of the file header by fix-headers:` above it, so a later run does not read it back as fields.
- **The edit is not a content change.** Moving text out of the header keeps the recorded `@Last modified by`.
- **`--diff` and `--sample-output` show the move.** The new value covers the header and the block moved below it, so moved text appears as moved rather than deleted.
- **HTML header delimiters.** The closing delimiter of an HTML-comment header is stripped whether it is written `-->` or `--!>`.

Follow-up edge cases found while reviewing this fix are tracked in [#162](#162). They cover `#` headers in files with CRLF line endings or a byte-order mark, a stacked header that starts with text, and `vi:` prose at the very top of a comment.

## 📚 Documentation

- **NEW:** [docs/changelog/v2/v2.2.3.md](./v2.2.3.md): this changelog.
- README: new "Text in the header block" section with a before/after example, and the `strictHeaderBlock` option and CLI flags in the option lists ([#161](#161)).
- README What's New promoted to v2.2.3.

## 🔧 Dependencies

Every entry is a lockfile-only update within the existing `package.json` range; no range changed.

### Runtime

- **`ignore` 7.0.12 → 7.0.14** ([#163](#163)). It is the only dependency fix-headers declares (`^7.0.5`) and is kept external by the build, so a consumer's install already resolves it from that range.

### Development

- **`prettier` 3.9.9 → 3.9.10** ([#144](#144)).
- **`vitest` and `@vitest/coverage-v8` 5.0.3 → 5.0.5**, with `vite` 8.3.2 → 8.3.5, `rolldown` 1.2.12 → 1.2.16 and its platform bindings ([#163](#163)).
- **`@cldmv/vitest-runner` 1.5.3 → 1.5.6** ([#163](#163)).
- **`@cldmv/configs` 1.2.4 → 1.3.0**, the shared config behind this repository's own `fix:headers` run. That run leaves every file unchanged with the new version ([#163](#163)).
- **`eslint` 10.12.0 → 10.14.0**, `@eslint/css` 2.0.1, `@eslint/json` 2.1.1 ([#163](#163)).
- **`@cldmv/jsonv` 1.1.5, `@cldmv/eslint-plugin-jsonv` 1.0.17, `@cldmv/prettier-plugin-jsonv` 1.1.4** ([#163](#163)).
- **`@types/node` 26.6.4 → 26.6.6** ([#163](#163)).
- Development-only transitives, including `postcss` 8.5.32, `nanoid` 3.3.20 and `source-map-js` 1.2.2. These also cover the Dependabot security bumps that had been opened against `hotfixes` ([#163](#163)).

---

## Upgrade notes

- No breaking change to the `fixHeaders` API or the CLI. `strictHeaderBlock` defaults to on, so existing configs need no change.
- **Expect a one-time diff in files whose header carries extra text.** The first run after upgrading moves that text into its own block below the header. Run with `--dry-run --diff` first to review it, or set `"strictHeaderBlock": false` to keep the text inside the header.
- Text that an earlier version already deleted is not recovered; restore it from version control if needed.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-99.5%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 99.9% |
| Branches   | 98.2% |
| Functions  | 100.0% |
| Lines      | 99.9% |

*Avg: **99.5%** · `8ffd077` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch type: documentation Relates to docs, README updates, guides, or inline code comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants