Constant parameters
What a constant-parameter finding of fallow dead-code means, why it matters and how to fix it.
What it reports
Each visible call passes this parameter in one way; review the parameter and its callers manually.
Dead code explains how fallow finds it.
Why it matters
A parameter of a module-scope function gets the same literal at each visible call (reason identical-argument), or an optional parameter is passed by no call (reason never-passed). The finding lists the value, the call count, the calls, and the count of conditions that test the parameter; a condition that tests a constant points at a branch that cannot run. Enable constant-parameters explicitly; it defaults to off. The rule fires only when each caller is visible. It abstains for public API and entry-point exports, exports that a plugin marks as used, dynamic imports, CommonJS, escaped namespaces, a function used as a value or through call/apply/bind, template hosts that can import the function, direct eval, classic scripts, framework auto-imports, open contracts (arguments, overloads, a reassigned binding, decorators, generators), a module with a parse error that can import the function, and fewer than 2 calls. A self-call that passes an optional parameter on blocks never-passed. A written, rest or destructured parameter gives no finding. In the default mode a test file is a caller; with --production only production callers count. Review the parameter manually; static analysis does not prove that no caller outside the project exists.
Example
format(value, compact, locale?) is called 14 times in the project, each time as format(n, true). compact is always true, so the branch for false cannot run, and no call passes locale.
Fix
Review the calls and the intent of the parameter. Remove the parameter and move the value into the function, or keep it when the flexibility is deliberate. Add a fallow-ignore-next-line constant-parameter comment above the parameter or the function to keep it. This candidate has no automatic fix.
Facts
| Fact | Value |
|---|---|
| Issue type | constant-parameter |
| Rule id in SARIF output | fallow/constant-parameter |
| Command | fallow dead-code |
| Default severity | off |
Config key in rules | constant-parameters |
| Filter option | --constant-parameters |
| Suppression comment | // fallow-ignore-next-line constant-parameter |
Fixable with fallow fix | No |
| Opt-in | Yes |
Note. Opt-in manual review candidate; defaults to off. Inspect the calls and the intent of the parameter before changing the function. No automatic fix.
When to keep the code
- The parameter is a deliberate option, a seam for tests, or it matches the signature of a similar function.
- A file that fallow does not analyze calls the function with another value: a file in
ignorePatterns, a gitignored file, or a file that a build step generates. Suppress the finding, or add the file to the analysis.
Notes
In the default mode a test file is a caller, so a test that passes another value prevents the finding. With --production, fallow ignores test files, and a finding means that the parameter is constant in production code.