#3142 Issue open
: Enable automated source code formatting¶
schlomo opened issue at 2024-01-29 17:42:¶
See also https://github.com/rear/rear/pull/3138#issuecomment-1914584978 for context.
I'd like to be able to use automated source code formatting with ReaR,
and the go-to-tool for that seems to be
shfmt
which is also supported in our .editorconfig
file and in various IDEs
(I'm currently using Visual Studio Code with
https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format).
Our
https://github.com/rear/rear/wiki/Coding-Style
has some rules that conflict with the abilities of this formatter,
specifically adding extra white space or padding around code fragments
or before ;
.
I wasn't able to find a shell script formatting solution that works in the IDEs that allows such a coding style, and I believe that automated consistent formatting is more important. Therefore I'd like to suggest to adjust our coding style to also allow (or demand?) a more compact way of writing Bash and to recommend using a shell script formatter to format the code.
I'm happy to submit the PR with the change that reformats all lines,
although that would kill git blame
and therefore I'd rather prefer
that we reformat files as we work on them.
Personally I'd prefer to not require a "clean" git blame
as a
requirement over consistent and automated code formatting.
What do you think @rear/contributors?
jsmeix commented at 2024-02-09 12:00:¶
Personally I don't worry about coding syntax style differences.
For example personally I don't care if
if CONDITION ; then
...
...
fi
or
if CONDITION
then ...
...
fi
is used because both are reasonably easy
to read and - most important - to understand.
Therefore
https://github.com/rear/rear/wiki/Coding-Style
talks initially about "hints" - not "rules":
Here is a collection of coding hints
that should help to get a more consistent code base.
Don't be afraid to contribute to Relax-and-Recover
even if your contribution does not fully match all this coding hints.
...
Nevertheless try to understand the idea behind this coding hints
so that you know how to break them properly
(i.e. "learn the rules so you know how to break them properly").
The overall idea behind this coding hints is:
Make yourself understood
So as long as it is reasonably easy for me
to understand some code I do not care about
coding syntax style.
For example I prefer spaces as separators
basically everywhere in my code for example as in
if for x in this that ; do echo $x ; done ; then
echo OK
fi
because personally I find that easier to read
than
if for x in this that; do echo $x; done; then
echo OK
fi
But this is really not something which makes
the code needlessly hard to read
so I don't worry about such coding syntax style details.
In contrast for example I think that backticks
make code needlessly hard to read - in particular
when also single quotes are used things look confusing.
jsmeix commented at 2024-02-09 12:03:¶
@schlomo
do you perhaps propose
to run an automated source code formatter
over all existing ReaR code?
[Export of Github issue for rear/rear.]