Skip to content

style: Introduce clang-format configurations for automated enforcement#948

Open
wmthornton-dev wants to merge 1 commit into
RsyncProject:masterfrom
wmthornton-dev:add-clang-format
Open

style: Introduce clang-format configurations for automated enforcement#948
wmthornton-dev wants to merge 1 commit into
RsyncProject:masterfrom
wmthornton-dev:add-clang-format

Conversation

@wmthornton-dev
Copy link
Copy Markdown

@wmthornton-dev wmthornton-dev commented Jun 2, 2026

This commit introduces a formatting pipeline to enforce consistent coding standards across the rsync codebase using clang-format.

The root _clang-format file is configured to enforce the Linux Kernel (K&R) coding style, specifically adapted for rsync's historical baseline and to account for developer habits:

  • 8-character hardware tabs for all indentation
  • 80-column line length limit
  • K&R brace placement (same line for control statements, new line for function definitions)
  • Function names and return types sharing the same line

Additionally, local _clang-format overrides have been added to the popt/ and zlib/ vendored library directories. These files inherit the root Linux structural rules but override the indentation to 4 spaces to respect their specific upstream formatting requirements.

Usage:
To automatically apply the formatting rules and modify the files in-place, run the following command from the root directory:

find . -name "*.c" -o -name "*.h" | xargs clang-format -i

To automatically apply the formatting rules and modify a single file in-place, run the following command from the root directory:

clang-format -i <path/to/file>

To validate code compliance without modifying the files (for use in pre-commit hooks or CI pipelines), run the dry-run command:

find . -name "*.c" -o -name "*.h" | xargs clang-format --dry-run --Werror

To validate code compliance for a single file, without modification, run the dry-run command:

clang-format --dry-run --Werror <path/to/file>

This commit is designed to work in conjunction with .editorconfig files but can be used standalone.

Signed-off by: Wayne Michael Thornton wmthornton-dev@outlook.com

This commit introduces a formatting pipeline to enforce consistent
coding standards across the rsync codebase using clang-format.

The root `_clang-format` file is configured to enforce the Linux Kernel
(K&R) coding style, specifically adapted for rsync's historical baseline
and to account for developer habits:
- 8-character hardware tabs for all indentation
- 80-column line length limit
- K&R brace placement (same line for control statements, new line
  for function definitions)
- Function names and return types sharing the same line

Additionally, local `_clang-format` overrides have been added to the
`popt/` and `zlib/` vendored library directories. These files inherit
the root Linux structural rules but override the indentation to 4 spaces
to respect their specific upstream formatting requirements.

Usage:
To automatically apply the formatting rules and modify the files in-place,
run the following command from the root directory:

    find . -name "*.c" -o -name "*.h" | xargs clang-format -i

To automatically apply the formatting rules and modify a single file
in-place, run the following command from the root directory:

    clang-format -i <path/to/file>

To validate code compliance without modifying the files (for use
in pre-commit hooks or CI pipelines), run the dry-run command:

    find . -name "*.c" -o -name "*.h" | xargs clang-format --dry-run --Werror

To validate code compliance for a single file, without modification, run
the dry-run command:

   clang-format --dry-run --Werror <path/to/file>

This commit is designed to work in conjunction with .editorconfig files
but can be used standalone.

Additionally, a proposed STYLEGUIDE.md file is included in the root
directory for publishing where appropriate.

Signed-off by: Wayne Michael Thornton <wmthornton-dev@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant