Skip to content

feat(config): support .dupehound.yml config file with auto-discovery - #8

Merged
machado144 merged 2 commits into
mainfrom
feat/2-config-file
Apr 2, 2026
Merged

machado144 merged 2 commits into
mainfrom
feat/2-config-file

Conversation

@machado144

Copy link
Copy Markdown
Contributor

Summary

  • Adds .dupehound.yml config file support with automatic directory-tree discovery (FindConfig)
  • CLI flags always win over config values; zero-value fields fall back to config (ApplyConfigDefaults)
  • Supports path, min-tokens, exclude, language, format, output, exit-zero in config
  • New dupehound init subcommand writes a starter config with inline comments
  • Explicit --config flag to override auto-discovery path

Tests

  • 9 unit tests in services/config_test.go: parse all fields, empty path, missing file, invalid YAML, FindConfig current dir, FindConfig walks up, CLI wins, fills zero values
  • 6 integration tests in integration/cli_test.go: config settings respected, CLI flag overrides config, exclude from config, init creates file, init fails if exists, init --force overwrites

Checklist

  • All tests pass (go test ./... — 100 tests)
  • golangci-lint clean
  • gofumpt clean
  • structlint clean
  • dupehound init writes a starter .dupehound.yml
  • Config auto-discovered by walking up directory tree
  • CLI flags override config values

Closes #2

- Add FindConfig to walk up directories for .dupehound.yml
- Add LoadConfig (yaml.v3) and ApplyConfigDefaults (CLI wins over config)
- Add `dupehound init` subcommand to write a starter config file
- Support format, output, exit-zero from config file
- Use c.IsSet() throughout scan action to distinguish explicit CLI flags from defaults
- Add 9 unit tests for config and 6 integration tests for config+init

Closes #2
@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

StructLint — All checks passed

46 rules validated against .structlint.yaml. No violations found.

View full run · Powered by StructLint

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core Changes

This Pull Request introduces support for a .dupehound.yml configuration file, allowing users to define scan parameters outside of command-line flags. Key features include:

  • Config File (.dupehound.yml): A new dupehound init command creates a starter configuration file. This file can specify path, min-tokens, exclude, language, format, output, and exit-zero settings.
  • Auto-discovery: The tool automatically searches for .dupehound.yml by walking up the directory tree from the current working directory.
  • CLI Flag Precedence: Command-line flags always override values specified in the configuration file.
  • Explicit Config Path: A new --config flag allows users to specify a custom path to a configuration file, bypassing auto-discovery.
  • Integration: The scan action now loads and applies settings from the config file, respecting the CLI flag precedence.

Concerns

None. The implementation correctly handles precedence, error wrapping, and provides good test coverage.

Verdict

Approve


Code review performed by GEMINI - gemini-2.5-flash.

- Handle os.Getwd() error in scan action instead of silently discarding it
- Add integration tests for config auto-discovery (cwd and walk-up)
- Add integration tests for --config with missing/invalid file returning errors
- Add integration tests for format, output, and language fields from config file

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core Changes

This pull request introduces support for a .dupehound.yml configuration file, allowing users to define scan parameters outside of command-line flags. Key features include:

  • Config File Loading: The scan command now attempts to load a .dupehound.yml file, either specified explicitly via --config or auto-discovered by walking up the directory tree from the current working directory.
  • CLI Flag Precedence: Command-line flags always override values specified in the configuration file, providing a clear hierarchy for settings.
  • init Command: A new dupehound init command is added to generate a starter .dupehound.yml file, with an option to force overwrite existing files.
  • Configurable Options: The configuration file supports path, min-tokens, exclude, language, format, output, and exit-zero settings.

Concerns

None. The changes are well-implemented and thoroughly tested.

Verdict

Approve


Code review performed by GEMINI - gemini-2.5-flash.

@machado144
machado144 merged commit 224b53c into main Apr 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: config file support (.dupehound.yml)

1 participant

⌂ 换网址