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

clang-format support in the project #531

Closed
REmerald opened this issue Jul 26, 2023 · 1 comment · Fixed by #517
Closed

clang-format support in the project #531

REmerald opened this issue Jul 26, 2023 · 1 comment · Fixed by #517
Labels
docs This issue or pull request discusses documentation

Comments

@REmerald
Copy link

Add .clang-format to the root of the project. See the details.

Firstly, it automatically fixes the format mistakes (e.g. see main.c here and here).

Secondly, and most importantly, it tells the contributors the code style they should follow. Even if a contributor doesn't use clang-format, they can just read the .clang-format and learn the project style. And, if a contributor does use clang-format, they won't even have to be bothered with the style, because clang-format can just format the code according to the desired style.

You don't even have to write the file from scratch, instead you can just copy the configuration from the project (but make sure not to break its license) that follows the same/similar coding style and tweak/add/remove some option according to your preference, and voila!

@REmerald
Copy link
Author

REmerald commented Aug 3, 2023

Also, might be a good idea to add compile_commands.json (see details), so that LSPs (e.g. clangd, see the link above) and linters (e.g. solarlint) (inside Neovim or VSCode) can work and help find errors for the contributors.

You can generate it using bear, see the first link and the project page. It must be regenerated when the compilation/linking flags are changed to any of the source/object. But I think the best way to handle the file in the project is to regenerate it each time the changes to makefile are made, or when the new sources are added, just in case. Btw, there's also an interesting alternative compiledb.

Ok, it turns out, some projects are removing compile_flags.json, and I don't know why... But some of the big projects (see in makefiles of ibm-s390-linux/s390-tools, raspberrypi/linux) have the rules to generate them. So, you can add a rule, if you use the compile_command.json yourself. Regardless if you'll do it or not, it will be a good idea to add the file to .gitignore like here; and, btw, maybe negate .clang-format, like here?

@AnErrupTion AnErrupTion linked a pull request Apr 16, 2024 that will close this issue
@AnErrupTion AnErrupTion added feature This issue or pull request discusses a feature docs This issue or pull request discusses documentation and removed feature This issue or pull request discusses a feature labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue or pull request discusses documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants