sh icon indicating copy to clipboard operation
sh copied to clipboard

syntax: extra white-space before trailing comments after some compound commands

Open antichris opened this issue 3 years ago • 0 comments

Some extra whitespace is added before trailing comments after

  1. brace groups
    {
    	foo #inline
    } #trailing
    
    foo() {
    	bar #inline
    } #trailing
    
    {
    	foo #inline
    }    #trailing
    
    foo() {
    	bar #inline
    }    #trailing
    
  2. subshells
    (
    	foo #inline
    ) #trailing
    
    foo() (
    	bar #inline
    ) #trailing
    
    (
    	foo #inline
    )    #trailing
    
    foo() (
    	bar #inline
    )    #trailing
    
  3. command substitutions
    foo=$(
    	bar #inline
    ) #trailing
    
    foo=$(
    	bar #inline
    )    #trailing
    
  4. if clauses
    if foo; then
    	bar #inline
    fi #trailing
    
    if foo; then
    	bar #inline
    fi   #trailing
    
Altogether that looks like a weak effort to align with the above inline comment, as it is done for case.
case $foo in
?) bar;; #inline
esac #trailing
case $foo in
?) bar ;; #inline
esac      #trailing
Nothing of the sort is being done to loop constructs (for, while and until), for which output is the same as input.
for foo; do
	bar #inline
done #trailing

while foo; do
	bar #inline
done #trailing

until foo; do
	bar #inline
done #trailing
for foo; do
	bar #inline
done #trailing

while foo; do
	bar #inline
done #trailing

until foo; do
	bar #inline
done #trailing

I'm not sure how often trailing comments on these constructs are used in practice, and whether they really are most commonly used for a continuation of the previous line (I'm inclined to doubt that is the case, but I may be biased).

antichris avatar Apr 07 '22 16:04 antichris