Skip to content
Fallow home
All docs pages

Docs home

Fix your first findings

Check one finding of each kind, remove the code with fallow fix and by hand, and run fallow again.

The first run of the demo project reported an unused file, three unused exports, two dependency problems, a clone group and a complex function. You do not want to delete code on trust, so each step here first asks fallow why it reports a finding, and then acts on it. You remove the dead code with fallow fix and by hand, and you see the report get smaller.

Before you start

  • Do the first run. This page uses the findings of the same demo project.
  • Commit your work, or use a copy of the project. fallow fix changes your files.

Delete the unused file

Start with the files. When you delete a file, an export that only this file imported becomes unused, and the fix in the next steps then removes it too. fallow fix does not delete files, so check the file first:

npx fallow dead-code --trace-file src/utils/legacy-currency.ts
  UNREACHABLE src/utils/legacy-currency.ts

  Exports (2):
    export toGuilders [unused]
    export fromGuilders [unused]

No entry point reaches the file, and no file uses its exports. Delete the file.

Check an unused export

The exports come next. Before you remove one, ask fallow why it reports it. Give the file and the name:

npx fallow dead-code --trace src/services/orders.ts:cancelOrder
  UNUSED cancelOrder in src/services/orders.ts

  File: reachable
  Namespace: value
  Reason: No references found, export is unused

The file is reachable, but no file imports cancelOrder. Namespace: value means that cancelOrder exists when the code runs. A type shows Namespace: type. If a file used the name, the trace would name that file. Trace a finding shows the other trace commands.

Fix the exports and the dependencies

fallow fix removes unused exports, unused dependencies and unused enum members. Run it with --dry-run first, which changes no files:

npx fallow fix --dry-run
Would remove export from src/services/orders.ts:18 `cancelOrder`
Would remove export from src/lib/index.ts:1 `formatPercent`
Would remove export from src/lib/format.ts:3 `formatPercent`
Would remove `left-pad` from dependencies in package.json
Dry run complete. No files were modified.

Then apply the fix. --yes skips the confirmation prompt, and fallow prints Fixed 4 issue(s).:

npx fallow fix --yes

The change in your files:

--- a/package.json
+++ b/package.json
   "dependencies": {
-    "zod": "^3.23.8",
-    "left-pad": "^1.3.0"
+    "zod": "^3.23.8"
   },
--- a/src/lib/index.ts
+++ b/src/lib/index.ts
-export { formatPrice, formatPercent } from "./format";
+export { formatPrice } from "./format";
 export { parseAmount } from "./parse";
--- a/src/services/orders.ts
+++ b/src/services/orders.ts
-export const cancelOrder = (order: Order): Order => ({ ...order, quantity: 0 });
+const cancelOrder = (order: Order): Order => ({ ...order, quantity: 0 });

The fix removes the export keyword and keeps the function. The change in src/lib/format.ts is the same. If you do not need the function, delete it yourself. To check a dependency before the fix removes it, run npx fallow dead-code --trace-dependency left-pad.

uuid is the opposite case: src/services/orders.ts imports it, but package.json does not list it. fallow fix does not add packages, so run npm install uuid. Your package manager then also updates the lock file.

Look at the clone group

The dead code is gone. The two parts that remain need a decision from you, because fallow cannot know which copy is right. Give the handle of the clone group to npx fallow dupes --trace dup:f42424e8:

  Clone group 1  dup:f42424e8 (17 lines, 210 tokens, 2 instances, spread 2)
    >> src/reports/export.ts:3-19
    -> src/utils/summary.ts:7-23
    Suggested refactor
      Extract function, saves ~17 lines

The trace also prints the 17 lines. If both files must change together, move the code into one shared function. If they only look the same today, keep both. Duplication helps you decide.

Look at the complex function

The header of the first run named one refactoring target. Run npx fallow health --targets to see what to do with it:

   17.4  pri:17.4    src/services/customers.ts
         complexity · effort:low · confidence:high  Extract classifyCustomer (cognitive: 32) in 48-LOC file into smaller functions

Split classifyCustomer into smaller functions when you next change it, and add a test first. Health and complexity explains the scores.

When a finding is wrong

Fallow can report code as unused when it cannot see how the code is loaded, for example by a framework or a config file. Do not delete that code: tell fallow about it, as Handle false positives shows. When your project has hundreds of findings, do not fix them in one pass: Adopt fallow in an existing project shows how to start with new code only.

Run fallow again

npx fallow
■ Metrics: dead files 0.0% (0 of 15) · dead exports 0.0% (0 of 16) · MI 95.6 (good)
── Dead Code ──────────────────────────────────────
✓ No issues found (0.04s)
Failed: dupes (1 clone group), health (1 above threshold): start with src/services/customers.ts

The dead code part is clean. The Failed: line names the two parts that you looked at and did not change.

What you learned

  • Delete unused files first, then let fallow fix remove the exports and dependencies.
  • A trace tells you why fallow reports a name, a file or a package.
  • A clone group and a complex function need your decision. Fallow gives the facts and a suggestion.

Next

You removed the old dead code. To stop new dead code, check each change: Check each pull request.