Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shell lint errors #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1
jobs:
build:
machine:
image: ubuntu-2004:202201-02
image: default
steps:
- checkout
- run:
Expand Down
3 changes: 3 additions & 0 deletions core/modules/args/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Gets the value of a script parameter, where --parameter=value.
#
# 1 will be returned if --parameter was passed without a value;
Expand All @@ -7,6 +9,7 @@
# @param $1
# The name of parameter.
function argvalue() {
# shellcheck disable=SC2154
source "$GlobalSCRIPTDIR"/core/modules/args/scripts/arg-value.source.sh "$1"
if [ -z "$ARGVALUE" ]; then
echo 0
Expand Down
5 changes: 4 additions & 1 deletion core/modules/args/scripts/arg-value.source.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash

# Available arguments
# * $PARAMS, an array of params like 'a=b', 'c=d'

# shellcheck disable=SC2154
for i in "${GlobalPARAMS[@]}"
do
# shellcheck disable=SC2154
source "$GlobalSCRIPTDIR"/core/modules/args/scripts/parse-param.source.sh "$i"
if [ "$NAME" == "$1" ]; then
ARGVALUE="$VALUE"
Expand Down
7 changes: 5 additions & 2 deletions core/modules/args/scripts/parse-arguments.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

set -e

# start by cycling through all arguments provided by the user.
Expand All @@ -11,7 +13,8 @@ while [ $# -gt 0 ]; do
UNVALIDATEDCOMMAND=$1
debug "Command is $COMMAND"
else
GlobalARGS+=($1)

GlobalARGS+=("$1")
debug "$1 is an arg"
fi
fi
Expand All @@ -21,5 +24,5 @@ done
if [ -z "$UNVALIDATEDCOMMAND" ]; then
UNVALIDATEDCOMMAND=help
fi

# shellcheck disable=SC2154
source "$GlobalSCRIPTDIR"/core/modules/args/scripts/validate-command.source.sh
10 changes: 7 additions & 3 deletions core/modules/args/scripts/parse-param.source.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash

ARG="$1"
NAME=$(sed 's/=.*$//g' <<< "$ARG")
NAME=$(sed 's/--//g' <<< "$NAME")
VALUE=$(sed 's/^--.*=//g' <<< "$ARG")
NAME="${ARG%%=*}" # Remove everything after the first '='
NAME="${NAME//--/}" # Remove '--' from the name
VALUE="${ARG#*=}" # Extract the value after '='

# If VALUE is empty, set it to 1
if [ -z "$VALUE" ]; then
VALUE=1
fi

8 changes: 6 additions & 2 deletions core/modules/args/scripts/run-command.source.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# At this point $GlobalCOMMAND is valid so we can run it.
#!/bin/bash

# At this point $GlobalCOMMAND is valid so we can run it.
# shellcheck disable=SC2154
invoke-all "pre-command-$GlobalCOMMAND"

# shellcheck disable=SC2154
if [ "$(ls "$GlobalSCRIPTDIR"/core/modules/*/commands/"$GlobalCOMMAND"/"$GlobalCOMMAND".source.sh 2>/dev/null)" ]; then
for f in "$GlobalSCRIPTDIR"/core/modules/*/commands/"$GlobalCOMMAND"/"$GlobalCOMMAND".source.sh
do
# shellcheck disable=SC1090
source "$f"
done
fi

if [ "$(ls "$GlobalSCRIPTDIR"/script/modules/*/commands/"$GlobalCOMMAND"/"$GlobalCOMMAND".source.sh 2>/dev/null)" ]; then
for f in "$GlobalSCRIPTDIR"/script/modules/*/commands/"$GlobalCOMMAND"/"$GlobalCOMMAND".source.sh
do
# shellcheck disable=SC1090
source "$f"
done
fi
Expand Down
2 changes: 2 additions & 0 deletions core/modules/args/scripts/validate-command.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2154
ls "$GlobalSCRIPTDIR"/core/modules/*/commands/"$UNVALIDATEDCOMMAND"/"$UNVALIDATEDCOMMAND".source.sh 2>/dev/null >/dev/null || ls "$GlobalSCRIPTDIR"/script/modules/*/commands/"$UNVALIDATEDCOMMAND"/"$UNVALIDATEDCOMMAND".source.sh 2>/dev/null >/dev/null || { echo -e "$GlobalSCRIPTNAME: Invalid command $UNVALIDATEDCOMMAND"; echo -e "See '$GlobalSCRIPTNAME usage' for available commands."; exit 1; }

GlobalCOMMAND="$UNVALIDATEDCOMMAND"
2 changes: 2 additions & 0 deletions core/modules/core/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

function uuid() {
if [ -f /proc/sys/kernel/random/uuid ]; then
LocalTEMPID=$(cat /proc/sys/kernel/random/uuid)
Expand Down
2 changes: 2 additions & 0 deletions core/modules/core/scripts/glob-exists.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# See https://github.com/koalaman/shellcheck/wiki/SC2144
set -e

Expand Down
2 changes: 2 additions & 0 deletions core/modules/core/scripts/uuid.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Returns a unique string

if [ -f /proc/sys/kernel/random/uuid ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

for f in $(development_get_all_tests); do
output list-element:"$f" 'info' "$f"
done
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ALLTESTS=$(development_get_all_tests)

for f in $ALLTESTS; do
Expand All @@ -20,6 +22,7 @@ set -e
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)"

echo -e "[info] removing $SCRIPTDIR/tmp/test-data directory"
# shellcheck disable=SC2154
rm -rf "$GlobalSCRIPTDIR"/tmp/test-*
echo -e '[info] linting'
DOCKER=docker
Expand Down
2 changes: 2 additions & 0 deletions core/modules/development/hooks/end/end.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ "$(argvalue debug)" == '1' ]; then
echo -e "-----"
echo -e "Printing full log because you set the --debug flag."
Expand Down
3 changes: 3 additions & 0 deletions core/modules/development/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

function debug() {
# shellcheck disable=SC2154
source "$GlobalSCRIPTDIR"/core/modules/development/scripts/debug.source.sh "$1"
}

Expand Down
2 changes: 2 additions & 0 deletions core/modules/development/scripts/debug.source.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

LOG+=("[$2] $1")
4 changes: 3 additions & 1 deletion core/modules/development/scripts/lint.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

echo '[info] About to get ShellCheck metrics'
echo '[info] if you are getting a false negative put:'
echo '[info] => # shellcheck disable=SC2016'
Expand All @@ -8,4 +10,4 @@ echo '[info] => # shellcheck disable=SC2016'

# shellcheck disable=SC2086
find . -name "*.sh" -print0 | \
xargs -0 $DOCKER run --rm -v "$(pwd)":/code dcycle/shell-lint --exclude=SC2034
xargs -0 $DOCKER run --rm -v "$(pwd)":/code dcycle/shell-lint:2 --exclude=SC2034
3 changes: 3 additions & 0 deletions core/modules/extensibility/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

function invoke-all () {
# shellcheck disable=SC2154
source "$GlobalSCRIPTDIR/core/modules/extensibility/scripts/invoke-all.source.sh" "$1"
}
5 changes: 5 additions & 0 deletions core/modules/extensibility/scripts/invoke-all.source.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

# Let modules respond to specific events like init, end, etc.
# shellcheck disable=SC2154
if ls "$GlobalSCRIPTDIR"/core/modules/*/hooks/"$1"/"$1".source.sh 1> /dev/null 2>&1; then
for f in "$GlobalSCRIPTDIR"/core/modules/*/hooks/"$1"/"$1".source.sh
do
# Cannot call debug() here because invoke-all might be used before
# functions are available.
source "$GlobalSCRIPTDIR"/core/modules/development/scripts/debug.source.sh "About to call '$f'." 'full'
# shellcheck disable=SC1090
source "$f"
done
else
Expand All @@ -17,6 +21,7 @@ if ls "$GlobalSCRIPTDIR"/script/modules/*/hooks/"$1"/"$1".source.sh 1> /dev/null
# Cannot call debug() here because invoke-all might be used before
# functions are available.
source "$GlobalSCRIPTDIR"/core/modules/development/scripts/debug.source.sh "About to call '$f'." 'full'
# shellcheck disable=SC1090
source "$f"
done
else
Expand Down
2 changes: 2 additions & 0 deletions core/modules/header/hooks/header/header.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2154
if [ -f "$GlobalSCRIPTDIR"/script/modules/header/files/header.txt ]; then
cat "$GlobalSCRIPTDIR"/script/modules/header/files/header.txt
else
Expand Down
4 changes: 4 additions & 0 deletions core/modules/help/commands/help/help.source.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

if [ -z "$GlobalARGS" ]; then
# shellcheck disable=SC2154
if [ -f "$GlobalSCRIPTDIR"/script/modules/help/help.txt ]; then
cat "$GlobalSCRIPTDIR"/script/modules/help/help.txt
else
Expand Down Expand Up @@ -27,6 +30,7 @@ else
fi

if [ "$COMMANDEXISTS" == 'false' ]; then
# shellcheck disable=SC2154
echo -e "$GlobalSCRIPTNAME: Invalid command $GlobalARGS"
echo -e "See '$GlobalSCRIPTNAME usage' for available commands."
exit 1
Expand Down
4 changes: 4 additions & 0 deletions core/modules/help/commands/usage/usage.source.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

echo -e ""
# shellcheck disable=SC2154
echo -e "Usage (call $GlobalSCRIPTNAME with no additional arguments to get help):"
echo -e "-----"
echo -e ""
Expand All @@ -7,6 +10,7 @@ echo -e ""
echo -e "Available global arguments:"
echo -e "-----"
echo -e ""
# shellcheck disable=SC2154
if [ "$("$GlobalSCRIPTDIR"/core/modules/core/scripts/glob-exists.sh "$GlobalSCRIPTDIR"/core/modules/*/arguments/*/README.md)" == 'true' ]; then
head -n 1 "$GlobalSCRIPTDIR"/core/modules/*/arguments/*/README.md | grep -v == | grep -v '^$'
else
Expand Down
3 changes: 3 additions & 0 deletions core/modules/help/hooks/usage/usage.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
# shellcheck disable=SC2154
echo -e "Usage (call $GlobalSCRIPTNAME with no additional arguments to get help):"
echo -e ""
# shellcheck disable=SC2154
echo -e "$GlobalSCRIPTNAME [command] [arguments] [parameters]"
2 changes: 2 additions & 0 deletions core/modules/output/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

function output() {
echo "[$2] $3"
}
3 changes: 3 additions & 0 deletions core/modules/temporary/hooks/cleanup/cleanup.source.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

if [ -z "$GlobalRUNID" ]; then
echo -e '[error] the cleanup hook expects GlobalRUNID to be set'
exit 1;
else
# shellcheck disable=SC2154
rm -rf "$GlobalSCRIPTDIR/tmp/$GlobalRUNID"
fi
3 changes: 3 additions & 0 deletions core/modules/temporary/hooks/init/init.source.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash

function tmp() {
RUNID=$(argvalue internalrunid)

LocalTEMPID=$(uuid)
# shellcheck disable=SC2154
LocalTMP="$GlobalSCRIPTDIR/tmp/$RUNID/$LocalTEMPID"
mkdir -p "$LocalTMP"
echo "$LocalTMP"
Expand Down
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert-different.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ "$HAYSTACK" == "$NEEDLE" ]; then
echo "[fail] both variables are identical: $NEEDLE == $HAYSTACK. $MESSAGE";
ERROR=1;
Expand Down
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert-file.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ -f "$NEEDLE" ]; then
echo "[pass] $MESSAGE";
else
Expand Down
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert-identical.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ "$HAYSTACK" == "$NEEDLE" ]; then
echo "[pass] $MESSAGE";
else
Expand Down
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert-no-file.source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ -f "$NEEDLE" ]; then
echo "[fail] file $NEEDLE cannot exist. $MESSAGE";
ERROR=1;
Expand Down
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert-not.source.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/bash

# shellcheck disable=SC2015
echo "$HAYSTACK" | grep "$NEEDLE" >> /dev/null && { echo "[fail] $NEEDLE found in $HAYSTACK. Failed: $MESSAGE"; ERROR=1; } || { echo "[pass] $MESSAGE."; }
2 changes: 2 additions & 0 deletions core/modules/testing/scripts/assert.source.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/bash

# shellcheck disable=SC2015
echo "$HAYSTACK" | grep "$NEEDLE" >> /dev/null && { echo "[pass] $MESSAGE"; } || { echo "[fail] $NEEDLE not found in $HAYSTACK. Failed: $MESSAGE"; ERROR=1; }
4 changes: 4 additions & 0 deletions core/modules/testing/scripts/cleanup.source.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

if [[ "$ERROR" -eq 1 ]]; then
# shellcheck disable=SC2128
echo -e "[error] $(basename "$BASH_SOURCE") Error has been detected, returning 1."
exit 1
else
# shellcheck disable=SC2128
echo -e "[pass] $(basename "$BASH_SOURCE") No error detected, returning 0."
exit 0
fi
2 changes: 2 additions & 0 deletions core/tests/modules/args/hooks/init/init.source.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ERROR=0
BASE=$(pwd)

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

echo "$1"
2 changes: 2 additions & 0 deletions core/tests/modules/args/scripts/arg-value.source.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ERROR=0
BASE=$(pwd)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ "$1" == "test-one" ]; then
NAME=firstname
VALUE=firstvalue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ERROR=0
BASE=$(pwd)

Expand All @@ -8,9 +10,9 @@ MESSAGE="$BASE/README.md must exist -- there needs to be a README file in the ba
source ./core/modules/testing/scripts/assert.source.sh

source ./core/modules/testing/scripts/cleanup.source.sh

# shellcheck disable=SC2317
PARAMS=([0]="--output-test=contains" [1]="a" [2]="space" [3]="--output-test=fully-enclosed" [4]="--output-test=partially" [5]="enclosed")

# shellcheck disable=SC2317
COMMAND=-output-test=onedash

# shellcheck disable=SC2317
ARGS=([0]="output-test-no-dash")
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

echo 'this file is required for testing'
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash

LOCATION=$1
GlobalSCRIPTDIR="$(pwd)/core/tests/modules/args/scripts/parse-arguments.source.test"
shift

function debug () {
:
}

# shellcheck disable=SC1090
source "$LOCATION"

set
2 changes: 2 additions & 0 deletions core/tests/modules/args/scripts/parse-param.source.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ERROR=0
BASE=$(pwd)

Expand Down
2 changes: 2 additions & 0 deletions core/tests/modules/args/scripts/run-command.source.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

ERROR=0
BASE=$(pwd)

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

echo 'command called in script'
Loading