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

Add AStyle or similiar formatter to repository #52

Open
Broekman opened this issue May 7, 2021 · 4 comments
Open

Add AStyle or similiar formatter to repository #52

Broekman opened this issue May 7, 2021 · 4 comments
Labels
question Further information is requested

Comments

@Broekman
Copy link
Collaborator

Broekman commented May 7, 2021

Add AStyle or similiar to project

An idea to add a default styling "something, e.g. AStyle" to the project to keep formatting aligned?

@Broekman Broekman added the question Further information is requested label May 7, 2021
@jadamroth
Copy link
Collaborator

Do we not have consistent formatting right now?

What is intended:

  1. ClassName{}
  2. functionName()
  3. int localVar = 0;
  4. 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.

@Broekman
Copy link
Collaborator Author

Broekman commented May 7, 2021

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

@jadamroth
Copy link
Collaborator

Got it, yes I think this is a good idea

@JohannesKauffmann
Copy link
Collaborator

JohannesKauffmann commented Aug 2, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants