Skip to content

Commit 8b3df7f

Browse files
committed
Initial release, exposing a simple proxy script for ShellCheck
0 parents  commit 8b3df7f

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.* export-ignore
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI Pipeline
2+
3+
# Execute on pushes to develop or main, as well as all PRs.
4+
on:
5+
push:
6+
branches:
7+
- develop
8+
- main
9+
pull_request:
10+
11+
jobs:
12+
13+
# Run ShellCheck against ShellCheck, pray we don't collapse the universe.
14+
shellcheck:
15+
name: Run ShellCheck
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Validate composer.json
21+
run: composer validate
22+
23+
- name: Check coding standards
24+
run: composer test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
composer.lock
2+
vendor
3+
4+
*.DS_Store

LICENSE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# License
2+
3+
Copyright © 2022 AssertWell
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
11+
ShellCheck is the copyright of Vidar Holden and made available under [the GPLv3 license](https://github.com/koalaman/shellcheck/blob/master/LICENSE).

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# ShellCheck
2+
3+
[Vidar Holen's ShellCheck is an invaluable tool for troubleshooting shell scripts](https://www.shellcheck.net), and this package makes it easy to import into the testing pipeline of your PHP-based project!
4+
5+
## How it works
6+
7+
This package contains a `bin/shellcheck` script that serves as a proxy to the system-installed copy of ShellCheck; if the ShellCheck binary is found, arguments pass through to it normally. If ShellCheck is **not** found locally, users are presented with the following notice:
8+
9+
> ShellCheck was not found in your $PATH!
10+
> Please visit https://github.com/koalaman/shellcheck#installing for installation instructions.
11+
12+
Normally, this would result in a non-zero exit code (2), though this behavior may be suppressed with the `--ignore-missing` option:
13+
14+
```none
15+
$ vendor/bin/shellcheck --ignore-missing some-script.sh
16+
17+
ShellCheck was not found in your $PATH!
18+
Please visit https://github.com/koalaman/shellcheck#installing for installation instructions.
19+
20+
$ echo $?
21+
0
22+
```
23+
24+
## Installation
25+
26+
The easiest way to install this package is via [Composer](https://getcomposer.org):
27+
28+
```sh
29+
$ composer require --dev assertwell/shellcheck
30+
```
31+
32+
You may wish to add a [Composer script](https://getcomposer.org/doc/articles/scripts.md) to make it easier for team members to run ShellCheck:
33+
34+
```jsonc
35+
# composer.json
36+
{
37+
// ...
38+
"scripts": {
39+
"test:shellcheck": [
40+
"shellcheck bin/*"
41+
]
42+
},
43+
"scripts-descriptions": [
44+
"test:shellcheck": "Lint shell scripts via ShellCheck"
45+
]
46+
}
47+
```
48+
49+
As for the installation of ShellCheck itself, please [see the instructions most-relevant to your environment in the ShellCheck documentation](https://github.com/koalaman/shellcheck#installing).
50+
51+
## License
52+
53+
[The assertwell/shellcheck Composer package is available under the MIT license](LICENSE.md).
54+
55+
ShellCheck itself is the copyright of Vidar Holden and made [available under the GPLv3 license](https://github.com/koalaman/shellcheck/blob/master/LICENSE).

bin/shellcheck

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Locate ShellCheck in the current environment and pass it the given arguments.
4+
#
5+
# If ShellCheck is not found, provide instructions for how to install it in the given environment.
6+
#
7+
# To remain consistent with ShellCheck's exit codes, this script will exit with a code of 2 if
8+
# ShellCheck cannot be found locally (unless the `--ignore-missing` option is present).
9+
#
10+
# Reference: https://github.com/koalaman/shellcheck/wiki/Integration#exit-codes
11+
#
12+
# OPTIONS:
13+
#
14+
# Note: All options other than those listed below will be passed directly to the ShellCheck binary.
15+
#
16+
# -i, --ignore-missing Print a warning, but consider the script successful if a local instance
17+
# of ShellCheck could not be found.
18+
#
19+
# This script is part of the assertwell/shellcheck package.
20+
#
21+
# URL: https://github.com/assertwell/shellcheck
22+
# Author: Steve Grunwell
23+
# License: MIT
24+
25+
declare -a args
26+
27+
# Default exit code if ShellCheck cannot be found.
28+
exit_code=2
29+
30+
# Look for any arguments specific to this script, and put everything else into $args.
31+
while [ $# -gt 0 ]; do
32+
case "$1" in
33+
-i|--ignore-missing)
34+
exit_code=0
35+
shift
36+
;;
37+
*)
38+
args+=("$1")
39+
shift
40+
;;
41+
esac
42+
done
43+
44+
# Find the local ShellCheck binary.
45+
shellcheck="$(command -v shellcheck)"
46+
47+
# Print installation instructions if ShellCheck was not found.
48+
if [[ -z "$shellcheck" ]]; then
49+
echo -e "\n\033[0;33mShellCheck was not found in your \$PATH!\033[0;0m"
50+
echo -e "Please visit \033[4mhttps://github.com/koalaman/shellcheck#installing\033[0m for installation instructions.\n"
51+
exit "$exit_code"
52+
fi
53+
54+
"$shellcheck" "${args[@]}"

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "assertwell/shellcheck",
3+
"description": "Expose ShellCheck as a vendor binary for PHP projects",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Steve Grunwell",
9+
"homepage": "https://stevegrunwell.com"
10+
}
11+
],
12+
"support": {
13+
"issues": "https://github.com/assertwell/shellcheck/issues",
14+
"source": "https://github.com/assertwell/shellcheck"
15+
},
16+
"bin": [
17+
"bin/shellcheck"
18+
],
19+
"scripts": {
20+
"test": "shellcheck bin/shellcheck"
21+
},
22+
"scripts-descriptions": {
23+
"test": "Run ShellCheck against the ShellCheck proxy script"
24+
},
25+
"minimum-stability": "stable",
26+
"config": {
27+
"preferred-install": "dist",
28+
"sort-packages": true
29+
}
30+
}

0 commit comments

Comments
 (0)