hdrnorm is a small Rust command-line utility that rewrites C/C++ #include directives to the preferred delimiter style.
- Converts local includes like
#include "vector"to#include <vector>when the header is a known standard header - Converts system-style includes like
#include <foo.h>to#include "foo.h"for project or third-party headers - Preserves non-include lines and trailing newlines
- Supports
// hdrnorm: keepannotations to preserve a specific include exactly
Build the tool from the repository:
cargo build --releaseThe binary will be available at target/release/hdrnorm.
Check a file without modifying it:
cargo run -- --check src/example.cppRewrite a file in place:
cargo run -- --fix src/example.cppRead from stdin and write formatted output to stdout:
cat src/example.cpp | cargo run -- --stdinRun hdrnorm with --fix to rewrite includes in place:
cargo run -- --fix src/example.cpp#include "vector"
#include <foo.h>
#include <third_party/foo.h> // hdrnorm: keep#include <vector>
#include "foo.h"
#include <third_party/foo.h> // hdrnorm: keepThis repository provides a pre-commit hook manifest at .pre-commit-hooks.yaml.
The hook is configured for language: rust, so pre-commit builds and runs the hdrnorm binary from this repository.
To use the hook from GitHub:
repos:
- repo: https://github.com/RainerKuemmerle/hdrnorm
rev: v0.1.1
hooks:
- id: hdrnormIf you want automatic fixing instead of just checking, use the hdrnorm-fix hook:
repos:
- repo: https://github.com/RainerKuemmerle/hdrnorm
rev: v0.1.1
hooks:
- id: hdrnorm-fixUse pre-commit install in the consuming repository after adding the hook configuration.
If a header should remain exactly as written, add // hdrnorm: keep to the include line:
#include <third_party/foo.h> // hdrnorm: keepThis annotation tells hdrnorm not to change the delimiter style for that include.
This repository includes common Rust project setup files:
Cargo.tomlandCargo.lockfor dependency management.gitignorefortarget, editor swap files, and generated artifactsrustfmt.tomlfor formatting configurationMakefilefor common commands:make build,make test,make fmt,make clippy, andmake clean.github/workflows/rust.ymlfor CI build and test on GitHub Actionsrelease.pyfor version bumping, git tagging, and pushing release metadata
Run the development workflow locally with:
cargo build
cargo test
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warningshdrnormdoes not sort includes; useclang-formator a separate tool for orderinghdrnormrelies on a built-in list of common C++ standard headers and common C-style headers- This repository was built with assistance from GitHub Copilot.
