feat!: per-language [[headers]] rules with existingStrategy - #212
Open
hubcio wants to merge 1 commit into
Open
Conversation
Replace the style-keyed [mapping.STYLE] config and useDefaultMapping with a per-language [[headers]] rule list carrying styles (preferred first) and an existingStrategy (replace|skip|error). Fixes korandoru#210: format no longer stacks a duplicate header when a file already has a header in a different comment style. An existing header is detected style-agnostically by a whole-word, case-insensitive scan for the configured keywords. A foreign-but-listed header (e.g. /* */ under a // rule) is migrated to the preferred style, not duplicated. One in an unlisted style, or a stray keyword that cannot be normalized, is left unchanged and reported as "foreign": under existingStrategy=replace this fails the run (exit non-zero) rather than silently passing un-normalized; skip leaves it and exits zero. check adds a "foreign" category; --output JSON gains foreign/skipped/conflict. format and remove now write files atomically (temp, fsync, rename); a symlinked path is replaced by a regular file, and source permissions are preserved on a best-effort basis. BREAKING CHANGE: [mapping.STYLE] blocks and useDefaultMapping are removed. Replace each [mapping.FOO] { extensions = [...] } with a [[headers]] rule carrying styles = ["FOO"], and rename useDefaultMapping to useDefaultHeaders. A 6.x config is rejected with a migration hint. format now exits non-zero when it finds an existing license-looking header it cannot normalize to the preferred style; hawkeye remove's --output "removed" entries are now bare paths (previously path=removed). Tested on downstream hawkeye users by migrating their configs: apache/opendal, datafuselabs/databend and apache/fory match 6.5.1 with no new diagnostics; apache/iggy needs one gitignored file excluded. Closes korandoru#210
Member
|
Thanks for your contribution @hubcio! I'm going to review this patch on the weekend. Feel free to ping me next week if I miss this review. |
tisonkun
self-requested a review
June 28, 2026 07:00
tisonkun
reviewed
Jun 28, 2026
| # Options to configure Git features. | ||
| [git] | ||
| # If enabled, do not process files that are ignored by Git; possible value: ['auto', 'enable', 'disable'] | ||
| # If enabled, do not process files that are ignored by Git AND untracked; a file matched by a |
Member
There was a problem hiding this comment.
Is it? Untracked files that do not ignored should be processed always.
tisonkun
reviewed
Jun 28, 2026
tisonkun
left a comment
Member
There was a problem hiding this comment.
This is a huge PR I just noticed.
Let me review it in the following days.
Actually I'm considering a full rewrite to cover:
- Use
snake_caseoptions always - Drop GitHub Actions support; everyone can use cargo-binstall and run the command as a faster way.
- Rework the integration tests framework.
- Forward quite a few Rust best practices.
That said, I'm taking these on my own. And thanks a lot for @hubcio your patch and nudge to me for finally working on these.
Hopefully I can get all these arranged and delievered in July.
Author
|
Thanks @tisonkun. Let me know if you need any help. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the style-keyed [mapping.STYLE] config and useDefaultMapping
with a per-language [[headers]] rule list carrying styles (preferred
first) and an existingStrategy (replace|skip|error). Fixes #210:
format no longer stacks a duplicate header when a file already has a
header in a different comment style.
An existing header is detected style-agnostically by a whole-word,
case-insensitive scan for the configured keywords. A foreign-but-listed
header (e.g. /* */ under a // rule) is migrated to the preferred style,
not duplicated. One in an unlisted style, or a stray keyword that cannot
be normalized, is left unchanged and reported as "foreign": under
existingStrategy=replace this fails the run (exit non-zero) rather than
silently passing un-normalized; skip leaves it and exits zero. check
adds a "foreign" category; --output JSON gains foreign/skipped/conflict.
format and remove now write files atomically (temp, fsync, rename);
a symlinked path is replaced by a regular file, and source permissions
are preserved on a best-effort basis.
BREAKING CHANGE: [mapping.STYLE] blocks and useDefaultMapping are
removed. Replace each [mapping.FOO] { extensions = [...] } with a
[[headers]] rule carrying styles = ["FOO"], and rename
useDefaultMapping to useDefaultHeaders. A 6.x config is rejected
with a migration hint. format now exits non-zero when it finds an
existing license-looking header it cannot normalize to the preferred
style; hawkeye remove's --output "removed" entries are now bare paths
(previously path=removed).
Tested on downstream hawkeye users by migrating their configs:
apache/opendal, datafuselabs/databend and apache/fory match 6.5.1
with no new diagnostics; apache/iggy needs one gitignored file excluded.
Closes #210