From 2d23c5173630f76d4d487979b60a00afdf34ddd6 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 07:47:53 +0000 Subject: [PATCH 1/3] - Fix shellcheck SC2124 in the generated script --- lib/completely/templates/template.erb | 3 ++- spec/approvals/cli/generated-script | 3 ++- spec/approvals/cli/generated-script-alt | 3 ++- spec/approvals/cli/generated-wrapped-script | 3 ++- spec/approvals/cli/test/completely-tester.sh | 3 ++- spec/approvals/completions/function | 3 ++- spec/approvals/completions/script | 3 ++- spec/approvals/completions/script-only-spaces | 3 ++- spec/approvals/completions/script-with-debug | 3 ++- spec/fixtures/tester/default.bash | 3 ++- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/completely/templates/template.erb b/lib/completely/templates/template.erb index d93b29d..1c134c5 100644 --- a/lib/completely/templates/template.erb +++ b/lib/completely/templates/template.erb @@ -6,7 +6,8 @@ <%= function_name %>() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" % if ENV['COMPLETELY_DEBUG'] if [[ -n "$COMPLETELY_DEBUG" ]]; then diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index 2b281c1..6a96aa4 100644 --- a/spec/approvals/cli/generated-script +++ b/spec/approvals/cli/generated-script @@ -6,7 +6,8 @@ _mygit_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'status'*) diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index c801c71..5836055 100644 --- a/spec/approvals/cli/generated-script-alt +++ b/spec/approvals/cli/generated-script-alt @@ -6,7 +6,8 @@ _mycomps() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'status'*) diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index 9e0206b..f9a72fd 100644 --- a/spec/approvals/cli/generated-wrapped-script +++ b/spec/approvals/cli/generated-wrapped-script @@ -7,7 +7,8 @@ give_comps() { echo $'' echo $'_mygit_completions() {' echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"' + echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' + echo $' local compline="${compwords[*]}"' echo $'' echo $' case "$compline" in' echo $' \'status\'*)' diff --git a/spec/approvals/cli/test/completely-tester.sh b/spec/approvals/cli/test/completely-tester.sh index 8208730..1281700 100644 --- a/spec/approvals/cli/test/completely-tester.sh +++ b/spec/approvals/cli/test/completely-tester.sh @@ -14,7 +14,8 @@ fi _mygit_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'status'*) diff --git a/spec/approvals/completions/function b/spec/approvals/completions/function index fd104a3..08230d9 100644 --- a/spec/approvals/completions/function +++ b/spec/approvals/completions/function @@ -7,7 +7,8 @@ send_completions() { echo $'' echo $'_completely_completions() {' echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"' + echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' + echo $' local compline="${compwords[*]}"' echo $'' echo $' case "$compline" in' echo $' \'generate\'*)' diff --git a/spec/approvals/completions/script b/spec/approvals/completions/script index df8761a..7714257 100644 --- a/spec/approvals/completions/script +++ b/spec/approvals/completions/script @@ -6,7 +6,8 @@ _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'generate'*) diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index ec5bc59..90a94f9 100644 --- a/spec/approvals/completions/script-only-spaces +++ b/spec/approvals/completions/script-only-spaces @@ -6,7 +6,8 @@ _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'generate'*) diff --git a/spec/approvals/completions/script-with-debug b/spec/approvals/completions/script-with-debug index 017f691..99149f3 100644 --- a/spec/approvals/completions/script-with-debug +++ b/spec/approvals/completions/script-with-debug @@ -6,7 +6,8 @@ _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" if [[ -n "$COMPLETELY_DEBUG" ]]; then echo "compline: '$compline'" > 'completely-debug.txt' diff --git a/spec/fixtures/tester/default.bash b/spec/fixtures/tester/default.bash index 8c91d19..b212310 100644 --- a/spec/fixtures/tester/default.bash +++ b/spec/fixtures/tester/default.bash @@ -6,7 +6,8 @@ _cli_completions() { local cur=${COMP_WORDS[COMP_CWORD]} - local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}" + local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") + local compline="${compwords[*]}" case "$compline" in 'command childcommand'*) From 8bea02bf160ed6d3d377b86499c5cc6cfe1e7e70 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 08:08:00 +0000 Subject: [PATCH 2/3] add shellcheck specs --- spec/completely/commands/generate_spec.rb | 5 +++++ spec/completely/tester_spec.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/completely/commands/generate_spec.rb b/spec/completely/commands/generate_spec.rb index e60c86c..b76f7c6 100644 --- a/spec/completely/commands/generate_spec.rb +++ b/spec/completely/commands/generate_spec.rb @@ -16,6 +16,11 @@ expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args') expect(File.read "completely.bash").to match_approval('cli/generated-script') end + + it "generates a shellcheck compliant script" do + expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args') + expect(`shellcheck completely.bash`).to be_empty + end end context "with CONFIG_PATH" do diff --git a/spec/completely/tester_spec.rb b/spec/completely/tester_spec.rb index d29074d..b10d81f 100644 --- a/spec/completely/tester_spec.rb +++ b/spec/completely/tester_spec.rb @@ -24,7 +24,7 @@ end end - describe '#test', :focus do + describe '#test' do it "returns an array with completions" do expect(subject.test compline).to eq ["command", "conquer"] end From 71afe4b6fc34ff715b6800208d21c6ae6bdd4bf9 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 08:40:34 +0000 Subject: [PATCH 3/3] tighten shellcheck spec --- spec/completely/commands/generate_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/completely/commands/generate_spec.rb b/spec/completely/commands/generate_spec.rb index b76f7c6..61d68fe 100644 --- a/spec/completely/commands/generate_spec.rb +++ b/spec/completely/commands/generate_spec.rb @@ -19,7 +19,7 @@ it "generates a shellcheck compliant script" do expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args') - expect(`shellcheck completely.bash`).to be_empty + expect(`shellcheck completely.bash 2>&1`).to be_empty end end