Add pre-commit config

Add pre-commit hooks for trailing whitespaces and newline at file end
Add pre-commit hook for tmt linting
Add pre-commit hook for static analysis on shell scripts (shellcheck)
Fixed issues flagged by shellcheck.
This commit is contained in:
Jesus Checa Hidalgo 2024-08-05 09:45:45 +02:00
commit d69918d2f8
3 changed files with 28 additions and 5 deletions

21
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
# See https://tmt.readthedocs.io/en/latest/guide.html#checking-data-validity
- repo: https://github.com/teemtee/tmt.git
rev: 1.32.2
hooks:
- id: tmt-lint
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
require_serial: true # Podman has trouble running concurrently
args: ["--exclude=SC1091"] # Ignore "Not following" sourced scripts

View file

@ -12,10 +12,11 @@ lldb -b -o 'breakpoint set --file test.cpp --line 7' -o run -o 'p v' -- a.out |
# (std::vector<int, std::allocator<(int)> >) $0 = size=1 {
# [0] = 2
test `grep \
# shellcheck disable=SC2016
test "$(grep -c \
-e '(std::vector<int\(, std::allocator<\(int\)\?> \)\?>) \($0 = \)\?size=1 {' \
-e '\[0\] = 2' \
lldb.log \
| wc -l` -eq 2
)" -eq 2
rm lldb.log

View file

@ -1,7 +1,7 @@
#!/bin/sh -eux
# Verify the formal side of things, lldb should really depend on its Python bits
LLDB_PACKAGE=${LLDB_PACKAGE:-$(rpm -qf $(which lldb))}
LLDB_PACKAGE=${LLDB_PACKAGE:-$(rpm -qf "$(which lldb)")}
rpm -q --requires "$LLDB_PACKAGE" | grep python3-lldb
# Sanity test
@ -11,10 +11,11 @@ lldb -b -o 'breakpoint set --file test.cpp --line 8' \
-o run -o 'p i' -o 'p f'\
-- a.out | tee lldb.log
test `grep \
# shellcheck disable=SC2016
test "$(grep -c \
-e '(int) \($0 = \)\?1' \
-e '(float) \($1 = \)\?1' \
lldb.log \
| wc -l` -eq 2
)" -eq 2
rm lldb.log