Skip to content

Add .clang-format file#3131

Closed
jimying wants to merge 3 commits intopjsip:masterfrom
jimying:clang-format
Closed

Add .clang-format file#3131
jimying wants to merge 3 commits intopjsip:masterfrom
jimying:clang-format

Conversation

@jimying
Copy link
Copy Markdown
Contributor

@jimying jimying commented May 31, 2022

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

@sauwming
Copy link
Copy Markdown
Member

sauwming commented Jun 6, 2022

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.

@jimying
Copy link
Copy Markdown
Contributor Author

jimying commented Jun 6, 2022

@sauwming

I use vscode edit code, it can format the selected code, which will not chang the format of a whole file.

Prepare:

  1. Make sure clang-format command in the PATH
  2. Put .clang-format style file in the root of your project
  3. 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" ^_^

@sauwming
Copy link
Copy Markdown
Member

sauwming commented Jun 6, 2022

Ah, that makes sense.

Unfortunately the .clang-format will fail the rest of PJSIP code :)

jimying added 2 commits June 14, 2022 13:46
modify 'UseTab' style
@sauwming
Copy link
Copy Markdown
Member

We decide to proceed with #3210. Thanks for the suggestion.

@sauwming sauwming closed this Sep 29, 2022
@jimying jimying deleted the clang-format branch February 23, 2023 06:51
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