Skip to content

Add a project .clang-format config file#1053

Open
mhucka wants to merge 3 commits intotensorflow:masterfrom
mhucka:add-clang-format-config
Open

Add a project .clang-format config file#1053
mhucka wants to merge 3 commits intotensorflow:masterfrom
mhucka:add-clang-format-config

Conversation

@mhucka
Copy link
Copy Markdown
Member

@mhucka mhucka commented Apr 17, 2026

Scripts and workflows that run clang-format currently each add the option --style=google to the invocation of clang-format. To follow best practices, this PR adds a .clang-format configuration file at the top level of the project to set the style, and removes the flag from where it was added on the command line explicitly.

The use of a config file has the following benefits:

  • It lets tools like IDEs discover the setting automatically.
  • It reduces the chances that developers will forget to add the flag when they run clang-format directly on the command line for quick checks, or write new scripts that use clang-format.
  • It communicates intentions more clearly to new contributors.

Removing the flag from the scripts is not strictly necessary (everything will work the same if there is both a config file and the flag is passed to clang-format). However, if a config file is used, it's better for maintainability and consistency to also remove the flag from individual invocations.

mhucka added 3 commits April 17, 2026 20:12
With the addition of a `.clang-format` config file at the top level, the
explicit argument on every invocation is no longer necessary.
TensorFlow sets the value the opposite way from the clang-format
default, but TFQ's files have already been formatted using the default
value of the DerivePointerAlignment option. To avoid having to reformat
files needlessly, lets leave this to the default for TFQ.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a .clang-format configuration file based on the Google style and updates the formatting scripts to utilize this local configuration instead of hardcoded style flags. The review feedback identifies a potential issue in the shell scripts where file patterns in the find command are unquoted, which could lead to unintended shell expansion; suggestions were provided to quote these patterns for better robustness.

Comment thread scripts/format_all.sh
Comment thread scripts/format_check.sh
@mhucka mhucka marked this pull request as ready for review April 17, 2026 20:44
@mhucka mhucka requested a review from MichaelBroughton April 17, 2026 20:44
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.

2 participants