Skip to content

Commit

Permalink
chore: add check-forbidden-classes.sh 🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Feb 1, 2025
1 parent 5de7635 commit 16b0376
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ jobs:
npm install -g doctoc
npm list -g --depth=0
scripts/update_md_toc.sh
# https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
- name: Check API docs
run: scripts/check_api_docs.sh
- name: Check forbidden classes
run: scripts/check-forbidden-classes.sh

# https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
- name: Check git dirty
run: |
git status --short
Expand Down
38 changes: 38 additions & 0 deletions scripts/check-forbidden-classes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eEuo pipefail
# the canonical path of this script
SELF_PATH=$(realpath -- "$0")
readonly SELF_PATH SELF_DIR=${SELF_PATH%/*}

# cd to project directory
cd "$SELF_DIR"/..

source "$SELF_DIR/bash-buddy/lib/common_utils.sh"

readonly forbidden_classes=(
# prefer edu.umd.cs.findbugs.annotations.Nullable
javax.annotation.Nullable
org.jetbrains.annotations.Nullable

# prefer edu.umd.cs.findbugs.annotations.NonNull
javax.annotation.Nonnull
org.jetbrains.annotations.NotNull

# prefer edu.umd.cs.findbugs.annotations.CheckForNull
javax.annotation.CheckReturnValue
org.jetbrains.annotations.CheckReturnValue

# prefer @edu.umd.cs.findbugs.annotations.DefaultAnnotationForParameters(NonNull.class)
javax.annotation.ParametersAreNonnullByDefault

# prefer static import methods of `Assertions`
'org.junit.jupiter.api.Assertions;'
)

PATTERN=$(printf '%s\n' "${forbidden_classes[@]}")
[[ "${GITHUB_ACTIONS:-}" = true || -t 1 ]] && MORE_RG_OPTIONS=(--color=always)
readonly PATTERN MORE_RG_OPTIONS

! cu::log_then_run rg -f <(printf '%s\n' "$PATTERN") -F -n -C2 \
--ignore-vcs --glob='!scripts/' --glob='!package-info.java' \
${MORE_RG_OPTIONS[@]:+"${MORE_RG_OPTIONS[@]}"}

0 comments on commit 16b0376

Please sign in to comment.