fix(dupes): honor scalar config fields when CLI flags are omitted#290
Merged
BartWaardenburg merged 1 commit intofallow-rs:mainfrom May 6, 2026
Merged
Conversation
`fallow dupes` ignored `duplicates.minLines`, `duplicates.minTokens`, `duplicates.threshold`, `duplicates.mode`, and `duplicates.skipLocal` in `.fallowrc.jsonc` when the matching CLI flag was not passed. The `Command::Dupes` clap definitions used `default_value = "5"` (etc.), so `min_lines: usize` was always populated with the clap default and `build_dupes_config` overwrote the toml value unconditionally. Switch the four scalar fields (`mode`, `min_tokens`, `min_lines`, `threshold`) on `DupesOptions` and the `Command::Dupes` clap args to `Option<T>` and drop their `default_value`s. `build_dupes_config` now falls back to `toml_dupes.x` when the CLI value is `None`. The `skip_local` boolean adopts the same OR-merge already used for `cross_language` / `ignore_imports` so config-driven `skipLocal: true` is honored too. Audit, combined, and programmatic call sites already merge config into their own structs before constructing `DupesOptions`, so they forward each value as an explicit `Some(...)` (no behavior change at those entry points). The standalone `DupesResult.threshold` is now sourced from the merged `dupes_config.threshold` rather than the unmerged `opts.threshold`, so `.fallowrc.jsonc`'s `threshold` actually drives the failure gate. Tests: - existing `build_config_uses_cli_*` tests updated to wrap CLI values in `Some(...)` - new regression tests for each fallback path: `falls_back_to_toml_min_lines_when_cli_unset`, `falls_back_to_toml_min_tokens_when_cli_unset`, `falls_back_to_toml_threshold_when_cli_unset`, `falls_back_to_toml_mode_when_cli_unset`, `cli_min_lines_overrides_toml`, `skip_local_or_merges_with_toml`
Collaborator
|
Released in v2.66.0. Thanks @ryota-murakami. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Standalone
fallow dupesignoresduplicates.minLines,duplicates.minTokens,duplicates.threshold,duplicates.mode, andduplicates.skipLocaldeclared in.fallowrc.jsoncwhenever the matching CLI flag is omitted. TheCommand::Dupesclap definitions usedefault_value = "5"(etc.), somin_lines: usizeis always populated with the clap default —build_dupes_configthen overwrites the toml value unconditionally.Reproduction
The same problem affects
mode,threshold, andskipLocal.audit/combined/programmaticpaths are not affected because they merge config into their own structs before constructingDupesOptions.Root cause
crates/cli/src/dupes.rs::build_dupes_configoverwrote each toml scalar with the correspondingopts.*value:Option<T>withdefault_valueis the only way to distinguish user-passed from clap-supplied default with non-Optional types — so we can't fix this without touching the CLI signature.Fix
mode,min_tokens,min_lines,thresholdonDupesOptionsand theCommand::Dupesclap args toOption<T>and drop theirdefault_values.build_dupes_confignow usesopts.x.unwrap_or(toml_dupes.x)for those four fields.skip_localadopts the OR-merge already used forcross_language/ignore_imports, so config-drivenskipLocal: trueis honored.DupesResult.thresholdis now sourced from the mergeddupes_config.threshold(wasopts.threshold), so the failure gate honors.fallowrc.jsonctoo.audit.rs,combined.rs, andprogrammatic.rsalready have explicit values from their own merges; they forward each asSome(...)(no behavior change at those entry points).Help text now reads:
Test plan
build_config_uses_cli_*tests to wrap CLI values inSome(...)falls_back_to_toml_min_lines_when_cli_unsetfalls_back_to_toml_min_tokens_when_cli_unsetfalls_back_to_toml_threshold_when_cli_unsetfalls_back_to_toml_mode_when_cli_unsetcli_min_lines_overrides_tomlskip_local_or_merges_with_tomlcargo fmt --allcargo clippy --workspace --all-targets -- -D warnings(clean)cargo test --workspace(all suites green)minLines: 100now suppresses the toy clone, and--min-lines 100still overrides configCompatibility
--mode,--min-tokens,--min-lines,--thresholdstill accept the same values; the only observable difference is "flag omitted" no longer wins over config. Users who relied on the old behavior can migrate by either settingduplicates.* = <prior_default>in their config or by passing the flag explicitly.DuplicationOptions): unchanged. Callers still pass concrete values; we forward each asSome(...)internally.