Skip to content

Commit

Permalink
use set-diff (python instead of bash to get O(n))
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilith Hafner authored and Lilith Hafner committed Oct 16, 2023
1 parent 5265529 commit 23a2de6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/SpellCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ jobs:
--quiet --output-document=- "${RELEASE_ASSET_URL}" \
| tar -xz -C "${{ runner.temp }}/typos" ./typos
"${{ runner.temp }}/typos/typos" --version
git diff-index --name-only --diff-filter=d -z FETCH_HEAD \
| xargs -0 "${{ runner.temp }}/typos/typos" --format json \
| jq --raw-output '"::warning file=\(.path),line=\(.line_num),col=\(.byte_offset)::perhaps \"\(.typo)\" should be \"" + (.corrections // [] | join("\" or \"") + "\".")'
OLD_FILES=$(git diff-index --name-only --diff-filter=ad -z FETCH_HEAD)
NEW_FILES=$(git diff-index --name-only --diff-filter=d -d FETCH_HEAD)
NEW_TYPOS=$(echo -n $NEW_FILES | xargs -0 "${{ runner.temp }}/typos/typos" --format json)
git checkout FETCH_HEAD -- $OLD_FILES
OLD_TYPOS=$(echo -n $OLD_FILES | xargs -0 "${{ runner.temp }}/typos/typos" --format json)
python -c '
import sys, json
existing = set(typo["typo"] for typo in json.loads("["+sys.argv[1].replace("\n", ",")+"]"))
for new in json.loads("["+sys.argv[2].replace("\n", ",")+"]"):
if new["typo"] not in existing:
print("::warning file={},line={},col={}::perhaps \"{}\" should be \"{}\".".format(
new["path"], new["line_num"], new["byte_offset"],
new["typo"], " or ".join(new["corrections"])))' "$OLD_TYPOS" "$NEW_TYPOS"

0 comments on commit 23a2de6

Please sign in to comment.