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
Add a step to CI to check files have been formatted with shfmt #1232
Conversation
This is needed to exit with a non-zero exit code when there is a diff.
67efe49
to
545ed67
Compare
@@ -42,8 +42,7 @@ if ! docker run \ | |||
--pull=never \ | |||
--rm \ | |||
"tonistiigi/binfmt@${QEMU_BINFMT_DIGEST}" \ | |||
--install all | |||
then | |||
--install all; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit unfortunate, I would prefer if the formatter did not do this, but I don't consider it important enough to be fatal to the goal of having a formatter.
Luckily, to mitigate potential confusion between the end of the conditional and start of the body of the if statement, most text editors will highlight the then
with coloured crayon technology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
To reduce loss of productivity due to debates about the formatting of shell scripts, I've added a formatting check to the CI that uses shfmt to detect script that are not formatted in accordance with it. This complements the existing checking of lints using shellcheck.
The options I've supplied to
shfmt
are:--indent 2
to use 2 spaces for indentation. This matches our conventions for languages other than go.--binary-next-line
which allows binary operators onto the next lineIf we didn't specify this, the first good example will be formatted to be like the first bad example, which I consider to be less readable as it requires reading to the end of the first line to see what the binary operator is, and is confusing as it does not use a line continuation at all.