mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
Meta: Update lint-{clang-format,shell-scripts}.sh to take a list of files
This should speed up pre-commit a bit as only files that are staged will be processed, and clang-format and shellcheck are only invoked once, not for every file. When no arguments are given (e.g. on CI), it still uses 'git ls-files'.
This commit is contained in:
parent
a56b3cbf7c
commit
51bcfb5a44
4 changed files with 56 additions and 43 deletions
|
@ -10,24 +10,25 @@ if ! command -v shellcheck &>/dev/null ; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
ERRORS=()
|
||||
|
||||
while IFS= read -r f; do
|
||||
if file "$f" | grep --quiet shell; then
|
||||
{
|
||||
shellcheck "$f" && echo -e "[\033[0;32mOK\033[0m]: successfully linted $f"
|
||||
} || {
|
||||
ERRORS+=("$f")
|
||||
}
|
||||
fi
|
||||
done < <(git ls-files -- \
|
||||
'*.sh' \
|
||||
':!:Toolchain' \
|
||||
':!:Ports' \
|
||||
':!:Shell/Tests' \
|
||||
)
|
||||
|
||||
if (( ${#ERRORS[@]} )); then
|
||||
echo "Files failing shellcheck: ${ERRORS[*]}"
|
||||
exit 1
|
||||
if [ "$#" -eq "0" ]; then
|
||||
mapfile -t files < <(
|
||||
git ls-files -- \
|
||||
'*.sh' \
|
||||
':!:Toolchain' \
|
||||
':!:Ports' \
|
||||
':!:Shell/Tests'
|
||||
)
|
||||
else
|
||||
files=()
|
||||
for file in "$@"; do
|
||||
if [[ "${file}" == *".sh" ]]; then
|
||||
files+=("${file}")
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if (( ${#files[@]} )); then
|
||||
shellcheck "${files[@]}"
|
||||
else
|
||||
echo "No .sh files to check."
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue