Describe the bug
context
When --exclude is passed on the CLI, it completely replaces the exclude list from .mdformat.toml rather than merging with it. This makes it impossible to use both CLI and config exclusions together.
expectation
CLI --exclude patterns should be additive with .mdformat.toml exclude patterns. Passing --exclude "node_modules/**" on the CLI should add that pattern to whatever is already defined in the config file, not replace it.
use case
I maintain a shared just module that wraps mdformat for multiple repositories. Each repository has its own .mdformat.toml with repo-specific exclusions. I wanted to add a common exclusion (node_modules/**) at the CLI level without having to duplicate it across every repo's config file, but the current behavior makes this impossible.
Reproduce the bug
mkdir -p /tmp/mdformat-test/node_modules /tmp/mdformat-test/vendor
cat > /tmp/mdformat-test/.mdformat.toml << 'EOF'
exclude = [
"vendor/**",
]
EOF
echo -e "# bad\n* extra spaces" > /tmp/mdformat-test/node_modules/test.md
echo -e "# bad\n* extra spaces" > /tmp/mdformat-test/vendor/test.md
cd /tmp/mdformat-test
Without --exclude (TOML works as expected):
$ mdformat --check .
Error: File "node_modules/test.md" is not formatted.
# vendor/test.md is correctly excluded by TOML
With --exclude (TOML exclusions are lost):
$ mdformat --check --exclude "node_modules/**" .
Error: File "vendor/test.md" is not formatted.
# vendor/test.md is no longer excluded — the TOML exclude was overwritten
List your environment
$ mdformat --version
mdformat 1.0.0 (mdformat-gfm 1.0.0, mdformat_frontmatter 2.0.10)
$ python3 --version
Python 3.14.13
Describe the bug
context
When
--excludeis passed on the CLI, it completely replaces theexcludelist from.mdformat.tomlrather than merging with it. This makes it impossible to use both CLI and config exclusions together.expectation
CLI
--excludepatterns should be additive with.mdformat.tomlexcludepatterns. Passing--exclude "node_modules/**"on the CLI should add that pattern to whatever is already defined in the config file, not replace it.use case
I maintain a shared just module that wraps
mdformatfor multiple repositories. Each repository has its own.mdformat.tomlwith repo-specific exclusions. I wanted to add a common exclusion (node_modules/**) at the CLI level without having to duplicate it across every repo's config file, but the current behavior makes this impossible.Reproduce the bug
Without
--exclude(TOML works as expected):With
--exclude(TOML exclusions are lost):List your environment