FP402 · matrix-key-missing-in-combo
An expression reads a matrix key that is only defined in some combinations.
| Code | Name | Category | Default severity | Reported by |
|---|---|---|---|---|
FP402 | matrix-key-missing-in-combo | Matrix | 🟡 warning | lint, 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:64Why 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):
# 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:
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 # optionaltarget 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:
rules:
FP402: off
# or: matrix-key-missing-in-combo: errorExplain it in the terminal:
flowpact explain FP402Related
FP401empty-binding-for-matrix-combo: An input passed underwith:is empty for some matrix combinations because a matrix key is missing there.FP404undefined-matrix-key: An expression reads a matrix key that no combination defines (or the job has no matrix).- How matrices are expanded