-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
contributing: Add clang-format shell script #2732
Conversation
I have tested the script on my Fedora 36 box (in order to update an existing PR) but
It seems the regex needs another tweak for (Linux) GNU findutils. |
Seems GNU find uses emacs regex by default. Please try: find . -type f -regextype posix-extended -iregex '.*\.(cpp|hpp|c|h)' |
Yes, the modified version appears to work with GNU find: find . -type f -regextype posix-extended -iregex '.*\.(cpp|hpp|c|h)' | wc -l
3357 |
Good! Updated accordingly. |
Almost there... (GNU find here): sh -x grass_clang_format.sh db
+ set -eu
...
+ find db -type f '-regextype posix-extended -iregex' '.*\.(cpp|hpp|c|h)' -exec clang-format -i '{}' +
find: unknown predicate `-regextype posix-extended -iregex'
|
With un-quoting |
I have the same problems using Unquoting $regex causes shellcheck to complain: shellcheck ./utils/grass_clang_format.sh
In ./utils/grass_clang_format.sh line 85:
${find} "${dir}" -type f ${regex} '.*\.(cpp|hpp|c|h)' -exec \
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
|
Here it doesn't:
|
Always these minor differences. Let's use standard find and skip regular expression. Probably the safest way. |
Great, now it works also for me! Just a glitch I spotted (shall I open a new issue?) - the header formatting is a bit distorted. This happens in the cmake related PR which I am trying to update:
|
That's good news!
I went through all files manually (in addition to clang-format) in the big formatting commits, removing remaining tabs in comments and fixed the above mentioned headers (hopefully all) where it was needed. Because of this, If there are no changes to the header in the PR, then you should leave this hunk as is (as it is good in main). |
I should add: It is best to only apply clang-format to the files in a particular PR that are modified (and not to the whole source dir). |
Good point. BTW: This would be a trick to easily list the files changed in a PR (source: https://stackoverflow.com/a/68682405/452464):
Only those then would undergo the |
Is this still useful with pre-commit? (Just trying to clean up the 8.3.0 milestone.) |
As long as pre-commit is not a requirement (and/or we use pre-commit-ci), then this might be useful for those who for whatever reason do not want to install pre-commit (and simplify their lives :). My intention was to replace the now obsolete grass_indent.sh. |
Okay, let's make this available. We want to make it easy, so an alternative is good. Can you please delete the old indent files? |
It is useful since pre-commit is, as far as I can see, yet heavily underused (also note to self). |
You can run |
The clang-format shell script replaces the grass_indent.sh and grass_indent_ALL.sh scripts, which are both hereby removed.
The clang-format shell script replaces the grass_indent.sh and grass_indent_ALL.sh scripts, which are both hereby removed.
Adds a grass_clang_format.sh script.
Usage:
If you have clang-format in PATH, execute for complete source formatting:
./utils/grass_clang_format.sh
Setting 'GRASS_CLANG_FORMAT' to explicitly set clang-format binary (its naming can depend on how various
distributions name it):
GRASS_CLANG_FORMAT="clang-format-15" ./utils/grass_clang_format.sh
It is also possible to format the content in a (one) given directory:
./utils/grass_clang_format.sh ./lib/raster