Skip to Content
flowpact

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.

CodeNameCategoryDefault severityReported by
FP506value-not-booleanEnv & expressions🔴 errorlint, check, the action, the editor

What you see

In the boolean-values fixture:

▲  WARN  FP506 value-not-boolean
  `needs.scan.outputs.is-report` is compared with `'true'`, but it can hold other text, and the comparison is then false: it is 'true' | text of `inputs.report-file` | '' (`inputs.report-file` omitted)
  ▶ .github/workflows/ci.yml:13:9

Why it matters

Only an if: reads a value as true or false. Under env:, with: and outputs: a value is passed on as text: a comparison gives 'true' or 'false', but a || b gives the operand itself, and an optional input is '' when omitted. fromJSON('') fails the job (continue-on-error: ${{ fromJSON(env.X) }} is the usual reader), and so does fromJSON() of a file name. A reader that compares the value with 'true' takes the false branch for any other text, and the run stays green. Reported as an error for fromJSON(), as a warning otherwise.

How to fix

Compare explicitly where the value is set, so that it is 'true' or 'false': inputs.x != '' (or inputs.x == 'yes'). A literal fallback (inputs.x || 'false') only fixes the empty case. The editor offers != '' as a quick fix where it is certain.

Example

- env:
    CONTINUE_ON_ERROR: ${{ inputs.report-file }}
  continue-on-error: ${{ fromJSON(env.CONTINUE_ON_ERROR) }}
  run: ./test.sh
outputs:
  is-report: ${{ steps.changed.outputs.any == 'true' || inputs.report-file }}

Scope

fromJSON() is reported only for a '' flowpact can point at: an optional input without a default (or with default: '') that a caller can omit (as for FP105, not one every local caller passes, unless the workflow can be dispatched or the unit is published), or the output of a step whose if: can skip it; not when the reader's own job or step if:, or an earlier operand of its &&, || or case(), reads the same input, output or github property. In a field that takes a boolean (continue-on-error:, a type: boolean input) such an input is reported even when every local caller passes it, since other text than 'true' or 'false' fails there too, unless each passes 'true' or 'false' as it is, or one expression that gives a boolean in the caller (${{ inputs.dry }} of an input every trigger of the caller declares type: boolean, a comparison, !, contains()). The || is reported when one of its operands is a boolean (a comparison, !, contains(), a boolean input, or 'true'/'false') and another is text; not c && 'yes' || 'no', which is always text, nor an && alone. Values known only at run time (a script’s outputs, github.event, the matrix) are never reported. Not reported either: comparisons in a run: script ([[ "$X" == "true" ]]), the fall-through of c && a || b when a is '', a value that is always 'true' or 'false' read by an if: (where 'false' is true), and text passed in with: to a type: boolean input. The quick fix is offered for a value written on one line, where each text operand is a reference that is text or '', and for fromJSON() only where it must give a boolean: continue-on-error:, a condition, or a type: boolean input.

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[FP506] why):

.github/workflows/ci.yml
# flowpact: ignore[FP506] why it is acceptable here
if: needs.scan.outputs.is-report == 'true'

In the config, with an override, which can expire:

.github/flowpact/flowpact.config.yml
overrides:
  - rule: FP506
    target: ".github/workflows/ci.yml#jobs.scan.outputs.is-report"
    reason: Why it is acceptable here, at least 10 characters.
    expires: YYYY-MM-DD   # optional

target is the symbol the finding is about; to list them:

flowpact lint --format json | jq -r '.findings[] | select(.code == "FP506") | .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:

.github/flowpact/flowpact.config.yml
rules:
  FP506: off
  # or: value-not-boolean: error

Explain it in the terminal:

flowpact explain FP506
  • FP507 redundant-empty-comparison: A condition compares a value with '' (!= '', == ''), which if: already does by itself.
  • FP103 input-type-mismatch: A literal value passed to a typed workflow_call input has the wrong type.

On this page