Skip to content

fix(config): search for config file recursively on --config-path - #7115

Open
rami3l wants to merge 4 commits into
rust-lang:mainfrom
rami3l:fix/config-path-dirwalk
Open

fix(config): search for config file recursively on --config-path#7115
rami3l wants to merge 4 commits into
rust-lang:mainfrom
rami3l:fix/config-path-dirwalk

Conversation

@rami3l

@rami3l rami3l commented Sep 11, 2026

Copy link
Copy Markdown
Member

Note

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

LLM has been used to analyze the existing usage of directory walking behavior.
The implementation of this patch is otherwise fully manual.

Closes #4660 based on the design discussed in #4660 (comment).

Background

The --config-path help description says:

        --config-path [Path for the configuration file]
                        Recursively searches the given path for the
                        rustfmt.toml config file. If not found reverts to the
                        input file path

However this description is not quite appropriate because:

  • It's unclear whether the path being passed in is a directory, or a TOML file.
  • Recursive search doesn't really happen when this argument is passed to rustfmt.

To be more precise, the current semantics of --config-path is that when it receives a path, it chooses to enter one of the following modes in the below fallback order:

  • Base dir mode: If path is exists and metadata says it's a dir, then search for predefined names ([".rustfmt.toml", "rustfmt.toml"]) under path only. Bails out if none is found.
  • TOML mode: If path exists and the metadata says it's not a dir, then interpret it as a TOML file. Bails out if none is found.

Proposed solution

This PR changes it to:

  • Base dir mode: If path terminates with /, or if it exists and metadata says it's a dir, then search for predefined names ([".rustfmt.toml", "rustfmt.toml"]) under path and all its parents. Bails out if none is found.
  • TOML mode: Otherwise, interpret it as a TOML file by searching for its filename under its parent dir and all parents of the latter. Bails out if none is found.

@rustbot rustbot added the S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. label Sep 11, 2026
@rami3l
rami3l marked this pull request as ready for review September 11, 2026 20:46
@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Sep 11, 2026
@rami3l
rami3l force-pushed the fix/config-path-dirwalk branch from ba0a09c to 6bc2a74 Compare September 11, 2026 20:52
@rami3l
rami3l marked this pull request as draft September 12, 2026 07:14
@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Sep 12, 2026
@rami3l

rami3l commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

I still some concerns regarding the distinction between the dir mode and the TOML mode, so reconverting to draft.

@rami3l
rami3l force-pushed the fix/config-path-dirwalk branch from 6bc2a74 to 3f3d54b Compare September 12, 2026 08:23
@rami3l
rami3l marked this pull request as ready for review September 12, 2026 08:49
@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Sep 12, 2026
@rami3l

rami3l commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

Addressed the concern regarding mode switching; updated both the PR description accordingly to reflect the new design. This PR is ready for review 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recursive --config-path doesn't recurse

2 participants