Skip to content
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

ci: add spellcheck.dic validation #7062

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,31 @@ jobs:
- uses: actions/checkout@v4
- name: Make sure dictionary words are sorted and unique
run: |
FILE="spellcheck.dic"

# Verify the first line is an integer.
first_line=$(head -n 1 "$FILE")
if ! [[ "$first_line" =~ ^[0-9]+$ ]]; then
echo "Error: The first line of $FILE must be an integer, but got: '$first_line'"
exit 1
fi
expected_count="$first_line"

# Verify the last line is completely empty (no spaces).
last_line=$(tail -n 1 "$FILE")
if [ -n "$last_line" ]; then
echo "Error: The last line of $FILE must be empty (without spaces)."
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this check to avoid the double newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it’s possible to remove the last-line check, but that would change the original design. Currently:

sed '1d;$d' "$FILE"

removes both the first line (the integer) and the last line (which is empty).

To avoid the double-newline issue from the existing approach, we’d need to:

  • Remove only the first line by changing the command to:

    sed '1d' "$FILE"

  • Eliminate the empty line at the end of spellcheck.dic.

  • Remove the check that enforces a trailing empty line.

From a user standpoint, having no trailing empty line can be simpler and less prone to breaking the rules (and thus reduce the need for an extra CI check).

I can add a new commit to this PR with those changes if you agree. Let me know if there’s anything else you’d like to adjust!

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, that sounds good. Let's do that.


# Check that the number of lines between the first and last matches the integer.
# xargs (with no arguments) will strip leading/trailing whitespace from wc's output.
actual_count=$(sed '1d;$d' "$FILE" | wc -l | xargs)
if [ "$expected_count" -ne "$actual_count" ]; then
echo "Error: The number of lines between the first and last ($actual_count) does not match $expected_count."
exit 1
fi

# `sed` removes the first line (number of words) and
# the last line (new line).
#
Expand All @@ -1096,10 +1121,10 @@ jobs:
# environments.

(
sed '1d; $d' spellcheck.dic | LC_ALL=en_US.UTF8 sort -uc
sed '1d; $d' $FILE | LC_ALL=en_US.UTF8 sort -uc
) || {
echo "Dictionary is not in sorted order. Correct order is:"
LC_ALL=en_US.UTF8 sort -u <(sed '1d; $d' spellcheck.dic)
LC_ALL=en_US.UTF8 sort -u <(sed '1d; $d' $FILE)
false
}
- name: Run cargo-spellcheck
Expand Down
3 changes: 2 additions & 1 deletion spellcheck.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
298
299
&
+
<
Expand Down Expand Up @@ -298,3 +298,4 @@ Wakers
wakeup
wakeups
workstealing

Loading