Skip to Content
flowpact

FP402 · matrix-key-missing-in-combo

An expression reads a matrix key that is only defined in some combinations.

CodeNameCategoryDefault severityReported by
FP402matrix-key-missing-in-comboMatrix🟡 warninglint, check, the action, the editor

What you see

In the dynamic-matrix fixture:

▲  WARN  FP402 matrix-key-missing-in-combo
  matrix.shard is undefined in 2 of 3 combinations of jobs.sharded
  ▶ .github/workflows/matrix.yml:33:64

Why it matters

In combinations without the key the value is an empty string. Scripts, env vars and runner labels built from it silently degrade (e.g. --config= with no value).

How to fix

Define the key for every combination, or add a fallback (${{ matrix.key || 'default' }}).

Example

strategy:
  matrix:
    include:
      - os: ubuntu-latest
        config: ci/linux.json
      - os: windows-latest   # no config
steps:
  - run: ./test.sh --config=${{ matrix.config }}

Scope

Not reported: conditions (if:) and continue-on-error, comparisons and negations (matrix.key != '', !matrix.key), matrix.key && ... guards, quoted shell tests in run: scripts ([[ -z "${{ matrix.key }}" ]], [ "${{ matrix.key }}" = on ]), and combinations where the job or step is skipped by its own if:.

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

.github/workflows/matrix.yml
# flowpact: ignore[FP402] why it is acceptable here
- run: ./test.sh --suite ${{ matrix.suite }} --shard ${{ matrix.shard }}

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

.github/flowpact/flowpact.config.yml
overrides:
  - rule: FP402
    target: ".github/workflows/matrix.yml#jobs.sharded.matrix.shard"
    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 == "FP402") | .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:
  FP402: off
  # or: matrix-key-missing-in-combo: error

Explain it in the terminal:

flowpact explain FP402
  • FP401 empty-binding-for-matrix-combo: An input passed under with: is empty for some matrix combinations because a matrix key is missing there.
  • FP404 undefined-matrix-key: An expression reads a matrix key that no combination defines (or the job has no matrix).
  • How matrices are expanded

On this page