koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.43k stars 1.78k forks source link

IF-THEN-FI Blocks should not report SC1143 (error): This backslash is part of a comment #2697

Open byrnejb opened 1 year ago

byrnejb commented 1 year ago

For bugs

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

Check SC1143 is intended to prevent premature termination of multi-line single commands. An IF-THEN-FI block is not a single multi-line command and yet this error is still reported.

#!/bin/env bash
. . .
  if [[ -n ${INVNUMB} ]]; \
    then \
#      echo "1 $INVNUMB" ;  \

Here's what shellcheck currently says:

In freebsd/bash/hp3000_pcl_pdf/hp3000_inv_pdf_xfr.sh line 106:
#      echo "1 $INVNUMB" ; \
                            ^-- SC1143 (error): This backslash is part of a comment and does not continue the line.

Here's what I wanted or expected to see:

Nothing

rpdelaney commented 1 year ago

The \ seems to have no syntactic significance here. Why do you want to include it?

byrnejb commented 1 year ago

On Sat, February 18, 2023 14:26, Ryan Delaney wrote:

The \ seems to have no syntactic significance here. Why do you want to include it?

Because this section of code is used for testing and I often cut and paste such sections into the shell after removing the comment #. The \ keeps the code together so that I can step though history to rerun it.

I could just make the code active in the script and surround it with another conditional block but having it commented out makes it crystal clear that the code section is not in use.

Regardless, I gather that this shell check is to detect interleaved comments in multi-line arguments and options passed to a single command parser; and not to detect comments in a if-then construct containing multiple commands.

If it is more bother than it is worth to alter the check then I can live with that. I just thought that you ought to know.

Regards,

-- e-Mail is NOT a SECURE channel Do NOT transmit sensitive data via e-Mail Unencrypted messages have no legal claim to privacy Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne @.*** Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3

TinCanTech commented 1 year ago

Because this section of code is used for testing and I often cut and paste such sections

Cut 'n' paste, such a gift ..

I recognise this pattern of coding, completely. No doubt, it is regularly employed.

I agree that # comment followed by \ should be exempt, a comment is a comment, after all.

Is this # comment \ syntax well defined by various shells ?

...

However, I choose to allow shellcheck to draw a faint line-in-the-sand for me to act upon, accordingly.