-
Notifications
You must be signed in to change notification settings - Fork 28
linting: add shellcheck for shell script lint #756
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
base: main
Are you sure you want to change the base?
Conversation
3b2e198 to
ad1f9e0
Compare
e61a5c5 to
8635352
Compare
hanno-becker
left a comment
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.
Thank you @L-series, in general I think linting the shell scripts is a great idea -- esp. seeing that at least I'm not a shell expert.
However, it looks like some of the quoting has broken scripts/lint, at least the Lint Shell command. Can you have a look, both at the issue itself and why the CI did not catch it?
|
@hanno-becker Hello, please see my comment above regarding what the issue was with the I'm adding a variable which tracks the shells scripts which exist across the project and I pass that to both |
054002b to
67a36aa
Compare
scripts/format
Outdated
| # Find all scripts in the repo | ||
| ALL_FILES=$(git grep -l '' :/) | ||
| SHELL_SCRIPTS=$(echo "$ALL_FILES" | xargs shfmt -f) | ||
| shfmt -s -l -i 2 -ci -fn $SHELL_SCRIPTS |
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.
Why have we lost -w?
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.
Will this work if scripts ever contain spaces in their file names?
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.
Added back the missing -w and fixed the command to use xargs as per the lint script. I've checked and this will not work for files which contain spaces in the filename, however the original implementation also suffers from this issue. The output of renaming lint to lint new and calling shfmt on it:
shfmt -s -w -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/))
lstat scripts/lint: no such file or directory
lstat new: no such file or directory
I'll spend some time tomorrow thinking on how to resolve this.
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.
We could use a loop of the sort to bypass this issue:
git grep -l '' :/ | while IFS= read -r file; do
shfmt -f "$file"
done | while IFS= read -r shellfile; do
shfmt -s -w -l -i 2 -ci -fn "$shellfile"
done
c2209ca to
7482a42
Compare
cf8aca3 to
f2f74f3
Compare
Add linting for shell scripts in the scipts directory as well as any *.sh file accross the project using shellcheck. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
Fix errors brought up by the linter. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
Add linting for shell scripts in the scipts directory as well as any
*.sh file accross the project using shellcheck.