Skip to content
Fallow home
All docs pages

Docs home

Fallow and linters

A linter checks one file at a time and fallow checks the whole project, so see which problem needs which tool and run both in CI.

You run a linter already, and you want to know what fallow adds. A linter reads one file and checks it against rules. Fallow reads the whole project: it starts at the entry points and follows each import. Some problems exist only between files, so a check of one file at a time cannot find them. That is why you use a linter and fallow together.

The problem

In the demo project, src/services/orders.ts exports cancelOrder, and no file imports it. The export looks correct in its own file, so a linter that reads only that file sees nothing wrong. To know that nothing imports cancelOrder, a tool must read each file that could import it. The same is true for src/utils/legacy-currency.ts, which no code reaches, and for left-pad, a package in package.json that no file imports.

Which tool finds which problem

The "Needs" column gives the reason for each row. A tool that reads one file at a time finds only the problems that need one file.

ProblemNeedsTool
A variable that the file never usesOne fileLinter
A missing dependency of a React hookOne fileLinter
== where === is meantOne fileLinter
Inconsistent code styleOne fileFormatter
An export that no file importsThe whole projectFallow
A file that no entry point reachesThe whole projectFallow
A package in package.json that no file importsThe whole projectFallow
An import of a package that package.json does not declareThe whole projectFallow, or a linter with a plugin
A circular import chain through many filesThe whole projectFallow, or a linter with a plugin
An import across an architecture boundaryThe whole projectFallow, or a linter with a plugin
A block of code that is copied in several filesThe whole projectFallow
A complex functionOne functionFallow, or a linter
A complex file that changes oftenThe project and its git historyFallow
New unused code in a pull requestThe project and the changeFallow, with a changed-code check

Some linter plugins also build the import graph, for example to find cycles. Fallow builds the graph once for each run and uses it for all of its checks.

How fallow checks the project

Each row with "The whole project" needs one view of all files and their imports. Fallow parses each file once and builds a graph of the imports of the project. It follows re-export chains through barrel files, and it resolves the path aliases of tsconfig.json. Its plugins find the entry points of frameworks, such as the pages of Next.js. Then it reads the graph:

  • An export that no reachable file imports is an unused export, such as cancelOrder.
  • A file that no entry point reaches is an unused file, such as src/utils/legacy-currency.ts.
  • A loop in the graph is a circular dependency. Fallow finds loops of each length, through import and require().
  • An import between two zones of your boundaries config, that the rules do not allow, is a boundary violation. For an import through a barrel file, fallow checks the zone of the file that declares the name.

What fallow cannot do

The graph shows how the files use each other. It does not show what happens inside one file, and it does not know the code outside the project:

  • Fallow does not check style, scope or the logic inside one file. Keep your linter for that.
  • An export that code outside the project imports, such as the public API of a library, looks unused. Mark it with /** @public */, or make its file an entry point.
  • Some cycles are intentional, for example in a framework with dependency injection. Fallow cannot tell an intentional cycle from a mistake. Accept a known cycle in circularDependencies.allow.

Run both in CI

Each tool finds problems that the other does not, so CI needs both. Run the formatter, the linter and fallow as separate jobs. They do not depend on each other, so they can run in parallel. Run fallow in CI shows how to add fallow to a pipeline. To start on a project with many findings, save a baseline, so that CI fails only on new findings.

Next

  • Next: First run. Run fallow on your own project and see which of these problems it has.
  • Run fallow in CI: add fallow to your pipeline.
  • Dead code: how fallow finds unused code.