Migrate from knip
Convert a knip config to a fallow config with fallow migrate, check the result, and run both tools for a while.
Your project has a knip config with entry patterns, ignore lists and rules that your team tuned over time. You do not want to write those settings again by hand, and you want to know which of them fallow cannot use. fallow migrate reads your knip config and writes a fallow config file with the same settings. It prints a warning for each setting that it cannot convert, so you know what to check by hand.
Before you start
- A knip config in one of these places:
knip.json,knip.jsonc,.knip.json,.knip.jsonc, or theknipfield ofpackage.json. - No fallow config file in the project.
fallow migratedoes not overwrite one.
Fallow finds knip.ts and knip.config.ts, but it cannot read them. Convert such a file to knip.json first.
What maps to what
Most knip keys have a fallow key with the same name or the same purpose. The table shows where each key goes. Read it now, or come back to it when the migration prints a warning.
| knip | fallow |
|---|---|
entry | entry. When some patterns have the production marker !, the marked patterns go to entry and the other patterns go to supportEntry. |
project | Fallow finds the project files itself. An exclusion with the production marker, such as !scripts/**!, becomes a production.ignore pattern. |
ignore | ignoreFindings. The files stay in the analysis. |
ignoreDependencies, ignoreBinaries | The same keys. A regular expression becomes a glob when a glob matches the same names. |
ignoreExportsUsedInFile, includeEntryExports | The same keys. |
rules, include, exclude | rules, with the fallow name of each issue type. nsExports and nsTypes follow exports and types. dependencies in include or exclude also covers devDependencies, as in knip. The migration keeps the knip severity: see Severity. |
ignoreIssues | An overrides entry that turns the issue types off for the file glob. |
cycles.allow | circularDependencies.allow. |
A workspaces.<path> section | The same fallow keys, with the workspace path in front of each pattern. ignoreDependencies and includeEntryExports go to workspaces.settings for the same path. |
A plugin section, such as vitest | Nothing. The built-in plugins find the config of the tool. |
paths, ignoreFiles, ignoreMembers, ignoreUnresolved, ignoreWorkspaces, ignoreGlobalBinaries, tags, compilers, preprocessor | Nothing. The migration prints a warning, and for most keys it names the fallow alternative. |
Steps
The steps use the demo project of these docs, with this knip.json in the project root:
{
"entry": ["src/index.ts!", "scripts/seed.js"],
"project": ["src/**/*.ts"],
"ignore": ["src/**/*.generated.ts"],
"ignoreDependencies": ["^@types/", "^(react|vue)$"],
"rules": { "types": "warn", "binaries": "off" },
"vitest": { "config": ["vitest.config.ts"] }
}
-
Preview the config. The command writes no file:
npx fallow migrate --dry-run{ "$schema": "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json", // Migrated from knip.json "entry": [ "src/index.ts" ], "ignoreFindings": [ "src/**/*.generated.ts" ], "ignoreDependencies": [ "@types/*" ], "rules": { "unused-types": "warn", "unlisted-binaries": "off", "unused-dev-dependencies": "error", "unused-namespace-members": "error", "duplicate-export-aliases": "error" }, "supportEntry": [ "scripts/seed.js" ] } Migrated from: knip.json Warnings (3): [knip] `project`: Fallow auto-discovers project files [knip] `ignoreDependencies`: regex pattern `^(react|vue)$` skipped (no glob matches the same names) (suggestion: rewrite it as a glob such as `@scope/*`, or add each name) [knip] `vitest`: plugin config `vitest` is auto-detected by fallow's built-in plugins (suggestion: remove this section; fallow detects framework config automatically)src/index.ts!has the production marker andscripts/seed.jshas none, so the seed script goes tosupportEntry. The regular expression^@types/becomes the glob@types/*, but no glob matches^(react|vue)$, so the migration skips it. The threeerrorrules keep the knip severity: see Severity. -
Write the config file:
npx fallow migrateFallow writes
.fallowrc.json, or.fallowrc.jsoncfor aknip.jsonc. Add--tomlto writefallow.toml. -
Read each warning. Add a skipped setting by hand, for example each package name of a skipped regular expression.
-
Run the analysis:
npx fallow dead-code
Check the result
The new config can be valid and still match other files than before, because the two tools use different glob engines. So fallow helps you check it: after the report, it prints a note for each migrated pattern that had no effect. The demo run ends with these lines:
3 entry points detected (2 manual entry, 1 plugin)
✗ 1 file · 3 exports · 1 unused dependency · 1 unlisted dependency (0.02s)
Note: ignoreFindings pattern matched no finding this run: src/**/*.generated.ts (patterns are project-root-relative globs; check for typos).
Note: ignoreDependencies glob matched no declared dependency this run: @types/* (globs match package names such as @scope/*; check for typos).
Note: entry pattern matched only files that are entry points anyway: src/index.ts (remove from the config).
The demo has no generated files and no @types packages, so the first two notes are correct, and a typo shows in the same way. Then compare the findings of fallow with the findings of knip on the same commit.
Severity
knip reports each issue type as an error, unless rules sets another severity. In fallow, these rules have the default severity warn, and a warning does not fail a run:
unused-dev-dependenciesunused-optional-dependenciesunused-namespace-membersduplicate-export-aliasesunlisted-binaries
So fallow migrate writes "error" for each of these rules that has a knip issue type, unless the knip config sets a severity for that issue type or turns it off. The run that failed in knip, for example on an unused devDependencies entry, then also fails in fallow. After the warnings, the migration prints a note that names the rules:
Note: the migrated config sets these rules to `error`, because knip reports
their issue types as errors. The fallow default for them is `warn`, and a
warning does not fail a run.
unused-dev-dependencies, unused-namespace-members, duplicate-export-aliases
https://fallow.tools/docs/migration/from-knip/
knip has no issue type for unused optionalDependencies, so unused-optional-dependencies keeps the default warn.
A fallow version before this change wrote none of these rules. If you migrated with such a version, add the rules to the rules of your config by hand:
{
"rules": {
"unused-dev-dependencies": "error",
"unused-namespace-members": "error",
"unlisted-binaries": "error",
"duplicate-export-aliases": "error"
}
}
When each dead-code finding of a run is a warning, the human report says so under the status line:
⚠ 1 dev/optional dependency (0.03s)
Warnings do not change the exit code. Set a rule to `error` to fail on it.
What differs
A difference in the findings has one of these causes:
- knip
ignorealso hides dependency findings by file path. FallowignoreFindingsnever hides findings that belong topackage.json, such as unused dependencies. - Fallow has more issue types, such as duplicate exports and stale suppressions. A finding that knip did not report can be correct.
- A name with the production marker in
ignoreDependencies, such asleft-pad!, loses the marker. Fallow ignores the name in each mode.
Run both tools for a while
fallow migrate does not change or delete the knip config. Each tool reads its own config, so you can run both in CI. Fallow does not report knip as an unused dev dependency. When the results agree, remove knip and its config.
To start on a project with many findings, save a baseline, so that fallow fails only on new findings.
Related
- Adopt fallow: read it next to plan the first cleanup and the CI check.
fallow migrate: each option of the command.- Dead code: how fallow finds unused code.