pjproject
pjproject copied to clipboard
Add .clang-format file
Use clang-format to help format code. It could help contributors and avoid useless code style reviews.
According to Coding Convention.
This only contains basic functions, It can be expanded on this basis, add other features.
#3115
Having a coding convention setting file is a good idea, but after playing around with clang-format, it doesn't seem to suit our need.
This only contains basic functions, It can be expanded on this basis, add other features.
You've pretty much summarised what we also want, which is that if we don't specify a setting, it should be ignored and accepted as is. So for example, if we only want to start with basic indentation convention (such as tab, indent width, and column width) and add more later, we should be able to do that. But with clang-format, if you don't specify a style a default will be chosen, so all style settings will be taken into account during formatting. This triggers a lot of warning for our existing codebase (warning: code should be clang-formatted [-Wclang-format-violations]) for something as simple as trailing whitespace, which is undesirable.
In general, if we are to use a code formatter, it should be clean (or produce only minimal warnings) when we run code-formatter any_PJSIP_codefile.c. So this will help contributors fix their code style since they know that any new warnings must be produced by their modifications.
@sauwming
I use vscode edit code, it can format the selected code, which will not chang the format of a whole file.
Prepare:
- Make sure clang-format command in the PATH
- Put .clang-format style file in the root of your project
- vscode settting property: "C_Cpp.clang_format_style": "file"
Now you can use mouse select some code, and click right, in the menu click "Format Selection" ^_^
Ah, that makes sense.
Unfortunately the .clang-format will fail the rest of PJSIP code :)
We decide to proceed with #3210. Thanks for the suggestion.