Skip to content

SC2145 false positive when using backslash-newline #3192

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

Open
krayon opened this issue Apr 24, 2025 · 0 comments
Open

SC2145 false positive when using backslash-newline #3192

krayon opened this issue Apr 24, 2025 · 0 comments

Comments

@krayon
Copy link

krayon commented Apr 24, 2025

For bash, a line ending with a backslash causes a false positive unless the backslash is proceeded with a space, eg:

echo "${@}"\
    |less

The following script:

#!/bin/bash

echo "1: This should not cause SC2145 error but does"; echo "${@}"\
|less

echo "2: This should not cause SC2145 error but does"; echo "${@}"\
    |less

echo "5: This should not cause SC2145 error but does"; echo "${@}"\
    "test"

echo "3: This correctly does not cause SC2145 error"; echo "${@}"|less

echo "4: This correctly does not cause SC2145 error"; echo "${@}" \
    |less

echo "6: This correctly does not cause SC2145 error"; echo "${@}" \
    "test"

echo "7: This correctly causes a SC2145 error"; echo "${@} test"

Gives the following output:


In test.bash line 3:
echo "1: This should not cause SC2145 error but does"; echo "${@}"\
                                                             ^--^ SC2145 (error): Argument mixes string and array. Use * or separate argument.


In test.bash line 6:
echo "2: This should not cause SC2145 error but does"; echo "${@}"\
                                                             ^--^ SC2145 (error): Argument mixes string and array. Use * or separate argument.


In test.bash line 9:
echo "5: This should not cause SC2145 error but does"; echo "${@}"\
                                                             ^--^ SC2145 (error): Argument mixes string and array. Use * or separate argument.


In test.bash line 20:
echo "7: This correctly causes a SC2145 error"; echo "${@} test"
                                                      ^--^ SC2145 (error): Argument mixes string and array. Use * or separate argument.
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

1 participant