Skip to content

Commit

Permalink
Add CI checks against todo comments without issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoyuu committed Dec 8, 2022
1 parent a3eaacf commit 319321b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/minimal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
# Don't use more features like "gdnative_bindings_generator/debug" to keep CI truly minimal
GDRUST_FEATURES: "gdnative/async,gdnative/serde"

RIPGREP_VERSION: "13.0.0"

on:
pull_request:
branches:
Expand Down Expand Up @@ -52,6 +54,19 @@ jobs:
- name: "Check clippy"
run: cargo clippy --workspace --features ${GDRUST_FEATURES} -- -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented

check-todo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Install ripgrep"
run: |
cd /tmp
wget --no-verbose https://github.com/BurntSushi/ripgrep/releases/download/${RIPGREP_VERSION}/ripgrep-${RIPGREP_VERSION}-x86_64-unknown-linux-musl.tar.gz -O ripgrep.tar.gz
tar -zxvf ripgrep.tar.gz
sudo mv ripgrep-${RIPGREP_VERSION}-x86_64-unknown-linux-musl/rg /usr/bin
- name: "Look for TODO comments without issue numbers attached to them"
run: sh tools/detect-todo.sh

unit-test:
runs-on: ubuntu-latest
steps:
Expand Down
75 changes: 75 additions & 0 deletions tools/detect-todo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/bash

# Small utility to detect todo comments
# Used by godot-rust developers

REGEX='(?<!clippy::)(TODO|FIXME)(?!!\(\)|[a-zA-Z]|\((#|(\w+/)+)\d+\))'

# Self test

TEST_OUTPUT=$(rg -i --pcre2 "$REGEX" <<EOF
# Should hit - Naive
todo
TODO
fixme
FiXmE
reallytodo
trulyfixme
# Should hit - Malformed
todo123
fixme123
TODO(123)
TODO(/////)
TODO(T123)
# Should not hit - With issue numbers
todo(#123)
todo(foo/bar/123)
fixme(#123)
fixme(foo/bar/123)
# Should not hit - Other uses of the words
clippy::todo
todo!()
# Should not hit - Words merely containing the keywords
mastodon
ictodosaur
EOF
)

diff -u --color <(printf '%s\n' "$TEST_OUTPUT") <(cat <<EOF
todo
TODO
fixme
FiXmE
reallytodo
trulyfixme
todo123
fixme123
TODO(123)
TODO(/////)
TODO(T123)
EOF
)

if [[ $? -ne 0 ]]
then
echo 'Test run of detection regex failed.'
exit 1
fi

# Actual run

rg -iTh -Tsh --pcre2 "$REGEX"
if [[ $? -eq 0 ]]
then
echo 'Found TODO comments without issue numbers.'
exit 1
fi

0 comments on commit 319321b

Please sign in to comment.