Skip to content

Commit f309e1f

Browse files
Add ShellCheck feature
1 parent 40a439e commit f309e1f

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

.shellcheckrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable all optional checks
2+
enable=all
3+
4+
# Follow source statements even when the file is not specified as input
5+
external-sources=true

src/shellcheck/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# shellcheck
2+
3+
Install [ShellCheck](https://www.shellcheck.net), a static analysis tool for shell scripts.
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/CargoSense/devcontainer-features/shellcheck:1": {}
10+
}
11+
```
12+
13+
## OS Support
14+
15+
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "ShellCheck",
3+
"id": "shellcheck",
4+
"version": "1.0.0",
5+
"description": "Install ShellCheck, a static analysis tool for shell scripts.",
6+
"installsAfter": [
7+
"ghcr.io/devcontainers/features/common-utils"
8+
]
9+
}
10+

src/shellcheck/install.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
if [ "$(id -u)" -ne 0 ]; then
6+
printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
7+
exit 1
8+
fi
9+
10+
apt update --yes
11+
apt install --no-install-recommends --yes shellcheck

test/shellcheck/test.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# This test file will be executed against an auto-generated devcontainer.json that
4+
# includes the 'shellcheck' Feature with no options.
5+
#
6+
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
7+
#
8+
# Eg:
9+
# {
10+
# "image": "<..some-base-image...>",
11+
# "features": {
12+
# "shellcheck": {}
13+
# },
14+
# "remoteUser": "root"
15+
# }
16+
#
17+
# Thus, the value of all options will fall back to the default value in the
18+
# Feature's 'devcontainer-feature.json'.
19+
#
20+
# These scripts are run as 'root' by default. Although that can be changed
21+
# with the '--remote-user' flag.
22+
#
23+
# This test can be run with the following command:
24+
#
25+
# devcontainer features test \
26+
# --features shellcheck \
27+
# --remote-user root \
28+
# --skip-scenarios \
29+
# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \
30+
# /path/to/this/repo
31+
32+
set -e
33+
34+
# Optional: Import test library bundled with the devcontainer CLI
35+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
36+
# Provides the 'check' and 'reportResults' commands.
37+
source dev-container-features-test-lib
38+
39+
# Feature-specific tests
40+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
41+
# check <LABEL> <cmd> [args...]
42+
check "version" shellcheck --version
43+
check "which shellcheck" bash -c "which shellcheck | grep /usr/bin/shellcheck"
44+
45+
# Report result
46+
# If any of the checks above exited with a non-zero exit code, the test will fail.
47+
reportResults

0 commit comments

Comments
 (0)