Skip to content
Fallow home
All docs pages

Docs home

fallow baselines

fallow baselines prune removes the entries of a committed baseline that match no current finding.

Keep the committed baseline files current.

For the baseline workflow, read Baselines.

Synopsis

fallow baselines [OPTIONS] <COMMAND>

Subcommands

SubcommandDescription
pruneRemove the baseline entries that match no current finding

prune

Remove each baseline entry that matches no current finding. Prune never adds an entry.

fallow baselines prune [OPTIONS]
OptionDescription
--checkReport the entries that a prune would remove, and write nothing
--dead-code-baseline <PATH>The dead-code baseline to prune. Overrides audit.deadCodeBaseline
--health-baseline <PATH>The health baseline to prune. Overrides audit.healthBaseline
--dupes-baseline <PATH>The duplication baseline to prune. Overrides audit.dupesBaseline
--coverage <PATH>The coverage input for CRAP scores, as for fallow health --coverage. Use the input that the health baseline was saved with
--coverage-root <PATH>Rebase the file paths of the coverage input onto this root

The global options are in these groups: Project, Output, Scope, Baselines, Gates, Duplication, Type-aware, Performance.

Prune reads the files that audit.deadCodeBaseline, audit.healthBaseline and audit.dupesBaseline name in the config file. A file option replaces the config path for one file. Prune analyzes the whole project, so it refuses --changed-since, --workspace, --changed-workspaces, --diff-file, --diff-stdin, and the global baseline options.

Prune runs in one mode. To prune a baseline that you saved with --production or --include-entry-exports, pass the same option. Prune skips a file that it cannot match to the mode of the run, or a file with an older key form, and prints the command that saves the file again.

Options

fallow baselines has no options of its own. The section of each subcommand under Subcommands lists its options.

Option details

What prune keeps

  • Prune keeps exactly the entries that --baseline matches, so a pruned file hides the same findings as before.
  • Prune never adds an entry. To record new findings on purpose, run --save-baseline on fallow dead-code, fallow health or fallow dupes.
  • Prune keeps the order of the file, and writes a file only when it removes an entry. It writes through a temporary file and a rename. It refuses a path that is a symbolic link.
  • In a health baseline, a slot of a higher severity can cover a finding of a lower severity, as with --baseline. An identity entry that follows a moved file keeps its saved key. An identity entry that loses all its slots stays as an empty object while the run reports its function, so the move matching does not change.
  • Prune does not change the runtime-coverage keys and the refactoring target keys of a health baseline.

Whole-project scope

A narrowed run would remove the entries of findings that it did not see. So prune exits with code 2 on --changed-since, --workspace, --changed-workspaces, --diff-file, --diff-stdin and the FALLOW_DIFF_FILE environment variable. It ignores workspaces.changedSince. It also exits with code 2 on --baseline, --save-baseline, --fail-on-baseline-growth and --baseline-base.

The CRAP scores of a health baseline depend on coverage. Prune reads --coverage, else FALLOW_COVERAGE, else health.coverage. Pass the input that you saved the health baseline with.

Mode of the file

--production and --include-entry-exports change which findings exist. A run in another mode does not see the findings of the file, so it would remove valid entries. Prune skips such a file with the reason_code scope-mismatch. It also skips a file that has no record of a mode that the run uses, for example a file that an older version saved. So --check can exit with code 2 in a project that sets production mode in the config. Review the findings of the file, then save it again in that mode:

fallow dead-code --production --save-baseline fallow-baselines/dead-code.json

Skipped files

Prune does not change a file that it cannot match entry by entry. It reports the file as refused, prints the command that saves it again, and exits with code 2. The other files are still pruned. A file is skipped when:

  • another command saved it;
  • it uses an older key form, for example a dead-code baseline without identity;
  • a type-aware run saved it;
  • it has fields that this version does not know, for example from a newer fallow version;
  • it is a duplication baseline with the old clone keys that unrelated groups shared. See Collision handles.

A file that does not exist or cannot be read gets the status error.

Pre-commit hook

fallow hooks install --target git --prune-baselines writes a hook that prunes before the audit. Prune reads the working tree, and the commit holds the index. So the hook prunes only when the working tree has no unstaged changes and no untracked files, and then runs git add -u. Otherwise it prints a note and skips the prune. It also skips the prune for a commit with paths (git commit <path> or --only), because git builds a temporary index for such a commit. A failed prune never blocks the commit, because the audit is the gate. For Lefthook or a hook that exists, the install command prints the lines to add.

Output

fallow baselines prune
Pruned 1 entry from the dead-code baseline fallow-baselines/dead-code.json (6 -> 5)
  unused_exports: unused-export:src/services/orders.ts:cancelOrder
dupes baseline fallow-baselines/dupes.json: nothing to prune (1 entry)

Each file gets one line with the number of entries before and after. An indented line gives each removed entry: its category and its key. With --check, the lines start with Would prune.

With --format json, the output has these top-level fields:

FieldContent
kind"baselines-prune"
schema_versionThe version of this output format.
checktrue for a run with --check.
filesOne object for each file: kind, path, status, entries_before, entries_after, removed, reason_code, reason.
actionsstage-baselines with the git add command for the written files, prune-baselines after --check, and resave-baseline for each skipped file.

status is pruned, would-prune, unchanged, refused (skipped) or error. reason_code gives the cause of a skip: parse-error, not-this-kind, legacy-keys, unknown-key-scheme, incompatible-identity, shared-clone-keys, unknown-fields or scope-mismatch. It is null for error and the other statuses. reason is a sentence for people, set for refused and error. Each removed entry has category, key and count. For a scope-mismatch skip, the action is prune-baselines with the mode options of the file when the run can prune it, else resave-baseline. The JSON output reference has each field.

Baseline staleness

A run of fallow dead-code, fallow dupes or fallow health with --baseline has a baseline_staleness object. It tells how much of the baseline still matches:

{
  "baseline_entries": 7,
  "matched_entries": 6,
  "stale_entries": 1,
  "current_findings": 6,
  "change_scoped": false,
  "stale": false,
  "warning": "none",
  "gate_trips": true,
  "moved_entries": 0
}
FieldContent
baseline_entries, matched_entries, stale_entriesThe entries of the file, the entries that matched a current finding, and the entries that matched none.
current_findingsThe findings of the run before the baseline filtered them.
remaining_findingsHealth only: the functions above a threshold that the baseline does not hold.
change_scopedtrue when the run cannot judge the file, because it saw only part of the project or ran in another mode. Then stale and gate_trips are false.
scope_reasonsPresent when change_scoped is true: each cause, for example diff, changed-since, changed-files, package-baselines, workspace, changed-workspaces, scope, file, issue-type-filter, production or include-entry-exports. The set is open.
stale, warningtrue when fallow printed the staleness warning. warning is none, partial (a quarter or more of the entries matched nothing) or zero-overlap (no entry matched).
gate_tripstrue when --fail-on-stale-baseline fails on this file: one entry matched nothing, or the file is of another kind.
moved_entriesHealth only, in identity mode: entries that matched by following a moved file.
unrecognised_format, saved_byPresent only for a file of another command. saved_by names that command: dead-code, dupes or health.
formatlegacy for a file with an older key form.

The staleness warning on stderr, and the message of --fail-on-stale-baseline, give the fallow baselines prune command for the file, with an absolute path.

Read change_scoped before you divide the counts: a narrowed run can match few entries of a correct baseline. production, include-entry-exports, workspace and changed-workspaces are your choice of the project, so a repeat run keeps them. A run that is narrowed only by diff, changed-since, scope, file or issue-type-filter adds a recheck-baseline entry to next_steps. Its command reads the baseline again over the whole project, and never saves it:

{
  "id": "recheck-baseline",
  "command": "fallow dead-code --baseline fallow-baselines/dead-code.json",
  "reason": "this run was narrowed to part of the project (changed-since), which cannot judge this baseline"
}

fallow audit loads baselines, but never judges them.

Baseline files

Each file that --save-baseline writes has a top-level kind: dead-code, dupes or health. A file without kind still loads, and its keys decide the format. A command that loads a file of another kind suppresses nothing. It prints a warning on stderr, also with --quiet, and sets unrecognised_format and saved_by. --fail-on-stale-baseline then exits with code 1. Do not read baseline_entries: 0 as a wrong file: a project with nothing to record has an empty baseline.

A dead-code baseline has "identity": "dc1" and keys without lines (Baseline file). A dead-code baseline without identity still loads, and each old entry matches only its exact old form. Some old keys hold a line, so they can go stale after a line shift. The run prints a note on stderr and sets format: "legacy":

Note: fallow-baselines/legacy.json uses the old baseline key format. Run --save-baseline to rewrite it without line numbers.

Run --save-baseline once to write the file again. An unknown identity value exits with code 2.

Install state

A dead-code baseline records if node_modules existed at the save. Dependency, unlisted, unresolved-import and script-binary findings need installed packages. So a run in the other install state can report baseline findings as new. Such a run prints a warning, also with --quiet, and adds this entry to workspace_diagnostics:

{
  "path": "fallow-baselines/dead-code.json",
  "kind": "baseline-install-state-mismatch",
  "baseline_node_modules": "present",
  "run_node_modules": "missing",
  "degrades_analysis": true
}

The entry also has a message. The warning does not change the comparison or the exit code. Save and compare the baseline in the same install state. A file without this record gives no warning. Health and duplication baselines do not record the install state.

Regression baseline

A regression baseline holds the issue counts, not the findings. --save-regression-baseline <PATH> writes the counts of each issue type and total_issues, with fallow_version, timestamp and git_sha. --fail-on-regression exits with code 1 when the total grows by more than --tolerance (for example 5 or 2%, default 0). The check works with fallow dead-code, fallow architecture and the bare fallow run. With --format json, the output has a regression object (check.regression on the bare run):

{
  "status": "exceeded",
  "baseline_total": 6,
  "current_total": 7,
  "delta": 1,
  "tolerance": 0.0,
  "tolerance_kind": "absolute",
  "exceeded": true
}

status is pass, exceeded or skipped. tolerance and tolerance_kind (percentage or absolute) are present only on exceeded. A run with --changed-since or --workspace skips the check, because its counts do not compare with the whole project: skipped has a reason. A regression baseline file that does not exist exits with code 2.

Exit codes

CodeMeaning
0The files are pruned, or have nothing to prune.
1With --check: at least one entry can be pruned.
2No baseline in the config, an option that narrows the run, a file that fallow cannot read or write, or a skipped file. Code 2 wins over code 1.

See Exit codes.

Examples

# Remove the entries of fixed findings
fallow baselines prune

# Show the entries that a prune removes, and write nothing
fallow baselines prune --check

# Prune a baseline that you saved in production mode
fallow baselines prune --production

# Prune one file that the config does not name
fallow baselines prune --dead-code-baseline fallow-baselines/dead-code.json
  • Baselines: save a baseline, and gate only new findings.
  • fallow hooks: --prune-baselines runs a prune in the Git hook.
  • fallow audit: the changed-code check that reads the same files.