Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate source code formatting with clang-format #185

Closed
iamazeem opened this issue Aug 2, 2024 · 5 comments · Fixed by #190
Closed

Automate source code formatting with clang-format #185

iamazeem opened this issue Aug 2, 2024 · 5 comments · Fixed by #190
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@iamazeem
Copy link
Collaborator

iamazeem commented Aug 2, 2024

Hi,

To automate the source code formatting and to keep it consistent throughout, clang-format can be configured for zsv:

https://zed0.co.uk/clang-format-configurator/ may be used to generate the .clang-format file.
Once .clang-format is added, the users can configure their editors, e.g. VS Code, to format source files automatically (on demand or on save).

The same can be integrated in the CI pipeline as well to enforce a consistent style.
The CI may fail if code is not formatted or it can reformat and commit the formatted files back to repo.
LMK what would be the preferred workflow. I'll update the CI accordingly.

Thanks!

@iamazeem iamazeem added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 2, 2024
@liquidaty
Copy link
Owner

Will review and comment shortly

@liquidaty
Copy link
Owner

Is it possible to start with CI failing if changed code does not conform-- but only for changed code? If so, let's do that.

If not, can we start with having the CI fail if code does not conform, but only for certain specified files? If so, let's do that, starting with src/*.*. We can broaden the scope later.

If none of the above is feasible, will review further and get back to you.

@iamazeem
Copy link
Collaborator Author

iamazeem commented Aug 8, 2024

Both are feasible.

However, I'll recommend to create one single PR first with formatted source code in one go excluding externals libs.
After that, it'll just be the conformance of the new code only.

@iamazeem
Copy link
Collaborator Author

UPDATE

For future changes, https://clang-format-configurator.site/ should be used instead of https://zed0.co.uk/clang-format-configurator.

It supports newer versions and includes other bug fixes.
See its README for a detailed overview.

@iamazeem
Copy link
Collaborator Author

iamazeem commented Sep 20, 2024

UPDATE: By default, clang-format-15 is being used in CI.
It includes the pointer alignment bug fix for struct observed with clang-format-14.
PR: #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants