Skip to content

ci: add style check for doc comments #2575

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 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ jobs:
version: "0.19"
args: --check lua

- name: doc-comments
run: ./scripts/doc-comments.sh
16 changes: 16 additions & 0 deletions scripts/doc-comments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

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

I always try to use /bin/sh after I caused a shell compatibility production incident 20 years ago.

However, we need bash features here and we know that CI provides bash so we are OK.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you insist on sh (it's fine either way):

#!/bin/sh

out=$(grep -nr "^--- @" lua)

if [ "$out" ]; then
	last_file=""
	printf %s "$out" | while read -r line; do
		file="$(echo "$line" | cut -d: -f1)"
		if [ "$file" != "$last_file" ]; then
			echo "$file:" >&2
			last_file="$file"
		fi
		echo "$line" | awk -F: '{ printf("  line %s: %s\n", $2, $3) }' >&2
	done
	exit 1
fi

Copy link
Member

@alex-courtis alex-courtis Dec 9, 2023

Choose a reason for hiding this comment

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

Works nicely, shellcheck is happy.

TIL print pipe into while

Edit: let's just go with bash; I'm being finicky


out=$(grep -nr "^--- @" lua)

if [ "$out" ]; then
last_file=""
while read -r line; do
file="$(echo "$line" | cut -d: -f1)"
if [[ "$file" != "$last_file" ]]; then
echo "$file:" >&2
last_file="$file"
fi
echo "$line" | awk -F: '{ printf(" line %s: %s\n", $2, $3) }' >&2
done <<< "$out"
exit 1
fi