refactor(packaging): name the arguments, and test the way the rest do - #81
Merged
Merged
Conversation
SonarQube reports 19 issues on this repository and all 19 are in these two files: seven shelldre:S7688 asking for `[[` over `[`, and twelve shelldre:S7679 asking for a positional parameter to be given a name. Both rules are right here, and the reason is not the rules — it is that these two scripts are the only ones in the repository that do not already do what they ask. Every other `.sh` under tools/ and tests/ tests with `[[`, and the shebang here is bash, so `[` was never buying portability it could spend. The names are the same story. `url_for` had already named its two arguments `id` and `ver` — as globals, which leak. Nothing depends on the leak today, and only by accident: the sole caller wraps the call in a command substitution, so the assignments happen in a subshell that never reaches the `for id in "$@"` loop sharing the name. `local` makes that true because of how the function is written rather than because of how it happens to be called. The judgement call is `is_published`, which is a one-line helper whose whole body is a single curl — the shape sonar.yml already excuses for tests/PackageSmokeTest/run.sh. It is named anyway, because the line that excuse actually draws is not one-line-ness: run.sh leaves `$1` alone in `step`, `pass`, `fail`, `get` and `status`, all of which take one argument, and writes `local what="$1" expected="$2" actual="$3"` in `expect`, which does not. `is_published` and `url_for` take two, in an order no call site recovers. So they read like `expect`, and the ignore list in sonar.yml does not grow — nothing is silenced, and the rule keeps reporting in these files. `check` in the test gains the most: it was `[ "$2" = "$3" ]` over a call written `check "…" "$status" 1`, so which side was expected and which was actual could only be learned by going to find out. The comment above it records that its order is the mirror of run.sh's `expect`, since the two are otherwise the same helper. Verified rather than assumed: shellcheck is clean over every tracked `.sh`, the test suite passes, its failure output was checked to still name expected and actual the right way round, deleting the id lowercasing still makes it fail, and the script's own output on a missing package is byte-identical to what it printed before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QTqbBNpEX6L4xGuRH6d7rn
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SonarQube reports 19 open issues on this repository and all 19 are in
tools/packaging/verify-published.shand its test — sevenshelldre:S7688([[over[) and twelveshelldre:S7679(name the positional parameter). Both rules are right here, and the reason is not the rules: these two scripts are the only ones in the repository that do not already do what they ask.Type of change
Changes
[becomes[[at all seven sites. Every other.shundertools/andtests/already tests with[[, and the shebang here is bash, so[was not buying portability it could spend.url_forhad already named its two argumentsidandver— as globals, which leak. Nothing depends on the leak today, and only by accident: the sole caller wraps the call in a command substitution, so the assignments happen in a subshell that never reaches thefor id in "$@"loop sharing the name.localmakes that true because of how the function is written rather than because of how it happens to be called.is_publishedis named too, and it is the judgement call: it is a one-line helper whose whole body is a single curl, the shapesonar.ymlalready excuses fortests/PackageSmokeTest/run.sh. But the line that excuse actually draws is not one-line-ness —run.shleaves$1alone instep,pass,fail,getandstatus, all of which take one argument, and writeslocal what="$1" expected="$2" actual="$3"inexpect, which does not.is_publishedandurl_fortake two, in an order no call site recovers.publishandcheckin the test are named for the same reason.checkgains the most: it was[ "$2" = "$3" ]over a call writtencheck "…" "$status" 1, so which side was expected and which was actual could only be learned by going to find out. A comment above it records that its order is the mirror ofrun.sh'sexpect, since the two are otherwise the same helper.sonar.ymldoes not grow, so both rules keep reporting in these files.Testing
None of the three boxes above are ticked, because none of the three were run and none of them would have measured this change — it touches two shell scripts and no C#, no project file and no packable output. What was run instead:
git ls-files '*.sh' | xargs shellcheck— clean, which is the check CI runs over shell here.tools/packaging/verify-published.test.sh— passes, and it is the real script under test against afile://feed rather than a stub.url_formakes it reportFAIL: both packages on the feed — expected exit 0, got 1, which also shows the newexpected/actualnames are wired the right way round.tools/style/lint-layout.shand thelint-layout/commit-lintself-tests — clean, unaffected.Public API
Documentation
No
CHANGELOG.mdentry: tooling-only commits here do not take one —13e40b5, which created both of these files,17e9ef7and42158ecall left it untouched.Related issues
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QTqbBNpEX6L4xGuRH6d7rn
Generated by Claude Code