Skip to content
Fallow home
All docs pages

Docs home

fallow migrate

fallow migrate converts a knip, jscpd or stylelint config into a fallow config file.

Convert the config of knip, jscpd or stylelint into a fallow config file.

For each source tool, read the migration page: knip, jscpd or stylelint.

Synopsis

fallow migrate [OPTIONS]

Options

OptionDescription
--tomlGenerate fallow.toml instead of JSONC
--jsoncWrite JSONC content to .fallowrc.jsonc instead of .fallowrc.json. The generated content is the same JSONC (with // comments) either way; the .jsonc extension lets editors auto-detect JSON-with-comments syntax highlighting and silences linters that flag comments in .json.
--dry-runOnly preview the generated config without writing
--from <PATH>Path to source config file (auto-detect if not specified)

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

--toml and --jsonc exclude each other. Without --from, fallow reads these sources and merges them into one config file:

ToolSources
knipknip.json, knip.jsonc, .knip.json, .knip.jsonc, the knip field of package.json
jscpd.jscpd.json, the jscpd field of package.json
stylelint.stylelintrc, .stylelintrc.json, .stylelintrc.jsonc, stylelint.config.js, stylelint.config.cjs, stylelint.config.mjs, the stylelint field of package.json

Fallow finds knip.ts and knip.config.ts, but cannot read them. Convert such a file to knip.json first. Fallow converts only the settings that have a fallow equivalent, and prints a note for each setting that it does not convert.

knip conversions

  • knip reads an ignoreDependencies entry as a regular expression when it is written as /.../ or holds one of * + \ ( | { ^ $. Fallow converts the entry to a glob only when a glob matches the same package names, for example ^@types/.*$ to @types/*. Fallow skips each other entry with a warning.
  • Fallow merges the settings of each knip workspaces entry into the top level, with the workspace path in front of each pattern. For example, src/x.ts of packages/* becomes packages/*/src/x.ts.
  • An unknown key in rules gives the warning unknown knip issue type `<name>`; not migrated.

The regular expressions that have an exact glob form:

knip entryGlob in fallow
@acme/.+, ^@acme/.+$ or ^@acme/.*@acme/*
/^@acme\//@acme/*
/^@acme/@acme*, because the regular expression also matches @acmecorp/lib
^@types/@types/*
^eslint-plugin-.*$eslint-plugin-*
-loader$*-loader
^react$react
^lodash\.get$lodash.get
^pkg-.$pkg-?

An alternation such as ^(react|vue)$, a character class such as ^@acme/[a-z]+$, or .+ in the middle of a name has no exact glob form. Add the names of such an entry by hand. After the migration, fallow dead-code names each ignoreDependencies glob that matches no dependency, so a glob with a typo shows.

ignoreBinaries gets the same conversion. A workspace list of ignoreBinaries merges into the top-level list. A name with the production marker, such as left-pad!, loses the marker: fallow ignores it in each mode, and prints a warning.

In rules, include and exclude, the knip issue type binaries becomes unlisted-binaries. optionalPeerDependencies, catalog and catalogReferences have no fallow issue type. They give the warning issue type `<name>` has no fallow equivalent, without a suggestion.

Workspace settings

ignoreDependencies and includeEntryExports of a workspace section go to workspaces.settings, with the workspace path as the key. The root workspace . uses the top-level keys. knip applies only the most specific workspace section, but fallow merges the ignoreDependencies lists of each key that matches. So when a glob section such as packages/* has a list and a more specific section also matches, fallow prints a warning: the more specific workspace now also ignores the entries of the glob. For includeEntryExports, fallow writes the root value into each more specific section that does not set it, so the result stays the same.

The ignore of knip also hides dependency findings by file path. ignoreFindings of fallow never hides a finding of package.json, such as an unused dependency. Each knip migration prints a note about this difference.

This sample comes from a knip.json with these three cases:

Warnings (3):
  [knip] `ignoreDependencies`: regex pattern `eslint-.+` skipped (no glob matches the same names) (suggestion: rewrite it as a glob such as `@scope/*`, or add each name)
  [knip] `ignoreDependencies`: regex pattern `/^(a|b)$/` skipped (no glob matches the same names) (suggestion: rewrite it as a glob such as `@scope/*`, or add each name)
  [knip] `rules.bogus`: unknown knip issue type `bogus`; not migrated (suggestion: check for a typo or report the missing mapping at https://fallow.tools/docs/migration/from-knip/)

Output

fallow migrate --dry-run
{
  "$schema": "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json",
  // Migrated from knip.json
  "entry": [
    "src/index.ts",
    "scripts/*.js"
  ],
  "ignoreFindings": [
    "src/utils/legacy-*.ts"
  ],
  "ignoreDependencies": [
    "left-pad"
  ],
  "ignoreExportsUsedInFile": true,
  "rules": {
    "unused-exports": "warn"
  }
}

Migrated from: knip.json

Note: knip and fallow use different glob engines; verify migrated entry /
ignoreFindings with `fallow dead-code` before relying on CI.
https://fallow.tools/docs/migration/from-knip/

With --dry-run, fallow prints the new config file. Without it, fallow writes the file and prints Created .fallowrc.json. The Migrated from: line names the sources, and each Note: explains a difference that needs a check.

Exit codes

CodeMeaning
0Fallow converted the config.
2No source config, a fallow config file that exists already, or a source that fallow cannot read.

See Exit codes.

Examples

# Show the converted config, and write nothing
fallow migrate --dry-run

# Convert each source that fallow finds
fallow migrate

# Convert one file into fallow.toml
fallow migrate --from config/knip.json --toml