Skip to content

Add shell script formatter #598

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

Merged
merged 1 commit into from
Jun 1, 2025
Merged

Add shell script formatter #598

merged 1 commit into from
Jun 1, 2025

Conversation

ChinYikMing
Copy link
Collaborator

@ChinYikMing ChinYikMing commented May 31, 2025

Leverage shfmt as the standard formatter for shell scripts in this repo.

Summary by Bito

This pull request standardizes shell script formatting by introducing shfmt, enhancing error handling, and improving readability. It includes an EditorConfig file for consistent formatting rules and updates to various scripts for better maintainability.

@ChinYikMing ChinYikMing requested a review from jserv June 1, 2025 03:35
@jserv
Copy link
Contributor

jserv commented Jun 1, 2025

Can you summarize the indention rules used in shfmt?

@ChinYikMing
Copy link
Collaborator Author

@jserv The CI using GCC 14 on the macOS host keeps failing due to a version mismatch (the latest is gcc-15). I'll send a PR to fix it first.

@ChinYikMing
Copy link
Collaborator Author

@jserv Please merge #599 first. Then I will rebase on it to make this pass.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest master branch and squash.

@ChinYikMing ChinYikMing force-pushed the shfmt branch 2 times, most recently from af8cf25 to 10617cb Compare June 1, 2025 06:26
@ChinYikMing
Copy link
Collaborator Author

Can you summarize the indention rules used in shfmt?

Mentioned in the commit messages.

@jserv
Copy link
Contributor

jserv commented Jun 1, 2025

Mentioned in the commit messages.

Move the formatting rules in CONTRIBUTING.md instead.

Leverage shfmt as the standard formatter for shell scripts in this repo.
- add `.editorconfig` with formatting rules and apply shfmt in
  .ci/check-format.sh. The formatting rules are as follows:
  * Use spaces for indentation
  * Indent with 4 spaces
  * Use Unix-style line endings (LF)
  * Remove trailing whitespace at the end of lines
  * Ensure the file ends with a newline
  * Place the opening brace of a function on the next line
  * Indent case statements within switch blocks
  * Add spaces around redirection operators (e.g., >, >>)
  * Place binary operators (e.g., &&, |) on the next line when breaking
    lines
- update CONTRIBUTING.md with formatting rules and usage instructions.
  Contributors must ensure consistent shell script style before code
  submission.

The early exit behavior (set -e) in .ci/check-format.sh has been removed
to allow collecting all formatting mismatches in a single run. The
script’s exit code is now the sum of the line-level mismatch count from
clang-format-18 and the file-level mismatch count from shfmt, which
should be 0 if all files are properly formatted.

All existing shell scripts are reformatted with the formatting rules.
@jserv jserv merged commit 88ddb73 into sysprog21:master Jun 1, 2025
10 checks passed
@jserv
Copy link
Contributor

jserv commented Jun 1, 2025

Thank @ChinYikMing for contributing.
Feel free to submit the similar changes against the projects in sysprog21 organization.

@ChinYikMing ChinYikMing deleted the shfmt branch June 1, 2025 08:03
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.

2 participants