refactor(lib): cleanup, remove useless code, fix lint

pull/143/head
jwerle 2 years ago committed by Joseph Werle
parent d8dae99045
commit f4665a5b74

@ -1,6 +1,17 @@
## Allow unsued variables
## Allow: To read lines rather than words, pipe/redirect to a 'while read' loop
disable=SC2013
## Allow: Unsued variables
disable=SC2034
## Allow declare and assign separately to avoid masking return values
disable=SC2155
## Double quote array expansions to avoid re-splitting elements.
## Allow: Double quote array expansions to avoid re-splitting elements
disable=SC2068
## Allow: Declare and assign separately to avoid masking return values
disable=SC2155
## Allow: Prefer mapfile or read -a to split command output (or quote to avoid splitting)
disable=SC2207
## Allow: Instead of 'let expr', prefer (( expr ))
disable=SC2219

@ -1,7 +1,7 @@
#!/bin/bash
## sets optional variable from environment
opt () { eval "if [ -z "\${"$1"}" ]; then $1='$2'; fi"; }
opt () { eval "if [ -z \"\$$1\" ]; then $1='$2'; fi"; }
## output usage
usage () {
@ -139,6 +139,7 @@ csv () {
SCRIPTS="${SCRIPTS//\"/}"
SCRIPTS="${SCRIPTS//\'/}"
SCRIPTS=($(wrap "${SCRIPTS}"))
# shellcheck disable=2219
let len=${#SCRIPTS[@]}
for (( i = 0; i < len; i++ )); do
word=${SCRIPTS[$i]}
@ -148,7 +149,7 @@ csv () {
TMP+="${word}"
fi
done
SCRIPTS="${TMP}"
SCRIPTS=("${TMP}")
}
fi
}

@ -204,8 +204,7 @@ bpkg_install () {
local let i=0
for remote in "${BPKG_REMOTES[@]}"; do
local git_remote=${BPKG_GIT_REMOTES[$i]}
bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global
if [[ "$?" == '0' ]]; then
if bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global; then
return 0
elif [[ "$?" == '2' ]]; then
error 'fatal error occurred during install'
@ -250,7 +249,7 @@ bpkg_install_from_remote () {
{
OLDIFS="$IFS"
IFS="@"
pkg_parts=($pkg)
pkg_parts=("$pkg")
IFS="$OLDIFS"
}
@ -269,7 +268,7 @@ bpkg_install_from_remote () {
{
OLDIFS="$IFS"
IFS='/'
pkg_parts=($pkg)
pkg_parts=("$pkg")
IFS="$OLDIFS"
}
@ -367,7 +366,7 @@ bpkg_install_from_remote () {
## construct scripts array
{
scripts=$(echo -n "$json" | bpkg-json -b | grep '\["scripts' | awk '{ print $2 }' | tr -d '"')
scripts=($(echo -n "$json" | bpkg-json -b | grep '\["scripts' | awk '{ print $2 }' | tr -d '"'))
## create array by splitting on newline
OLDIFS="$IFS"

@ -185,7 +185,8 @@ parse () {
parse_options "$@"
if [ "$0" = "${BASH_SOURCE}" ] || [ -z "${BASH_SOURCE}" ];
# shellcheck disable=2128
if [ "$0" = "${BASH_SOURCE[0]}" ] || [ -z "$BASH_SOURCE" ];
then
tokenize | parse
fi

@ -1,29 +0,0 @@
#! /usr/bin/env bash
cd "${0%/*}" || exit
# make test output TAP compatible
# http://en.wikipedia.org/wiki/Test_Anything_Protocol
fails=0
tests=$(ls invalid/* -1 | wc -l)
echo "1..${tests##* }"
for input in invalid/*
do
i=$((i+1))
if ../JSON.sh < "$input" > /tmp/JSON.sh_outlog 2> /tmp/JSON.sh_errlog
then
echo "not ok $i - cat $input | ../JSON.sh should fail"
#this should be indented with '#' at the start.
echo "OUTPUT WAS >>>"
cat /tmp/JSON.sh_outlog
echo "<<<"
fails=$((fails+1))
else
echo "ok $i - $input was rejected"
echo "#" $(cat /tmp/JSON.sh_errlog)
fi
done
echo "$fails test(s) failed"
exit $fails

@ -1,3 +0,0 @@
{
"hello", "comma!"
}

@ -1,35 +0,0 @@
#! /usr/bin/env bash
cd "${0%/*}" || exit
. ../JSON.sh
ptest () {
tokenize | parse >/dev/null
}
fails=0
i=0
echo "1..4"
for input in '"oooo" ' '[true, 1, [0, {}]] ' '{"true": 1}'
do
i=$((i+1))
if echo "$input" | ptest
then
echo "ok $i - $input"
else
echo "not ok $i - $input"
fails=$((fails+1))
fi
done
if ! ptest < ../bpkg.json
then
echo "not ok 4 - Parsing bpkg.json failed!"
fails=$((fails+1))
else
echo "ok $i - bpkg.json"
fi
echo "$fails test(s) failed"
exit $fails

@ -1,54 +0,0 @@
#! /usr/bin/env bash
cd "${0%/*}" || exit
. ../JSON.sh
i=0
fails=0
ttest () {
i=$((i+1))
local input="$1"; shift
local expected="$(printf '%s\n' "$@")"
echo "$expected" > /tmp/json_ttest_expected
if echo "$input" | tokenize | diff -u - /tmp/json_ttest_expected
then
echo "ok $i - $input"
else
echo "not ok $i - $input"
fails=$((fails+1))
fi
}
ttest '"dah"' '"dah"'
ttest '""' '""'
ttest '["dah"]' '[' '"dah"' ']'
ttest '" "' '" "'
ttest '" \" "' '" \" "'
ttest '["dah"]' '[' '"dah"' ']'
ttest '123' '123'
ttest '123.142' '123.142'
ttest '-123' '-123'
ttest '1e23' '1e23'
ttest '0.1' '0.1'
ttest '-110' '-110'
ttest '-110.10' '-110.10'
ttest '-110e10' '-110e10'
ttest 'null' 'null'
ttest 'true' 'true'
ttest 'false' 'false'
ttest '[ null , -110e10, "null" ]' \
'[' 'null' ',' '-110e10' ',' '"null"' ']'
ttest '{"e": false}' '{' '"e"' ':' 'false' '}'
ttest '{"e": "string"}' '{' '"e"' ':' '"string"' '}'
if ! cat ../bpkg.json | tokenize >/dev/null
then
fails=$((fails+1))
echo "Tokenizing bpkg.json failed!"
fi
echo "$fails test(s) failed"
exit $fails

@ -1,21 +0,0 @@
#! /usr/bin/env bash
cd "${0%/*}" || exit
fails=0
i=0
tests=$(ls valid/*.json -1l | wc -l)
echo "1..$tests"
for input in valid/*.json
do
expected="${input%.json}.parsed"
i=$((i+1))
if ! ../JSON.sh < "$input" | diff -u - "$expected"
then
echo "not ok $i - $input"
fails=$((fails+1))
else
echo "ok $i - $input"
fi
done
echo "$fails test(s) failed"
exit $fails

@ -1,5 +0,0 @@
[0] 1
[1] 2
[2] 3
[3] "hello"
[] [1,2,3,"hello"]

@ -1 +0,0 @@
{"foo": "{\"foo\":\"bar\"}"}

@ -1,2 +0,0 @@
["foo"] "{\"foo\":\"bar\"}"
[] {"foo":"{\"foo\":\"bar\"}"}

@ -1,4 +0,0 @@
{
"key1": "string",
"key2": 3573
}

@ -1,3 +0,0 @@
["key1"] "string"
["key2"] 3573
[] {"key1":"string","key2":3573}

@ -1,5 +0,0 @@
[ 1
, []
, [4, "hello", {}]
, {"array": []}
]

@ -1,9 +0,0 @@
[0] 1
[1] []
[2,0] 4
[2,1] "hello"
[2,2] {}
[2] [4,"hello",{}]
[3,"array"] []
[3] {"array":[]}
[] [1,[],[4,"hello",{}],{"array":[]}]

@ -1,7 +0,0 @@
{
"object": {
"key": "value",
"empty": {}
},
"number": 5
}

@ -1,5 +0,0 @@
["object","key"] "value"
["object","empty"] {}
["object"] {"key":"value","empty":{}}
["number"] 5
[] {"object":{"key":"value","empty":{}},"number":5}

@ -1,3 +0,0 @@
{
"key": "Value"
}

@ -1,2 +0,0 @@
["key"] "Value"
[] {"key":"Value"}

@ -1 +0,0 @@
"hello this is a string"

@ -1 +0,0 @@
[] "hello this is a string"

@ -1 +0,0 @@
["hello this is a string"]

@ -1,2 +0,0 @@
[0] "hello this is a string"
[] ["hello this is a string"]

@ -1 +0,0 @@
{"key":"hello this is a string"}

@ -1,2 +0,0 @@
["key"] "hello this is a string"
[] {"key":"hello this is a string"}

@ -38,11 +38,11 @@ bpkg_package () {
if [ -z "$prop" ]; then
## output all propertyies if property
## is ommited
cat "$pkg" | "$BPKG_JSON" -b
cat < "$pkg" | "$BPKG_JSON" -b
else
## show value for a specific property
## in 'bpkg.json' or 'package.json'
cat "$pkg" | "$BPKG_JSON" -b | grep "$prop" | awk '{ $1=""; printf $0 }' | tr -d '"' | sed 's/^ *//;s/ *$//'
cat < "$pkg" | "$BPKG_JSON" -b | grep "$prop" | awk '{ $1=""; printf $0 }' | tr -d '"' | sed 's/^ *//;s/ *$//'
echo
fi

@ -1,98 +0,0 @@
#!/bin/bash
## include
. term.sh
## data
declare -a data=( 0 2 3 1 3 3 3 8 2 12 4 2 4 3 )
## clean up everything
cleanup () {
## clear
term clear screen
## bring back cursor
term cursor show
return 0
}
## on SIGINT signal
onsigint () {
cleanup
exit 1
}
## clear screen
term clear screen
## position to top left
term move 0 0
## clear line
term clear line
## hide cursor
term cursor hide
## catch sigint
trap "onsigint" SIGINT
## main loop
{
let pad=3
let n=0
let w=($(tput cols))
let h=($(tput lines))
let x=0
let y=0
let len="${#data[@]}"
term clear screen
term move ${pad} 1
## y axis
for (( n = 0; n < (h - pad - 1); n += 2 )); do
term transition 0 2
term color gray
printf "."
done
y=( ${h} - 2 )
term move ${pad} ${y}
## x axis
for (( n = 0; n < (w - pad * 3); n += 6)); do
term color gray
printf "."
term transition 6 0
done
x=0
for (( i = 0; i < len; ++i )); do
let n="${data[$i]}"
while (( n-- )); do
if (( n < 0 )); then
break
fi
let a=( ${x} * 6 + ${pad} )
let b=( ${h} - ${n} + ${pad} )
#echo $a $b
term move ${a} ${b}
term reset
printf "█"
done
(( x++ ))
sleep .5
done
h=( ${h} - 1)
term move ${w} ${h}
}
## clean up terminal
cleanup
## exit
exit $?
Loading…
Cancel
Save