From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH v3] [pre-commit] Add shellcheck
Date: Thu, 27 Aug 2026 09:40:02 +0200 [thread overview]
Message-ID: <6f12c448-2e14-4736-b103-5d540a64fe4c@suse.de> (raw)
In-Reply-To: <20260730123539.24766-1-tdevries@suse.de>
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
prev parent reply other threads:[~2026-08-27 7:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 12:35 Tom de Vries
2026-08-27 7:40 ` Tom de Vries [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6f12c448-2e14-4736-b103-5d540a64fe4c@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox