Skip to content
Fallow home
All docs pages

Docs home

Migrate from jscpd

Convert a jscpd config to the duplicates settings of fallow with fallow migrate, check the result, and run both tools for a while.

Your project has a jscpd config with a threshold, a minimum size for a copy, and a list of ignored files. Your CI fails when the share of duplicated code goes above the threshold. fallow migrate reads that config and writes the same limits into the duplicates section of a fallow config file. Then fallow dupes fails at the same threshold. Duplication explains how fallow compares code.

Before you start

  • A jscpd config: .jscpd.json, or the jscpd field of package.json.
  • No fallow config file in the project. fallow migrate does not overwrite one.

What maps to what

Most jscpd options have a fallow key with the same name. The options that change how code is compared go to duplicates.normalization:

jscpdfallow
thresholdduplicates.threshold
minTokensduplicates.minTokens
minLinesduplicates.minLines
modeduplicates.mode
skipLocalduplicates.skipLocal
ignoreduplicates.ignore
ignoreIdentifiers: true or "consistent"duplicates.normalization.ignoreIdentifiers and consistentIdentifiers, both true
ignoreIdentifiers: "blind"duplicates.normalization.ignoreIdentifiers: true
ignoreLiterals: trueduplicates.normalization.ignoreStringValues and ignoreNumericValues, both true
formatNothing. Fallow finds the JavaScript and TypeScript files itself.
maxLines, maxSize, ignorePattern, reporters, output, gitignore and the other optionsNothing. The migration prints a warning for each one. For ignorePattern, it proposes a range suppression.

Steps

The steps use the demo project of these docs, with this .jscpd.json in the project root:

{ "threshold": 5, "minTokens": 60, "minLines": 6, "mode": "weak", "ignore": ["**/*.generated.ts"], "ignoreIdentifiers": true, "format": ["typescript"] }
  1. 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 .jscpd.json
      "duplicates": {
        "minTokens": 60,
        "minLines": 6,
        "threshold": 5.0,
        "mode": "weak",
        "ignore": [
          "**/*.generated.ts"
        ],
        "normalization": {
          "ignoreIdentifiers": true,
          "consistentIdentifiers": true,
          "ignoreStringValues": false
        }
      }
    }
    
    Migrated from: .jscpd.json
    
    Warnings (2):
      [jscpd] `mode`: jscpd's "weak" mode may differ semantically from fallow's "weak" mode. jscpd uses lexer-based tokens while fallow uses AST-based tokens. (suggestion: test with both "weak" and "mild" to find the best match)
      [jscpd] `format`: fallow auto-detects JS/TS files

    The config has mode: "weak" and no ignoreLiterals, so the migration adds ignoreStringValues: false. What differs gives the reason.

  2. Write the config file:

    npx fallow migrate

    Add --toml to write fallow.toml.

  3. Run the analysis:

    npx fallow dupes
    ● Duplicates (2 clone groups)
    
         17 lines  2 instances  spread 2  dup:ca69f412
        src/reports/export.ts:3-19
        src/utils/summary.ts:7-23
    
         17 lines  2 instances  dup:06de2df9
        src/reports/invoice.ts:4-20
        src/reports/receipt.ts:4-20
    
    ✗ 68 lines (40.7%) duplicated across 4 files (0.02s)
    Duplication (40.7%) exceeds threshold (5.0%)

    The migrated threshold of 5 percent makes the run fail. invoice.ts and receipt.ts use other names for the same code, and the migrated ignoreIdentifiers lets fallow match them. With these settings, the group of export.ts and summary.ts gets another handle than in a run with the default settings.

Check the result

Compare the clone groups of fallow with the result of jscpd on the same commit. The warning about mode tells you to try a second mode. The fallow modes strict and mild (the default) give the same result, because fallow compares parsed code. To also match copies with other names, try the semantic mode:

npx fallow dupes --mode semantic

What differs

  • The fallow weak mode ignores the text of strings. When the jscpd config has mode: "weak" without ignoreLiterals: true, the migration adds ignoreStringValues: false, so that strings stay compared.
  • Fallow compares parsed code, so comments and formatting never hide a copy.
  • An ignoreIdentifiers value other than true, false, "consistent" or "blind" gets a warning, and the migration skips it.

Run both tools for a while

fallow migrate does not change or delete the jscpd config, so you can run both tools in CI. When the results agree, remove jscpd and its config.