Add AStyle or similiar formatter to repository
Broekman opened this issue · 4 comments
Add AStyle or similiar to project
An idea to add a default styling "something, e.g. AStyle" to the project to keep formatting aligned?
Do we not have consistent formatting right now?
What is intended:
- ClassName{}
- functionName()
- int localVar = 0;
- int _privateVar = 0;
I prefer to not break any backwards compatibility without releasing a new major version, but let me know what you see/think, and I'm open on having consistent styling.
Hi Adam,
I mean things like spaces, bracket positioning, line-width etc... The things you mentioned are left untouched. My editor keeps somewhat shifting the formatting to my own settings and I have to keep adjusting this. Perhaps as a pre-commit hook or something.
I generally use something like this (.astylerc)
# Allman style formatting/indenting uses broken brackets.
style=allman
mode=c
# Indent using 2 spaces per indent
indent=spaces=2
indent-preproc-block
indent-preproc-define
indent-col1-comments
indent-classes
indent-namespaces
#Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block. The entire case block is indented.
indent-switches
#Indent 'case X:' blocks from the 'case X:' headers. Case statements not enclosed in blocks are NOT indented
indent-cases
max-instatement-indent=120
#Insert space padding around operators
pad-oper
#Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...)
pad-header
#Remove extra space padding around parenthesis on the inside and outside.
unpad-paren
#Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...).
add-brackets
#Converts tabs into spaces in the non-indentation part of the line.
convert-tabs
#Attach a pointer or reference operator (* or &) to either the variable type (left) or variable name (right), or place it between the type and name (middle)
align-pointer=type
align-reference=type
break-after-logical
#Do not retain a backup of the original file.
suffix=none
preserve-date
recursive
Got it, yes I think this is a good idea
For basic options, such as tabs vs spaces, newlines, tab size etc, I think EditorConfig could be used. The upside is that it works while you type (in any supported editor, at least) and not after you type (ctrl+s).
For C++-specific options, such as pointer- or reference aligment, clang-format looks like a good choice. I don't know if the codebase can be formatted satisfactorily, however - ATM I'm experimenting with this.
Edit: we could even run clang-format in CI after #50.