FP507 · redundant-empty-comparison
A condition compares a value with `''` (`!= ''`, `== ''`), which `if:` already does by itself.
| Code | Name | Category | Default severity | Reported by |
|---|---|---|---|---|
FP507 | redundant-empty-comparison | Env & expressions | ⚪ off (opt-in) | lint, check, the action, the editor |
Why it matters
An if: treats '', null, 0 and false as false and every other value as true, so x != '' decides it the same way as x, and x == '' as !x. Outside a condition the comparison matters: under env:, with: or outputs: it turns the value into true or false, and continue-on-error: accepts only a boolean.
How to fix
Remove the comparison: x != '' becomes x, and x == '' becomes !x. The editor offers it as a quick fix where the change is certain.
Example
if: ${{ steps.patch.outputs.file != '' && steps.check.outputs.skip == '' }}Scope
Only a comparison with the string '' that decides the condition: the whole if:, or an operand of !, && or || in it. Not != null, != 0 or != false, which differ for '0'; not inside a comparison, a function's arguments (case() requires real booleans) or an if: with text around its ${{ }}, which is always true; not under env:, with:, outputs: or continue-on-error:. While FP105 runs, not for an optional input without a default: FP105 reports one decided by its truthiness, and counts != '' as handling the omitted case. Nor a condition that a YAML alias shares with another key (if: *flag), whose text may be a value. Off by default: the comparison is harmless, and some prefer it written out; turn it on with FP507: info. The quick fix is offered for a condition written on one line, not in a single-quoted YAML string, in a file with LF line endings; not for a value in parentheses ((a || b) != '') or a matrix value (YAML's .nan compares otherwise), nor when the condition would then start with ! without ${{ }}, which YAML reads as a tag. Not reported in generated files, which are not edited by hand.
Accept one finding
When a finding is intended, accept it with a reason rather than turning the rule off. It is listed apart from the other findings, and does not fail the build.
On its line, with an ignore comment alone on the line above it (the
editor's quick fix adds it there) or at the end of the line, after any other comment such as a version
(# v4.3.0 # flowpact: ignore[FP507] why):
# flowpact: ignore[FP507] why it is acceptable here
<the line of the finding>In the config, with an override, which can expire:
overrides:
- rule: FP507
target: <the finding's symbol>
reason: Why it is acceptable here, at least 10 characters.
expires: YYYY-MM-DD # optionaltarget is the symbol the finding is about; to list them:
flowpact lint --format json | jq -r '.findings[] | select(.code == "FP507") | .symbol'* matches within a path segment and ** across segments, so one entry accepts every finding whose symbol matches:
target: '**#inputs.app-id' is that input in every workflow and action.
Change the severity
Change the severity (or turn the rule off) in .github/flowpact/flowpact.config.yml, by code or by name:
rules:
FP507: warning
# or: redundant-empty-comparison: errorExplain it in the terminal:
flowpact explain FP507Related
FP105optional-input-no-default-in-condition: An optional input that is '' when omitted (no default, ordefault: '') decides anif:by its truthiness.FP506value-not-boolean: A value read as a boolean can be another string:fromJSON()of a value that may be '', a comparison with 'true' of a value that may be other text, or anenv:,with:oroutputs:value that gives a boolean or text.
FP506 · value-not-boolean
A value read as a boolean can be another string: `fromJSON()` of a value that may be '', a comparison with 'true' of a value that may be other text, or an `env:`, `with:` or `outputs:` value that gives a boolean or text.
FP601 · call-cycle
Reusable workflows call each other in a cycle.