Repository: risingwavelabs/risingwave
File: scripts/check/check-trailing-spaces.sh (Shell)

Code before:
    echo "  -s, --skip-dir <dir>   Skip a directory (can be specified multiple times)."
    echo "                          Example: $self --skip-dir target --skip-dir src/tests"
    echo "  -h, --help             Show this help message and exit."
}

fix=false
skip_dirs=()
while [ $# -gt 0 ]; do
    case $1 in
    -f | --fix)
        fix=true
        ;;
    -s | --skip-dir)
        shift
        if [ $# -eq 0 ]; then
            echo -e "${RED}${BOLD}$self: missing argument for --skip-dir${NONE}"
            print_help
            exit 1
        fi
        skip_dirs+=("$1")
        ;;
    -h | --help)
        print_help
        exit 0
        ;;
    *)
        echo -e "${RED}${BOLD}$self: invalid option \`$1\`\n${NONE}"
        print_help
        exit 1
        ;;
    esac
    shift
done

temp_file=$(mktemp)

echo -ne "${BLUE}"
# Build git pathspec exclusions. `--` separates revs/options from pathspecs.
# Default: search repo root, but skip `.cargo/` and `src/tests/regress/`.
git_grep_pathspec=(-- ':' ':!.cargo' ':!src/tests/regress')
if [ ${#skip_dirs[@]} -gt 0 ]; then
    for d in "${skip_dirs[@]}"; do
        # Normalize leading "./" to keep the pathspec consistent.
        d="${d#./}"
        git_grep_pathspec+=(":!${d}")
    done
fi

git grep -nIP --untracked '[[:space:]]+$' "${git_grep_pathspec[@]}" | tee "$temp_file" || true
echo -ne "${NONE}"


Review comment (suggestion):
The pathspec has changed from ':!src/tests/regress' (excluding the entire regress directory) to ':!src/tests/regress/data' (excluding only the data subdirectory). This narrows the exclusion scope and may cause the script to now check files in src/tests/regress/ that were previously excluded. If this change is intentional, it should be documented; otherwise, it should remain as ':!src/tests/regress' to maintain the original behavior.
```suggestion
git grep -nIP --untracked '[[:space:]]+$' -- ':!src/tests/regress' | tee $temp_file || true
```

Code after:
    echo "  -h, --help             Show this help message and exit."
}

fix=false
while [ $# -gt 0 ]; do
    case $1 in
    -f | --fix)
        fix=true
        ;;
    -h | --help)
        print_help
        exit 0
        ;;
    *)
        echo -e "${RED}${BOLD}$self: invalid option \`$1\`\n${NONE}"
        print_help
        exit 1
        ;;
    esac
    shift
done

temp_file=$(mktemp)

echo -ne "${BLUE}"
git grep -nIP --untracked '[[:space:]]+$' -- ':!src/tests/regress/data' | tee $temp_file || true
echo -ne "${NONE}"

bad_files=$(cat $temp_file | cut -f1 -d ':' | sort -u)
rm $temp_file

if [ ! -z "$bad_files" ]; then
    if [[ $fix == true ]]; then
        for file in $bad_files; do
            sed -i '' -e's/[[:space:]]*$//' "$file"
        done

        echo
        echo -e "${GREEN}${BOLD}All trailing spaces listed above have been cleaned.${NONE}"
        exit 0
    else
        echo
        echo -e "${RED}${BOLD}Please clean all the trailing spaces listed above.${NONE}"
        echo -e "${BOLD}You can run '$self --fix' for convenience.${NONE}"
        exit 1
    fi
else
    echo -e "${GREEN}${BOLD}No trailing spaces found.${NONE}"
    exit 0
fi