Thoughts on improving and enforcing coding style
Created by: AMS21
Here are some general ideas to improve coding style.
Implementing these would generally be split into 2 steps.
- Running the option on the entire code base.
- Creating a GitHub workflow which run on every commit/pull request to verify it in the future.
-
Replacing tabs with spaces ref #1477 -
Source files should be encoded with UTF-8 #1480 ref -
Ensuring files don't contain windows-style line endings #1480 Should be automatically handled by .gitattributes but can't hurt to check and enforce. -
Running clang-format #1496 -
Removing trailing white spaces #1477 Not a big problem but look bad IMO ref -
Ensuring files end with a new line #1477 Not required but is kind of the convention with C/C++.
To address one problem immediately. Mass formatting commits tend to mess up the git blame
. But fortunately for this very problem the --ignore-rev
option was created which allows you to ignore certain commits and even load these from a file.
And GitHub supports this commit ignoring out of the box see this.
So all of these mass formatting commits would be added to the .git-blame-ignore-revs
file and should not show up in the git blame. For local use you might have to set it up manually like this.
git config --local blame.ignoreRevsFile ".git-blame-ignore-revs"
What are the community thoughts on this?
I have implemented all of these options in past so it shouldn't be a big problem.