nimbuscontrols / EIPScanner

Free implementation of EtherNet/IP in C++
https://eipscanner.readthedocs.io/en/latest/
MIT License
233 stars 93 forks source link

Add AStyle or similiar formatter to repository #52

Open Broekman opened 3 years ago

Broekman commented 3 years ago

Add AStyle or similiar to project

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

jadamroth commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Got it, yes I think this is a good idea

JohannesKauffmann commented 2 years ago

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.