-
Notifications
You must be signed in to change notification settings - Fork 95
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
fix and enforce convention on white-spaces, code-indentation and other coding style #98
Comments
@NikEfth has done some more experiments on issue 1 above (how git handles changes in white-space). Here's his email, essentially saying that as long as we make sure that white-spaces get corrected before any merge, we should be fine.
|
Issue 2: tool/conventions to use I believe that a lot of STIR was formatted with emacs default c++-mode settings (no tabs), but this might have become a minor fraction by now. Nikos used astyle with the following
Another well-known tool is clang-format. This might not do matlab or Python (not sure). |
Issue 3: git integration we'd have to prevent new commits messing things up again, while not making a contributor's life too complicated. There's a lot of tools for this, involving git hooks, server-side stuff etc. Advice sorely needed. Possibly @dvolgyes, @casperdcl can help? Examples used by CMake are at https://gitlab.kitware.com/cmake/cmake. This combines usage of a |
I always have a |
To be explicit, I'd propose:
[attr]cppfiles eol=lf filter=cppfmt
[attr]cfiles eol=lf filter=cppfmt
[attr]pyfiles eol=lf filter=pyfmt
*.cpp cppfiles
*.hpp cppfiles
*.h cfiles
*.c cfiles
*.py pyfiles
---
Language: Cpp
BasedOnStyle: LLVM
Standard: Cpp11
...
[style]
split_before_named_assigns=False
$ git config --global filter.cppfmt.clean clang-format
$ git config --global filter.pyfmt.clean yapf
$ sudo apt-get install clang-format
$ pip install yapf Not sure about linting for matlab files. |
The other advantage of the above is users can easily turn off linting (e.g. if it takes too long): ~/UCL/STIR$ git config --local filter.cppfmt.clean cat And of course if |
Well, there are a lot of technical issues here. First, there is no way to actually prevent a git commit. Period. This is the reason why github has no pre-commit hook. However, you can enforce rules through the pull requests: There are several bots, like the "pep8speaks" which tests the PR, The usual way to enforce special rules, like style, is through continuous integration.
This has the advantage that any tool can be used, even quite specialized one. So what could be incorporated?
I liked astyle more, but uncrustify seems to be more maintained. Theoretically, anything could work. But I would argue for a server-side protection. And the only way I see this Astyle/uncrustify or anything else: there are dozens of similar apps, starting with clang tools, In the end, it depends on the usability, etc. Enforcing clang code formatter Enforcing through Travis is easier, but it has the disadvantage that the actual debugging (figuring out what is wrong with the commit) could be more challenging. (It might be hard to find in the log file.) That's my opinion. (Besides that: I do not really care. I try to keep the current code style of the file, and if I just want to understand the code, then I enforce my own rules, make a patch, and reformat the patch in the old style.) astyle/emacs/vi/eclipse/etc.: It would be nice to choose a universally applicable style but it is not always possible. E.g. tools differ in tiny things, like: do they count the line length from the first character or the first non-whitespace character? (The answer depends on the tool.) |
@dvolgyes I think @KrisThielemans's point was that we want liniting but don't want the casual user to be put off because of it. So my suggestion was to:
|
I have had another read at this. So this looks mostly ok to me. there's 2 things I'd like to get some feedback on:
Anyone wants to create a PR for this? |
I have no useful idea for cleaning up PRs, but there is one for the enforcement part. I was experimenting with the framework, and it is quite OK, e.g. I could write a plugin in 30 minutes which checks image/video/audio file integrity, and rejects corrupted files. First of all, writing plugins is easy, secondly, it does not do anything, unless enabled. It is pretty well designed, multi-platform, and I did not find anything at least similarly capable alternatives. |
By the way, here is a longer list of hooks. I did not find astyle hook, but it shouldn't be too complicated. |
Perhaps a format could be decided upon for new additions to begin with, with no formal enforcement (avoiding discussions on existing files, merges/PRs/forks, enforcement). So far suggested have been astyle, clang-format and uncrustify. flake8 is pretty universal for Python (if you're interested, look at black, but it is too much for here). |
EditorConfig seems pretty good... |
EditorConfig doesn't have quite enough options. E.g.,
|
I've had a brief look at this. It seems that support for My current understanding is that these plug-ins allow you to format a section of code, but they don't set editor settings from the It all sounds daunting again, but we should at least make a baby-step soon. I like @casperdcl's suggestion. Next thing would be to come up with a |
I've played around a bit with
Some motivation:
There's still a large amount of changes moving int
A::
func() (which is a FSF recommendation) to int
A::func() but I didn't find a setting for this, and we're not consistent with this style anyway. Here's the full If anyone has any strong opinions, or finds a setting that changes less things (while still doing something!), feel free to chip-in! |
If clang-format, or any other formatter is used, then i would strongly suggest introducing a pre-commit hook too, Pre-commit is awesome, and i highly recommend it for any and every project. :) There are other hooks too, not just formatting, e.g. cpp-check could check for new code issues, (For me, docker, CI/CD and pre-commit are the top 3 developer tools of the past decade. I am not sure in the order.) |
thanks @dvolgyes looks interesting! If you happen to be able to suggest a small |
Note: the only way I found to download |
Apparently you can do it with Node.js' npm:
|
reopened as we provided the infrastructure but haven't actually cleaned-up the source yet, The intention is to first merge 1 or 2 major PRs. However, developers should already configure their editor to follow the conventions in our |
see #970 |
Current code uses a mixture of conventions from different editors etc. We've had some discussion on this on the stir-devel mailing list, see https://sourceforge.net/p/stir/mailman/message/34996792/.
There's a few issues here:
Following comments address these.
The text was updated successfully, but these errors were encountered: