Skip to content

Conversation

@L-series
Copy link
Contributor

@L-series L-series commented Dec 1, 2025

Add linting for shell scripts in the scipts directory as well as any
*.sh file accross the project using shellcheck.

@L-series L-series force-pushed the shellcheck branch 2 times, most recently from 3b2e198 to ad1f9e0 Compare December 1, 2025 01:49
@L-series L-series marked this pull request as ready for review December 1, 2025 01:59
@L-series L-series requested a review from a team as a code owner December 1, 2025 01:59
@L-series L-series force-pushed the shellcheck branch 2 times, most recently from e61a5c5 to 8635352 Compare December 1, 2025 15:15
Copy link
Contributor

@hanno-becker hanno-becker left a 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?

@L-series
Copy link
Contributor Author

L-series commented Dec 1, 2025

@hanno-becker Hello, please see my comment above regarding what the issue was with the shfmt syntax. I've changed that syntax and I simplified the logic behind the shellcheck implementation.

I'm adding a variable which tracks the shells scripts which exist across the project and I pass that to both shfmt and shellcheck instead of recomputing it for shellcheck.

@L-series L-series force-pushed the shellcheck branch 3 times, most recently from 054002b to 67a36aa Compare December 1, 2025 20:01
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
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

@L-series L-series Dec 9, 2025

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.

Copy link
Contributor Author

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

@mkannwischer mkannwischer changed the title linting: add shelcheck for shell script lint linting: add shellcheck for shell script lint Dec 3, 2025
@L-series L-series force-pushed the shellcheck branch 5 times, most recently from c2209ca to 7482a42 Compare December 15, 2025 03:27
@L-series L-series force-pushed the shellcheck branch 3 times, most recently from cf8aca3 to f2f74f3 Compare December 23, 2025 22:00
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants