-
Notifications
You must be signed in to change notification settings - Fork 0
Package per-language codestyle sections as Skills #680
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| name: shell-codestyle | ||
| description: >- | ||
| Governs Bash/shell script style for ptr727/ProjectTemplate fleet repos: when a bootstrap or | ||
| host-tool script may be shell instead of Python, the mandatory set -Eeuo pipefail header, the | ||
| pipefail-versus-early-reader pitfall, self-locating scripts, shellcheck cleanliness, and the | ||
| why-not-what comment rule. Use this whenever writing, reviewing, or editing a .sh file, whenever | ||
| deciding whether a new script should be Bash or Python, or whenever a pipeline built from | ||
| `curl`/`grep`/`jq`-style commands looks like it silently swallowed a failure. Triggers even when | ||
| the task looks like a one-line tweak to an existing script, because a missing `-e`/`pipefail`, | ||
| or a reader piped straight from a producer that closes the pipe early, are each invisible until | ||
| the exact failure mode they guard against actually happens. Fleet-wide: a shell script can | ||
| appear in any repo (a bootstrap that installs the interpreter, a host tool that must run before | ||
| a toolchain exists), not only a repo whose primary language is shell. | ||
| --- | ||
|
|
||
| # Shell Codestyle | ||
|
|
||
| ## Why this exists | ||
|
|
||
| This is the shell-specific half of the fleet's code style guide, kept in one place instead of | ||
| re-derived per repo or per session. Shell is the fleet's exception language, reached for only | ||
| where Python cannot run yet, so its rules exist to keep that narrow surface safe rather than to | ||
| cover general scripting style. | ||
|
|
||
| ## When shell, not Python | ||
|
|
||
| Bash, and only where a program cannot be Python: a bootstrap that installs the interpreter cannot | ||
| be written in it, and a host tool that must run before a development toolchain exists cannot | ||
| depend on one. Everything else is Python, with a test beside it. | ||
|
|
||
| ## Rules | ||
|
|
||
| - **`set -Eeuo pipefail`, before the first command the script runs.** A header comment sits above | ||
| it, as `repo-config/configure.sh` and the `host-setup/` scripts do, since what matters is that | ||
| nothing executes unguarded rather than which line number it lands on. Without `-e` a failed | ||
| command in the middle of a sequence lets the rest run against a state nobody checked, and | ||
| without `pipefail` a pipeline reports the exit of its last stage, so a fetch that failed reads | ||
| as an answer when a parser downstream succeeds on an empty input. `-E` carries an `ERR` trap | ||
| into functions and command substitutions, so a script that later adds one is not surprised by | ||
| where it does not fire. | ||
| - **A reader that stops early needs its producer read first.** Under `pipefail`, a producer | ||
| writing to a closed pipe exits non-zero, so `curl ... | grep -q` reports a successful fetch as | ||
| a failure whenever the match is found early enough. Capture the output, then search it. | ||
| - **Self-locating, never dependent on the caller's directory.** A script resolves its own | ||
| directory from `BASH_SOURCE` and references its payloads through it, since the working | ||
| directory at invocation is not a property of the script. | ||
| - **`shellcheck` clean, and a deliberate exception carries its reason inline.** A | ||
| `# shellcheck disable=SCxxxx` names why the rule does not apply here, so the next reader can | ||
| tell a considered exception from an unread warning. `repo-config/configure.sh` is the worked | ||
| example, carrying five `SC2016` disables where a single-quoted `jq` program must stay | ||
| unexpanded, each with its reason on the same line. | ||
| - **Comments say why, never what.** The code states what it does. A comment restating it goes | ||
| stale silently, where a comment carrying a reason fails visibly when the reason stops being | ||
| true. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 5d298d74098bac47 | ||
| d2ea6560beea37fd |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.