From 84327a6f296656e207dc528e0872dc808a47c81f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 11 Oct 2025 11:50:15 +0800 Subject: [PATCH] Fix Parameters:value handling to prevent unmatched braces error Resolves: #5 The Parameters:value construct in shellspec is a standalone declaration that doesn't require wrapping with braces like other DSL constructs. Previously, altshfmt was adding opening braces after Parameters:value lines but no matching closing braces, causing shfmt to fail with "reached EOF without matching { with }". This fix adds special handling for Parameters:value to skip brace wrapping while preserving correct behavior for other Parameters variants (block, matrix, dynamic) that do require braces. Co-Authored-By: Claude Signed-off-by: Coiby Xu --- altshfmt | 4 ++++ spec/altshfmt_spec.sh | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/altshfmt b/altshfmt index 686659b..e60fc07 100755 --- a/altshfmt +++ b/altshfmt @@ -174,6 +174,10 @@ altshfmt() { /^[[:space:]]*('"$SHELLSPEC_DSL_ONLINE_DATA"').*/ { next } + /^[[:space:]]*(Parameters:value)([[:space:]].*|$)/ { + # Parameters:value is a standalone construct and does not need braces + next + } /^[[:space:]]*('"$SHELLSPEC_DSL_BEGIN"')([[:space:]].*|$)/ { while(match($0, /.*\\$/)) { getline; print } print "{ # @@altsh@@begin" diff --git a/spec/altshfmt_spec.sh b/spec/altshfmt_spec.sh index c56c2fd..c3613f3 100644 --- a/spec/altshfmt_spec.sh +++ b/spec/altshfmt_spec.sh @@ -201,4 +201,52 @@ Describe "altshfmt" The output should eq "1: arg1 arg2 -l" End End + + # Regression tests + Describe "Parameters:value handling" + Context "when Parameters:value is used in shellspec" + Data + #|#!/bin/bash + #| + #|Parameters:value aarch64 ppc64le s390x x86_64 + #| + #|It 'is simple' + #| When call echo "$1" + #| The output should eq "$1" + #|End + End + + It "formats without syntax errors" + When call altshfmt + The status should be success + The output should include "Parameters:value aarch64 ppc64le s390x x86_64" + End + + It "produces valid shell syntax" + When call bash -c './altshfmt | bash -n' + The status should be success + End + End + + Context "when other Parameters variants are used" + Data + #|#!/bin/bash + #| + #|Parameters:block + #| foo bar + #|End + #| + #|It 'test' + #| echo hello + #|End + End + + It "still formats Parameters:block correctly" + When call altshfmt + The status should be success + The output should include "Parameters:block" + The output should include "foo bar" + End + End + End End