Skip to content

fix: format explicit paths outside the --config file's directory with its unanchored patterns - #1314

Merged
dsherret merged 1 commit into
mainfrom
fix-stdin-outside-config-dir
Oct 10, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix-stdin-outside-config-dir

Conversation

@dsherret

@dsherret dsherret commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Fixes dprint/dprint-plugin-markdown#287

Since #1257, a local --config file's patterns are relative to the config file's directory. That left --stdin with an absolute path broken for anyone pointing -c at a config in another directory (ex. a personal config used by an editor integration):

dprint fmt -c ~/.config/dprint/dprint.jsonc --stdin ~/a.md < ~/a.md

The file was outside the config file's directory, so it was treated as not matched and the input was echoed back unformatted, even with no includes in the config. dprint fmt -c ... ~/a.md formatted the same file.

Behavior

For a config file specified via --config and an explicitly specified file outside its directory (the --stdin path or a fmt/check path arg):

Config pattern Applies to the outside file?
no includes yes, the file is formatted
**/*.md, ** yes
*.md, dist (no slash) yes
src/**/*.md, ./sub, ../other no, stays relative to the config file's directory

The same applies to excludes, plugin associations, and the files of plugin config overrides.

This only affects explicitly specified paths. dprint fmt -c sub/dprint.json with no path args still only walks sub/.

Breaking change

A fmt/check path arg outside the --config file's directory previously had all of the config's patterns re-anchored at the path's root directory, so "includes": ["src/**/*.md"] in /config/dprint.json matched /src/file.md. That predates #1257 and contradicted it. Anchored patterns now stay relative to the config file's directory, so that include no longer matches /src/file.md.

Changes

  • ResolvedConfig has a new optional anchored_patterns_base_path. When a --config file is rebased at the root directory of an outside path, it keeps the config file's directory, and new_config_glob_pattern bases the patterns that match at any depth at the root and the anchored ones at the config file's directory.
  • stdin_fmt rebases the config the same way fmt does for a path arg, using the same definition of "outside" (outside the highest directory the includes are based at).
  • Includes that can't reach the rebased directory (ex. anchored includes when the path is on another drive on Windows) are removed so the result doesn't depend on the order of the includes.

Not changed:

  • The global config file and discovered config files behave as before for --stdin.
  • Editor service and LSP matching.

Known limitations

  • ./**/*.md is anchored, so a config using that form still doesn't match an outside file. **/*.md does.
  • With a ../ include, a file within the ancestor directory the include is based at but outside the config file's directory doesn't get the any-depth patterns applied (ex. /a/config/dprint.json with "includes": ["../other/**/*.txt", "**/*.txt"] doesn't match /a/sibling/file.txt). --stdin and path args agree on this.

Testing

  • --stdin with a file outside the --config file's directory: no includes, --excludes still applying, any-depth vs anchored includes and excludes, and a ../ include.
  • The same patterns through fmt path args to check both agree.
  • Unit tests for the pattern classification and for includes on another drive (Windows only).
  • Checked the issue's reproduction with a local build and the markdown plugin.

@dsherret dsherret changed the title fix(BREAKING): format explicit paths outside the --config file's directory with only its unanchored patterns fix: format explicit paths outside the --config file's directory with only its unanchored patterns Oct 10, 2026
@dsherret
dsherret merged commit 47a3360 into main Oct 10, 2026
17 checks passed
@dsherret
dsherret deleted the fix-stdin-outside-config-dir branch October 10, 2026 17:36
@dsherret dsherret changed the title fix: format explicit paths outside the --config file's directory with only its unanchored patterns fix: format explicit paths outside the --config file's directory with its unanchored patterns Oct 10, 2026
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.

1 participant