Skip to content

feat: support config file in a .config directory - #1369

Merged
dsherret merged 4 commits into
mainfrom
dot-config-dir
Oct 18, 2026
Merged

dsherret merged 4 commits into
mainfrom
dot-config-dir

Conversation

@dsherret

@dsherret dsherret commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Closes #938

Adds support for putting the config file in a .config directory at .config/dprint.json or .config/dprint.jsonc.

A .config directory is treated as part of its parent directory:

  • When searching a directory for a config file, the existing names (dprint.json, dprint.jsonc, .dprint.json, .dprint.jsonc) are checked first and take precedence. Then the .config names are checked, but only if a .config directory exists.
  • The config file applies to the parent directory. Running dprint from within .config/ works the same as running it from any other subdirectory of the parent, so only the files in .config/ are formatted.
  • Patterns that match at any depth (ex. **/*.ts, node_modules) match within the parent directory. Anchored patterns (ex. ./x, src/**, ../src/**) stay relative to the config file. This is the same split --config already uses for paths outside its directory, and it applies whether the file is discovered or passed via --config.
  • Config files are never detected in a .config directory on its own, since its config file is found via the parent.
  • "inherit": true in a .config config inherits from the parent directory's ancestors. Inherited anchored excludes are rewritten so they still point at the same directories.
  • The home directory's .config (ex. ~/.config, the XDG config home) is an ordinary directory and is never searched as part of the home directory.
  • dprint init treats an existing .config/dprint.json(c) as an existing config file. It creates the config file at .config/dprint.json when the current directory already has a .config directory (dprint init --config dprint.json creates it in the current directory instead).

Performance

Checking for the .config directory before looking inside it means a directory without one, which is almost all of them, costs:

  • 1 extra stat in the startup ancestor walk and in the lookup used for file paths given on the command line (that lookup's results are cached per directory).
  • 0 extra syscalls in the glob traversal, because whether .config exists is already known from the directory listing it reads.

Behavior changes

  • Config files with other names directly in a .config directory (ex. .config/.dprint.json) are no longer discovered.
  • get_home_dir() in the real environment no longer panics when the home directory can't be canonicalized. It's called in more places now.

The VS Code extension is updated in dprint/dprint-vscode#191.

- base the association globs in the includes derived from the plugins the
  same way the association matcher does
- record a config file's anchored patterns directory where it's found
  rather than deriving it from the canonicalized path (symlinks, case
  insensitive file systems), and inherit from the config's base path
- don't treat the home directory's `.config` as a `.config` directory in
  `dprint init`, or in the lsp when given an uncanonicalized path
- cache the home directory
@dsherret
dsherret merged commit d613c4f into main Oct 18, 2026
22 checks passed
@dsherret
dsherret deleted the dot-config-dir branch October 18, 2026 19:50
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.

RFE: support loading config from .config/ subdir

1 participant