* [PATCH v3] [pre-commit] Add shellcheck
@ 2026-07-30 12:35 Tom de Vries
2026-08-27 7:40 ` Tom de Vries
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-07-30 12:35 UTC (permalink / raw)
To: gdb-patches
Add a pre-commit shellcheck hook.
Contrary to a usual pre-commit setup, users are expected to provide shellcheck
themselves.
Since that can be non-trival, as a compromise both versions 0.11.0 and 0.10.0
are allowed.
This can lead to "but it works for me" situations, but people not using it
because they don't have the latest version available seems worse.
If version 0.10.0 is used, a note is emitted, though this is only visible
with -v:
....
$ pre-commit run shellcheck --all-files -v
shellcheck...............................................................Passed
- hook id: shellcheck
- duration: 0.13s
Using shellcheck version 0.10.0, but version 0.11.0 is preferred.
...
Using shellcheck version 0.10.0, but version 0.11.0 is preferred.
...
Alternative solutions are:
- pureshellcheck [1]. Python, but the project seems unmaintained.
- shellcheck-py [2]. Downloads an executable and runs it.
- shellcheck-precommit [3]. Downloads a docker image and runs it.
Changes in v3:
- abandoned pureshellcheck approach used in v1 and v2.
Versions:
- v2 https://sourceware.org/pipermail/gdb-patches/2026-June/228145.html
- v1 https://sourceware.org/pipermail/gdb-patches/2026-June/228118.html
[1] https://github.com/adam2go/pureshellcheck
[2] https://github.com/shellcheck-py/shellcheck-py
[3] https://github.com/koalaman/shellcheck-precommit
---
.pre-commit-config.yaml | 10 ++++++
gdb/contrib/shellcheck.sh | 65 +++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
create mode 100755 gdb/contrib/shellcheck.sh
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 8ff84dae274..75eb1edd11d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -147,3 +147,13 @@ repos:
language: unsupported_script
entry: gdb/contrib/check-file-mode.sh
files: *gdb_files
+ - id: &id5 shellcheck
+ name: *id5
+ files: '^(gdb|gdbsupport|gdbserver)/'
+ types: ['shell']
+ language: unsupported_script
+ # The gdb/contrib/shellcheck.sh script requires shellcheck 0.11.0
+ # (preferred) or 0.10.0. Not pinning this to a single version is a
+ # compromise to deal with the fact that users themselves need to
+ # provide the dependency, which may be non-trivial.
+ entry: gdb/contrib/shellcheck.sh
diff --git a/gdb/contrib/shellcheck.sh b/gdb/contrib/shellcheck.sh
new file mode 100755
index 00000000000..259988bec48
--- /dev/null
+++ b/gdb/contrib/shellcheck.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# Copyright (C) 2026 Free Software Foundation, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+version=$(shellcheck --version | grep ^version | awk '{print $2}')
+
+case "$version" in
+ 0.11.0)
+ # Preferred version.
+ true
+ ;;
+ 0.10.0)
+ # Allowed version, but mention preferred version. This will be
+ # visible with "pre-commit run shellcheck --all-files -v".
+ echo "Using shellcheck version 0.10.0, but version 0.11.0 is preferred."
+ ;;
+ *)
+ echo "Please install shellcheck version 0.11.0 (preferred) or 0.10.0"
+ exit 1
+ ;;
+esac
+
+files=()
+for f in "$@"; do
+ case "$f" in
+ */configure)
+ # Skip generated files.
+ continue
+ ;;
+ gdb/config/djgpp/djcheck.sh \
+ | gdb/config/djgpp/djconfig.sh \
+ | gdb/contrib/cc-with-tweaks.sh \
+ | gdb/contrib/gdb-add-index.sh \
+ | gdb/gdb_buildall.sh \
+ | gdb/gdb_mbuild.sh \
+ | gdb/po/gdbtext \
+ | gdb/regformats/regdat.sh \
+ | gdb/testsuite/lib/pdtrace.in)
+ # Skip unclean files.
+ continue
+ ;;
+ *)
+ files=("${files[@]}" "$f")
+ ;;
+ esac
+done
+
+if [ ${#files[@]} -eq 0 ]; then
+ # Nothing to do.
+ exit 0
+fi
+
+shellcheck "${files[@]}"
base-commit: 0d22d419a4b60672acf5555f5479fcf6956018a1
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v3] [pre-commit] Add shellcheck
2026-07-30 12:35 [PATCH v3] [pre-commit] Add shellcheck Tom de Vries
@ 2026-08-27 7:40 ` Tom de Vries
0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2026-08-27 7:40 UTC (permalink / raw)
To: gdb-patches
On 7/30/26 2:35 PM, Tom de Vries wrote:
> Add a pre-commit shellcheck hook.
>
> Contrary to a usual pre-commit setup, users are expected to provide shellcheck
> themselves.
>
> Since that can be non-trival, as a compromise both versions 0.11.0 and 0.10.0
> are allowed.
>
I've pushed this, with some last-minute changes:
- fixing review comments from Claude Code: added set -e, added some
quoting
- set stages to manual. This makes it opt-in, and normal pre-commit
usage shouldn't be disturbed, handling the case that someone doesn't
have (an allowed version of) shellcheck installed more gracefully
Running all hooks now becomes:
...
$ for hs in pre-commit manual; do \
pre-commit run --hook-stage $hs --all-files; \
done
...
Thanks,
- Tom
> This can lead to "but it works for me" situations, but people not using it
> because they don't have the latest version available seems worse.
>
> If version 0.10.0 is used, a note is emitted, though this is only visible
> with -v:
> ....
> $ pre-commit run shellcheck --all-files -v
> shellcheck...............................................................Passed
> - hook id: shellcheck
> - duration: 0.13s
>
> Using shellcheck version 0.10.0, but version 0.11.0 is preferred.
> ...
> Using shellcheck version 0.10.0, but version 0.11.0 is preferred.
> ...
>
> Alternative solutions are:
> - pureshellcheck [1]. Python, but the project seems unmaintained.
> - shellcheck-py [2]. Downloads an executable and runs it.
> - shellcheck-precommit [3]. Downloads a docker image and runs it.
>
> Changes in v3:
> - abandoned pureshellcheck approach used in v1 and v2.
>
> Versions:
> - v2 https://sourceware.org/pipermail/gdb-patches/2026-June/228145.html
> - v1 https://sourceware.org/pipermail/gdb-patches/2026-June/228118.html
>
> [1] https://github.com/adam2go/pureshellcheck
> [2] https://github.com/shellcheck-py/shellcheck-py
> [3] https://github.com/koalaman/shellcheck-precommit
> ---
> .pre-commit-config.yaml | 10 ++++++
> gdb/contrib/shellcheck.sh | 65 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 75 insertions(+)
> create mode 100755 gdb/contrib/shellcheck.sh
>
> diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
> index 8ff84dae274..75eb1edd11d 100644
> --- a/.pre-commit-config.yaml
> +++ b/.pre-commit-config.yaml
> @@ -147,3 +147,13 @@ repos:
> language: unsupported_script
> entry: gdb/contrib/check-file-mode.sh
> files: *gdb_files
> + - id: &id5 shellcheck
> + name: *id5
> + files: '^(gdb|gdbsupport|gdbserver)/'
> + types: ['shell']
> + language: unsupported_script
> + # The gdb/contrib/shellcheck.sh script requires shellcheck 0.11.0
> + # (preferred) or 0.10.0. Not pinning this to a single version is a
> + # compromise to deal with the fact that users themselves need to
> + # provide the dependency, which may be non-trivial.
> + entry: gdb/contrib/shellcheck.sh
> diff --git a/gdb/contrib/shellcheck.sh b/gdb/contrib/shellcheck.sh
> new file mode 100755
> index 00000000000..259988bec48
> --- /dev/null
> +++ b/gdb/contrib/shellcheck.sh
> @@ -0,0 +1,65 @@
> +#!/bin/bash
> +
> +# Copyright (C) 2026 Free Software Foundation, Inc.
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +version=$(shellcheck --version | grep ^version | awk '{print $2}')
> +
> +case "$version" in
> + 0.11.0)
> + # Preferred version.
> + true
> + ;;
> + 0.10.0)
> + # Allowed version, but mention preferred version. This will be
> + # visible with "pre-commit run shellcheck --all-files -v".
> + echo "Using shellcheck version 0.10.0, but version 0.11.0 is preferred."
> + ;;
> + *)
> + echo "Please install shellcheck version 0.11.0 (preferred) or 0.10.0"
> + exit 1
> + ;;
> +esac
> +
> +files=()
> +for f in "$@"; do
> + case "$f" in
> + */configure)
> + # Skip generated files.
> + continue
> + ;;
> + gdb/config/djgpp/djcheck.sh \
> + | gdb/config/djgpp/djconfig.sh \
> + | gdb/contrib/cc-with-tweaks.sh \
> + | gdb/contrib/gdb-add-index.sh \
> + | gdb/gdb_buildall.sh \
> + | gdb/gdb_mbuild.sh \
> + | gdb/po/gdbtext \
> + | gdb/regformats/regdat.sh \
> + | gdb/testsuite/lib/pdtrace.in)
> + # Skip unclean files.
> + continue
> + ;;
> + *)
> + files=("${files[@]}" "$f")
> + ;;
> + esac
> +done
> +
> +if [ ${#files[@]} -eq 0 ]; then
> + # Nothing to do.
> + exit 0
> +fi
> +
> +shellcheck "${files[@]}"
>
> base-commit: 0d22d419a4b60672acf5555f5479fcf6956018a1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-27 7:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-30 12:35 [PATCH v3] [pre-commit] Add shellcheck Tom de Vries
2026-08-27 7:40 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox