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
Automated Code Formating #2238
base: master
Are you sure you want to change the base?
Automated Code Formating #2238
Conversation
Initial Commit See formatting/README.md for more details.
|
Sounds like a good idea. Was meaning to try this out already, but still haven't gotten around to it. |
|
@justinclift - good thing you held off. My first swing was a bit "hackish" - just made to work. This is rather "revamped" and I'm more comfortable with the results. This is "almost" something that can be re-fashioned for other projects. But that's so far down the road at the moment... |
Is this going to be very disruptive, i.e. is this going to make a lot of formatting changes when applied? My impression is that we are following more or less, acceptable formatting style. What has concerned me from time to time is naming conventions. There are various conventions for naming files and identifiers. It is evident the hand of different developers without a consensus on that. I was thinking in asking @MKleusberg what are his conventions, because I don't mind following them, but they aren't totally clear to me.
In any case, both for formatting and for naming conventions, I'm not sure whether it is worth the disruption to change all our code. For new code that would be a different matter, and we should start to follow a common convention.
Process doesn't have to be disruptive. As a group, we can decide what does/doesn't work for us. Also why I didn't include results of changes with PR.
When running
I haven't found a tool that can handle c/c++ file naming (python has pylint and flake8).
They are not clear to me either. Late in life and I realize someone has taken the time to document the different layouts for c/c++ files ( see astyle docs page here ). Who knew.
And this is a reasonable assertion. Is there a benefit going forward? Is that benefit worth the cost? |
|
As a neewbie to this code-base I'd have no concerns on code formating for all the code that has been growing over years. As long as it is only formating. Enforcing proper naming on the actual code-base looks risky to me. That feature should be preserved for future changes only. |
|
The only downside of this that really springs to mind, is that we're currently in a release cycle. So when we do stuff in the Formatting changes will definitely screw up the cherry picking. So we'd need to ensure the first merging of "cleaned up" code goes into master after we've done the 3.12.0 release. Or preferably, after the .1 or .2 (which is pretty much always needed That being said, I don't seem a problem with merging this PR itself (ie adding the tooling) in the meantime. |
In other projects, I've seen a "release" branch and a "development" branch. Not sure if that would ease burden but that's a subject of another PR.
I don't see how (but let me think on fallout some more). What jumps to mind is that code should be run through formatting before commit of a PR (ideally). So cherry-picking comes after commit of formatted code. At least that's the workflow I have in my head. Am I missing something @justinclift ? |
Our development branch is
Just due to the code in the Saying "will likely" because I haven't tried it this time around, but I've previously been caught out (way too many times |
There's some residual trauma here I'm not touching... I haven't dug into project release cycle much. I've focused on the "master" branch only. It sounds like latest release is created from an amalgamation of cherry-picks from the "master" and applied to previous latest commit. (yes?) In that case, I would apply code formatting to master and to last release. Then "enforce" (or otherwise encourage others) to apply formatting to PR's before commit to master. In theory, code should be properly formatted when doing cherry picks. This would be a 'one-time' effort as part of implementation, if I'm reading this correctly. |
|
I'll try to test this in the next couple of days or so, just to see how many lines are changed. I agree with what @mgrojo said before that too many changes to the code would be disruptive, also because I really like to use git blame and similar to understand why certain pieces of code were written. As for my code style: it definitely is inconsistent. I try to mimic the style of the part of the code I'm currently editing but also have my own changing style. So we might want to come up with some conventions regarding naming and similar and apply them together with any format changes. |
|
Out of curiosity: why did you choose astyle instead of e.g. clang format? I haven't tried either of them but clang format seems to have some sort of integration into Qt Creator. |
Good question. I had tripped over increasing proliferation of clang-tidy. However, there is the issue of it being only available if clang is installed. Other than Unix environments, that isn't guaranteed. Also influencing the choice was some familiarity with Ultimately, if the group wants to go to clang-tidy, okay. We'll figure out the command line parameters and make happen. For getting going and showing what can/could be done I implemented what I knew worked well. |
|
No worries. I'm fine either way. If nobody bolts in and insists on clang tidy, I'd stick with astyle |
d396227
to
16035be
Compare


Initial Commit
See formatting/README.md for more details.
Inspiration was taken from cppcheck. Project lead has established two shell scripts to automate code formatting. However, shell scripts are for use on either a Unix/Linux platform(
runastyle) or Windows(runastyle.bat). IMHO, maintaining a script for each platform is nothing short of a monumental PITA. The easy way out of the platform trap is to write a single python module to do all the heavy lifting.With a functional framework implemented, a discussion can initiated about implementing some kind of code QA. Intent is not to change project code with this commit but to discuss what applications and settings work best for the group.
When applications/settings are finalized, a singe, large commit can be pushed to the tree with the expectation that going forward all future commits/PR's will be passed through automated code formatting.
In short....we're implementing a project standard.
Feedback and bugs welcomed.