-
Notifications
You must be signed in to change notification settings - Fork 675
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
introducing clang-format #1248
Comments
We can add clang-format if we can create a custom format that doesn't change the entire code base 🤯 clang-format supports 6 predefined styles: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft. I think I went over them before and each one will create tons of changes compared to the style we currently have... |
I think custom clang-format will be great, manually formatting can be problematic and both reviewers and contributors miss some minor things. A simple example, Mixed use of tab and spaces (4 tabs + spaces equivalent for another 4 tabs). Another example is from my PRs which I noticed yesterday, the alignment of public private keyword. Some PRs indent them with spaces but most of the code base not indent them. Probably both of us miss them during merge @seladb |
@egecetin I totally agree! Unfortunately I know there are many formatting issues in the current code base 😕 @egecetin @tigercosmos would you consider working on a custom clang-format style? |
I will find some time to work on this. Let's see how we can customize the style. |
@seladb what's the issue to have one big MR? My experience is that maintaining a custom styles is really painfull and sometimes not properly supported by Clang... |
@clementperon At present, the CI system does not verify the code format, and relying on manual inspection is not consistently reliable. Additionally, with the integration of a code formatter, individuals can effortlessly adhere to the official standard by using IDEs. While acknowledging that a substantial merge request may ensue, I contend that the advantages outweigh the disadvantages. |
Sorry if I was not clear, but I'm 100% in favor to have a clang-format checker in the CI. I'm not convince to have a custom clang-format coding style. IMO I would stick with the LLVM default coding style |
I'm unsure if we're referring to the same "custom style." In this context, the term "custom" style doesn't involve creating new rules; rather, I mean selecting options from the predefined choices offered by clang-format. |
Yes but some rules are working properly but others have sometimes "cross-effect" between them. IMO only predefined styles could be considered as "stable", so if there is one predefined styles that match our needs I will prefer to stuck to it as much as possible. |
@clementperon @tigercosmos the main issue I have is that any predefined clang-format style (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) will cause changes in almost every line in every file, so:
If we have a custom style that is very close to what we currently have, there should be a lot fewer changes and we can enforce this style in the future |
We use scripts to generate code, and we also run the tests, there should be no issues.
I don't think this is a strong support for stopping us, since people can easily check the history before the format.
I agree with @clementperon, following the predefined styles is simpler for unifying the code. Not to mention that the current codebase includes many different coding styles from different people. Yes, a big MR is inevitable, but later on, life becomes easy. |
Since the changes are made by automated scripts, just a quick glance will be enough I think. I'm not sure it will break any code. And unit tests, fuzzers and also compilation itself eliminates a lot of risks. The only problem is "git blame" but it is not a big deal |
I also think that the checksum of the file generated will be identical.
|
If this is true then it's a good way to test the migration script! |
@seladb @clementperon @egecetin I really want to have this feature.
|
@tigercosmos, just to be more clear on my opinion. As we don't have a strong opinion on the coding style, let's enforce with a properly define one and properly supported by clang-format. I'm personally used to the default LLVM one but I think PcapPlusPlus coding style looks like Microsoft coding style. The checksum should be indeed identical if you remove debug symbols, SHA1 and date version info of the build. I can help on that if you need. |
I agree to use "Microsoft", after playing around with LLVM, Google, Webkit, etc, I think it's the most similar to PCPP.
@clementperon Sure, if you can help with this, it will be great. |
@clementperon @tigercosmos do you have an example of how the Microsoft format looks like? |
@seladb Check this site https://zed0.co.uk/clang-format-configurator/ |
Nice!! It does look quite similar to the current formatting |
Seems we all agree with using "Microsoft" for clang-format. That's great. |
Btw, can we get a todo task list on this issue, with which parts are done and which are not? |
Sounds good. Feel free to modify the issue, or I will do it later. |
Added one. I think only Common is formatted right? I checked only that due to the closed PR reference on this issue. |
@Dimi1010 thanks, I added more information. |
Formatting applied to:
Tests
#1456)Tests
#1456)clang-format
for Examples and Tutorials #1464)Tests
#1456)The text was updated successfully, but these errors were encountered: