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

build(ci): add shellcheck linting #57

Open
wants to merge 4 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
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: reviewdog
on:
push:
branches-ignore:
- 'gh-pages'

jobs:
shellcheck:
name: shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: shellcheck
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
path: "./commands/inits/data"
pattern: "*.sh"
2 changes: 2 additions & 0 deletions commands/inits/data/aliases.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source file: aliases.sh
# shellcheck shell=sh
alias gs='scmpuff_status'
alias ga='git add'
alias gd='git diff'
Expand Down
5 changes: 4 additions & 1 deletion commands/inits/data/git_wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# source file: git_wrapper.sh
# shellcheck shell=sh

# Remove any existing git alias or function
unalias git > /dev/null 2>&1
unset -f git > /dev/null 2>&1
Expand All @@ -6,7 +9,7 @@ unset -f git > /dev/null 2>&1
SCMPUFF_GIT_CMD=${SCMPUFF_GIT_CMD:-"$(\which git)"}
export SCMPUFF_GIT_CMD

function git() {
git() {
case $1 in
commit|blame|log|rebase|merge)
scmpuff exec -- "$SCMPUFF_GIT_CMD" "$@";;
Expand Down
46 changes: 23 additions & 23 deletions commands/inits/data/status_shortcuts.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# source file: status_shortcuts.sh
# shellcheck shell=sh

scmpuff_status() {
local scmpuff_env_char="e"
__scmpuff_env_char="e"

# Ensure shwordsplit is on for zsh
if [ -n "$ZSH_VERSION" ]; then setopt shwordsplit; fi;

# Run scmpuff status, store output
# (`local` needs to be on its own line otherwise exit code is swallowed!)
local cmd_output
cmd_output="$(/usr/bin/env scmpuff status --filelist $@)"
__scmpuff_status_cmd_output=$(/usr/bin/env scmpuff status --filelist "$@")
__scmpuff_status_exit=$?

# if there was an error, exit prematurely, and pass along the exit code
# (STDOUT was swallowed but not STDERR, so user should still see error msg)
local es=$?
if [ $es -ne 0 ]; then
return $es
if [ $__scmpuff_status_exit -ne 0 ]; then
return $__scmpuff_status_exit
fi

# Fetch list of files (from first line of script output)
files="$(echo "$cmd_output" | head -n 1)"
__scmpuff_files="$(echo "$__scmpuff_status_cmd_output" | head -n 1)"

# Export numbered env variables for each file
scmpuff_clear_vars
IFS=$'\t'
local e=1
for file in $files; do
export $scmpuff_env_char$e="$file"
let e++
IFS=$(printf '\t')
__scmpuff_loop_e=1
for __scmpuff_file in $__scmpuff_files; do
export $__scmpuff_env_char$__scmpuff_loop_e="$__scmpuff_file"
__scmpuff_loop_e=$((__scmpuff_loop_e+1)) #e++
done
IFS=$' \t\n'
IFS=$(printf ' \t\n')

# Print status (from line two onward)
echo "$cmd_output" | tail -n +2
echo "$__scmpuff_status_cmd_output" | tail -n +2

# Reset zsh environment to default
if [ -n "$ZSH_VERSION" ]; then unsetopt shwordsplit; fi;
}


# Clear numbered env variables
scmpuff_clear_vars() {
local scmpuff_env_char="e"
local i

for (( i=1; i<=999; i++ )); do
local env_var_i=${scmpuff_env_char}${i}
if [[ -n ${env_var_i} ]]; then
unset ${env_var_i}
__scmpuff_env_char="e"
__scmpuff_loop_i=0
while [ $__scmpuff_loop_i -le 999 ]; do
__scmpuff_env_var_i=${__scmpuff_env_char}${__scmpuff_loop_i}
if [ -n "$__scmpuff_env_var_i" ]; then
unset "$__scmpuff_env_var_i"
else
break
fi
__scmpuff_loop_i=$((__scmpuff_loop_i+1)) #i++
done
}
2 changes: 1 addition & 1 deletion features/command_init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: init command

Scenario Outline: --wrap controls git cmd wrapping in output (default: yes)
When I successfully run `scmpuff init <flags>`
Then the output <should?> contain "function git()"
Then the output <should?> contain "git() {"
Examples:
| flags | should? |
| -s | should |
Expand Down