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

False positive for SC1003 #3032

Open
2 tasks done
ale5000-git opened this issue Jul 30, 2024 · 4 comments
Open
2 tasks done

False positive for SC1003 #3032

ale5000-git opened this issue Jul 30, 2024 · 4 comments

Comments

@ale5000-git
Copy link

ale5000-git commented Jul 30, 2024

For bugs

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

#!/bin/sh

echo 'abc test' | tr -d '\\'

Here's what shellcheck currently says:

echo 'abc test' | tr -d '\\'
                          ^-- SC1003 (info): Want to escape a single quote? echo 'This is how it'\''s done'.

Here's what I wanted or expected to see:

It is the backslash that is escaped, not the single quote.

The backslash in tr need to be escaped, otherwise bash say this:

echo 'abc test' | tr -d '\'
tr: warning: an unescaped backslash at end of string is not portable
@wileyhy
Copy link

wileyhy commented Aug 2, 2024 via email

@brother
Copy link
Collaborator

brother commented Aug 6, 2024

@wileyhy a edit to the wiki is helpful indeed. but the case pointed out by OP is still valid I think.

Not sure it will be possible to handle all the permutations with a nice and easy information message though.
Decipher the actual intent is always hard. Did they forget the end single quote? And why was there two back slashes to begin with...

@ale5000-git
Copy link
Author

And why was there two back slashes to begin with...

Because bash warn against this:
tr -d '\'
So it need to be this:
tr -d '\\'

@brother
Copy link
Collaborator

brother commented Aug 9, 2024

It was meant as a point in an imaginary internal reasoning leading up to that it's hard to understand the exact intent of code.
If they are missing a backslash, or added one too many. Or was missing a single quote. Or something completely different. People are hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants