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

Skip SC2015 when the last command is true #3114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Flu
Copy link

@Flu Flu commented Jan 7, 2025

In cases like

#!/bin/sh
set -e
foo && bar || true

The last true is used for masking the return value, no matter if both foo and bar executed, therefore SC2015 has no relevance here.

Closes #2977

@SvenStaehs
Copy link

SvenStaehs commented Mar 10, 2025

Thank you! Hope to see this included in the next release, we are due one any day now 😆
My use-case for the record:

#!/usr/bin/env bash
set -euo pipefail
[...]
for attempt in {3..0}; do
    [[ $attempt -gt 0 ]] || die "Failed to [do the thing]."
    # shellcheck disable=SC2015 # "break" never fails (I think), AND "true" has no side-effect, so this rule does not apply. See https://github.com/koalaman/shellcheck/issues/2977
    doSomethingFlaky && break || true
done

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

Successfully merging this pull request may close these issues.

Skip SC2015 when it end with: || true
2 participants