Per file clang-format style definition for multi developer teams (original) (raw)

November 2, 2023, 5:38pm 1

When working in teams, different developers have different style preferences and each developer owns the files they have created. So, in one project, one developer creates the GUI, another MQTT communication, someone else deals with GPIO stuff and each one owns a number of .cpp files.
However, if the file that is owned by developer A, gets a minor modification by developer B, we wouldn’t want to change that style to developer B’s style. We would like to keep that style intact.

In fact, we would suggest to have style file be defined inside the source code that is being formatted.
If the clang-format file mentioned in the source code is not found, just ignore formatting this source code file. We intend to put everyone’s .clang-format file in the repository with the project in the same level with .gitignore and .gitattributes.

Can this be done with the latest version?

example… gpio.cpp

// clang-format style-file=./.clang-format-for-developer-A
int formatted_code;
void formatted_code_again;

Any advice to achieve this or a similar solution is appreciated.

Thanks
//Agron

And you have all these files in the same folder?

agron November 2, 2023, 6:42pm 3

No. Everyone’s files are in ./src folder.