|
1 | 1 | #!/bin/bash |
2 | | - |
| 2 | +[ -n "$BASH_VERSION" ] || { echo "ERROR: This script requires bash. Run with: bash $0" >&2; exit 1; } |
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | 5 | RUNTIME_DIR="Packages/com.unity.inputsystem/InputSystem/Runtime" |
6 | 6 |
|
7 | | -# Rust regexes (no PCRE2 required) — \b prevents matching identifiers that merely contain these strings. |
| 7 | +# POSIX ERE patterns for grep -E, compatible with macOS (BSD grep) and Ubuntu (GNU grep). |
| 8 | +# No \b word boundaries — not portable across both. False positive risk is negligible |
| 9 | +# since no real identifiers contain these namespace roots as substrings. |
8 | 10 | # (\.[A-Za-z0-9_]+)* covers sub-namespaces (UnityEditor.UI, …Editor.Tools, …). |
9 | | -# Add more lines as needed, e.g. '\bUnityEditorInternal(\.[A-Za-z0-9_]+)*\b' |
| 11 | +# Add more lines as needed, e.g. 'UnityEditorInternal(\.[A-Za-z0-9_]+)*' |
10 | 12 | FORBIDDEN_REGEX=( |
11 | | - '\bUnityEditor(\.[A-Za-z0-9_]+)*\b' |
12 | | - '\bUnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*\b' |
| 13 | + 'UnityEditor(\.[A-Za-z0-9_]+)*' |
| 14 | + 'UnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*' |
13 | 15 | ) |
14 | 16 |
|
15 | 17 | RED=$'\033[0;31m' |
16 | 18 | GREEN=$'\033[0;32m' |
17 | 19 | NC=$'\033[0m' |
18 | 20 |
|
19 | | -command -v rg >/dev/null 2>&1 || { echo "ERROR: ripgrep (rg) is not installed. See https://github.com/BurntSushi/ripgrep#installation" >&2; exit 1; } |
20 | | - |
21 | 21 | INCLUDE_COMMENTS=false |
22 | 22 | for arg in "$@"; do |
23 | 23 | case "$arg" in |
|
42 | 42 |
|
43 | 43 | COMBINED=$(IFS='|'; echo "${FORBIDDEN_REGEX[*]}") |
44 | 44 |
|
45 | | -PATTERN="(?:$COMBINED)" |
46 | | - |
47 | | -RG_OUTPUT=$(rg --type cs --line-number --no-heading --color never "$PATTERN" "$RUNTIME_DIR" || true) |
| 45 | +GREP_OUTPUT=$(grep -rn --include='*.cs' --color=never -E "$COMBINED" "$RUNTIME_DIR" || true) |
48 | 46 |
|
49 | 47 | if [ "$INCLUDE_COMMENTS" = false ]; then |
50 | | - # Filter out pure comment lines (/// and //) by checking the content portion (field 3+) |
51 | | - VIOLATIONS=$(echo "$RG_OUTPUT" | grep -Ev ':[0-9]+:[[:space:]]*//' || true) |
| 48 | + VIOLATIONS=$(echo "$GREP_OUTPUT" | grep -Ev ':[0-9]+:[[:space:]]*//' || true) |
52 | 49 | else |
53 | | - VIOLATIONS="$RG_OUTPUT" |
| 50 | + VIOLATIONS="$GREP_OUTPUT" |
54 | 51 | fi |
55 | 52 |
|
56 | 53 | if [ -z "$VIOLATIONS" ]; then |
|
0 commit comments