Skip to content
Fallow home
All docs pages

Docs home

Rules and severities

Set the severity of each issue type in the rules config, change it for some files with overrides, and see the defaults.

In the demo project, fallow dead-code finds an unused file, three unused exports and two dependency problems, and it exits with code 1. Your team can agree with each finding and still want to remove the exports next month, without a red CI job until then. The rules object of the config file sets the severity of each issue type, so you decide which findings fail a run. Findings defines rules, severities and gates.

The rules object

Each key is a rule name, and each value is a severity:

SeverityEffect
errorFallow reports the finding, and the run exits with code 1.
warnFallow reports the finding, and the run exits with code 0.
offFallow does not look for the issue type.
// .fallowrc.json
{
  "rules": {
    "unused-files": "error",
    "unused-exports": "warn",
    "unused-types": "off",
    "private-type-leaks": "warn"
  }
}
# fallow.toml
[rules]
unused-files = "error"
unused-exports = "warn"
unused-types = "off"
private-type-leaks = "warn"

A rule that you do not set keeps its default. An unknown rule name gives a warning on stderr, and fallow ignores the entry.

Set each of the four rules of the demo findings to warn, and fallow dead-code still lists each finding. The summary line starts with ⚠ instead of ✗, and the command exits with code 0:

⚠ 1 file · 3 exports · 1 unused dependency · 1 unlisted dependency (0.02s)

Rule names

To set a rule, you need its name. The rule name is the plural form of the issue type in most cases, for example unused-exports for the issue type unused-export. Most rules also accept the other form as an alias, for example circular-dependency for circular-dependencies. The page of each issue type gives its key in the row "Config key in rules". Issue types lists each issue type with its default severity. The rules reference lists each key.

Defaults

Before you change a rule, know where it starts. A rule defaults to error unless it is in one of these groups:

  • off: the checks that you turn on yourself. Examples are private-type-leaks, deprecated-exports-in-use, unused-protected-class-members, absent-component-props, constant-parameters, prop-drilling, thin-wrapper, duplicate-prop-shape, coverage-gaps, feature-flags, require-suppression-reason, security-sink, security-client-server-leak, diverged-clone-sibling and added-dependency.
  • warn: these groups of rules.
    • unused-dev-dependencies, unused-optional-dependencies, type-only-dependencies, test-only-dependencies and dev-dependencies-in-production.
    • The framework rules, for example unused-component-props and unused-store-members, and the Effect rules.
    • The client and server directive rules, and the styling rules (css-*).
    • unused-catalog-entries, empty-catalog-groups and unused-dependency-overrides.
    • The change checks of fallow audit that are not off: weakened-tests, added-suppression, test-only-branch and introduced-clone-group.
    • unlisted-binaries, unused-namespace-members, duplicate-export-aliases, re-export-cycle, package-cycle, stale-suppressions and policy-violation.

To see the severity of each rule for your project, run fallow config. The rules object of its output holds the result after extends and the defaults.

Overrides

A severity in rules applies to the whole project, but one part of the code can need another one. overrides sets other severities for the files that its globs match. The globs follow the glob rules.

files takes globs of project files, not package names or binary names. The glob must match the file that has the finding. For unresolved-import, that is the file with the import, not the import target. To hide one import, add its specifier to ignoreUnresolvedImports.

These rules read only the top-level severity, so an override does not change them:

  • unused-dependencies, unused-dev-dependencies and unused-optional-dependencies: a package in package.json that no file uses.
  • unlisted-dependencies: a package that a file imports, but that package.json does not list.
  • unlisted-binaries: a binary that a package.json script or a process call runs, but that no installed package provides.
  • type-only-dependencies: a production dependency that the code uses only for types.
  • test-only-dependencies: a production dependency that only test files use.
  • dev-dependencies-in-production: a development dependency that production code imports.
  • duplicate-exports: an export name that more than one file exports.
  • re-export-cycle: files that re-export each other in a loop.
  • unused-catalog-entries: a catalog entry that no workspace package uses.

To hide one package, add it to ignoreDependencies. To hide one binary, add it to ignoreBinaries.

In this config for the demo project, unused exports only warn. The rule is off in src/lib, but src/lib/format.ts must stay clean:

// .fallowrc.json
{
  "rules": { "unused-exports": "warn" },
  "overrides": [
    { "files": ["src/lib/**"], "rules": { "unused-exports": "off" } },
    { "files": ["src/lib/format.ts"], "rules": { "unused-exports": "error" } }
  ]
}
npx fallow dead-code --unused-exports
● Unused exports (2)
  src/lib/format.ts
    :3 formatPercent
  src/services/orders.ts
    :18 cancelOrder
  Exported symbols with no known consumers
  https://fallow.tools/docs/explanations/dead-code/#unused-exports

✗ 2 exports (0.03s)

The re-export in src/lib/index.ts is gone, because the first entry turns the rule off in src/lib. formatPercent stays, at error, so the run fails. cancelOrder keeps the top-level warn.

  • Fallow applies the entries in list order. When two entries match a file and set the same rule, the later entry wins.
  • An override cannot start a check that the top-level rules turns off. Set the rule on at the top level, then set it to off for the other files.

Fallow reports an override entry that has no effect as an override rule with no effect. The overrides reference has the details.

Production mode

The same config can give other results in production mode, because a development dependency does not ship. Production mode changes some dependency rules:

  • unused-dev-dependencies and unused-optional-dependencies are off.
  • Fallow reports type-only-dependencies (default warn) only in production mode.
  • Fallow reports test-only-dependencies only outside production mode.

Complexity rules

Complexity findings use two settings with different jobs. The health limits, for example health.maxCyclomatic, decide if a function has a complexity finding. The rules complexity-cyclomatic, complexity-cognitive, complexity-crap and complexity-file-lines decide if that finding fails the run.

  • A rule at warn keeps the finding in the report. fallow health then exits with code 0, and the verdict of fallow audit is warn.

  • A rule at off removes the finding from the report.

  • A function above more than one limit takes the most severe rule of those limits.

  • In JSON output, effective_severity holds the rule severity. severity holds the band: moderate, high or critical.

  • The rule applies before fallow health --min-severity. So a finding at warn does not fail the run, also when its band is at or above the --min-severity level.

  • --fail-on-issues, and --ci, make a warn complexity finding fail fallow health and the bare fallow run.

  • complexity-crap: "off" removes only the CRAP findings. health.maxCrap: 0 also removes the CRAP signals from the file scores.

After you set a complexity rule to off, save the health baseline again. Its entries for the removed findings no longer match.

Change the result for one run

A CI job or a local check can need a stricter or a narrower run than the config file sets. The config file stays the same for these options:

  • --fail-on-issues makes a warn finding fail the run too. --ci includes it. fallow audit ignores it and keeps its own verdict.
  • An issue type filter, such as --unused-deps, does not turn on a rule that is off. Fallow then adds a requested rule that is off warning.
  • When the config sets their rule to off, these filters of fallow dead-code turn it on at warn: --private-type-leaks, --deprecated-exports-in-use, --unused-protected-class-members, --absent-component-props and --constant-parameters.

Exit codes lists each code.

Levels in CI formats

A severity also decides how a finding looks in a pull request. The CI formats take the level of a finding from its rule severity, also from an overrides entry. A complexity finding takes its level from its complexity-* rule, not from its band.

Rule severitygithub-annotationsSARIFCodeClimate
error::errorerrormajor
warn::warningwarningminor

With the default rules, a moderate complexity finding is an ::error annotation and a SARIF error, because the finding fails the run. Each finding in the JSON output has the effective_severity field, and fallow report --from reads it. So a saved report gives the same levels as the run that made it.