Skip to content

Commit a68b0e9

Browse files
Merge pull request #6 from assertwell/release/v1.0.2
Version 1.0.2
2 parents 2257a07 + 2b83e10 commit a68b0e9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Version 1.0.2] — 2022-02-09
8+
9+
### Fixed
10+
11+
* Look for `COMPOSER_RUNTIME_BIN_DIR`, not `COMPOSER_BIN_DIR` when altering the user's `$PATH` to prevent recursion in Composer scripts ([#5]).
12+
713
## [Version 1.0.1] — 2022-02-08
814

915
### Fixed
@@ -17,4 +23,6 @@ Initial release.
1723
[Unreleased]: https://github.com/assertwell/shellcheck/compare/main...develop
1824
[Version 1.0.0]: https://github.com/assertwell/shellcheck/releases/tag/v1.0.0
1925
[Version 1.0.1]: https://github.com/assertwell/shellcheck/releases/tag/v1.0.1
26+
[Version 1.0.2]: https://github.com/assertwell/shellcheck/releases/tag/v1.0.2
2027
[#3]: https://github.com/assertwell/shellcheck/pull/3
28+
[#5]: https://github.com/assertwell/shellcheck/pull/5

bin/shellcheck

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#
1414
# Note: All options other than those listed below will be passed directly to the ShellCheck binary.
1515
#
16+
# --debug Print debug messages within this script, useful when troubleshooting
17+
# $PATH issues.
1618
# -i, --ignore-missing Print a warning, but consider the script successful if a local instance
1719
# of ShellCheck could not be found.
1820
#
@@ -26,10 +28,22 @@ declare -a args
2628

2729
# Default exit code if ShellCheck cannot be found.
2830
exit_code=2
31+
debug_mode=0
32+
33+
# Print a debug message if debug_mode=1
34+
function debug() {
35+
if [[ "$debug_mode" == 1 ]]; then
36+
printf "\033[0;36m[DEBUG]\033[0;0m %s\n" "$1"
37+
fi
38+
}
2939

3040
# Look for any arguments specific to this script, and put everything else into $args.
3141
while [ $# -gt 0 ]; do
3242
case "$1" in
43+
--debug)
44+
debug_mode=1
45+
shift
46+
;;
3347
-i|--ignore-missing)
3448
exit_code=0
3549
shift
@@ -45,9 +59,22 @@ done
4559
#
4660
# However, this can lead to recursion since the first "shellcheck" script `command -v shellcheck`
4761
# will find will be...well, this one.
48-
if [[ -n "$COMPOSER_BIN_DIR" ]]; then
62+
#
63+
# Composer 2.2.6 introduced the COMPOSER_RUNTIME_BIN_DIR environment variable, so we can use that
64+
# to strip the bin-dir from the user's $PATH.
65+
#
66+
# For older versions of Composer, attempt to build the path by reading the Composer configuration
67+
# (if present).
68+
if [[ -z "$COMPOSER_RUNTIME_BIN_DIR" ]]; then
69+
debug "COMPOSER_RUNTIME_BIN_DIR not found, checking Composer configuration"
70+
COMPOSER_RUNTIME_BIN_DIR="$(composer config --absolute bin-dir || 'true')"
71+
fi
72+
73+
# If we have a value for COMPOSER_RUNTIME_BIN_DIR, strip it from the user's $PATH.
74+
if [[ -n "$COMPOSER_RUNTIME_BIN_DIR" ]]; then
75+
debug "Stripping '${COMPOSER_RUNTIME_BIN_DIR}' from \$PATH"
4976
# shellcheck disable=SC2001
50-
PATH="$(sed -e "s|^${COMPOSER_BIN_DIR}:||" <<< "$PATH")"
77+
PATH="$(sed -e "s|^${COMPOSER_RUNTIME_BIN_DIR}:||" <<< "$PATH")"
5178
fi
5279

5380
# Find the local ShellCheck binary.
@@ -57,7 +84,10 @@ shellcheck="$(command -v shellcheck)"
5784
if [[ -z "$shellcheck" ]]; then
5885
echo -e "\n\033[0;33mShellCheck was not found in your \$PATH!\033[0;0m"
5986
echo -e "Please visit \033[4mhttps://github.com/koalaman/shellcheck#installing\033[0m for installation instructions.\n"
87+
debug "PATH: ${PATH}"
6088
exit "$exit_code"
6189
fi
6290

91+
debug "Using ${shellcheck}"
92+
debug "Running \`shellcheck ${args[*]}\`"
6393
"$shellcheck" "${args[@]}"

0 commit comments

Comments
 (0)