Skip to content

Conversation

LoKolbasz
Copy link

Generate editorconfig based on the current/selected rustfmt config, that sets the rules for all rust source files.
Available only as a nightly option.

Usage

  1. Output editorconfig to stdout
rustfmt --editorconfig
# Generated by rustfmt version: 1.8.0-nightly (0332da0148 2025-06-21)

[*.rs]
indent_style = space
indent_size = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
  1. Append to the specified file
rustfmt --editorconfig=.editorconfig
cat .editorconfig
# Generated by rustfmt version: 1.8.0-nightly (0332da0148 2025-06-21)

[*.rs]
indent_style = space
indent_size = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
  1. Append to the .editorconfig file in a specified directory
rustfmt --editorconfig=./
cat .editorconfig
# Generated by rustfmt version: 1.8.0-nightly (0332da0148 2025-06-21)

[*.rs]
indent_style = space
indent_size = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
  1. Specify rustfmt.toml path for the generator to use
rustfmt --editorconfig --config-path=/path/to/rustfmt/config/
# Generated by rustfmt version: 1.8.0-nightly (0332da0148 2025-06-21)

[*.rs]
indent_style = space
indent_size = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100

Value mapping:

Rustfmt EditorConfig
indentstyle indent_style(left unset when auto)
X indent_size=tab
tab_spaces tab_width
new_line_style end_of_line
X charset=utf-8 (AFAIK all rust files are utf-8)
X trim_trailing_whitespace=true
X insert_final_newline=true
max_width max_line_length
  • I'm unsure about indent_size and tab_spaces. It might be better to switch them up, and only set indent_size
  • trim_trailing_whitespace and insert_final_newline are set to true, as that is what rustfmt does without any explicit configuration needed (AFAIK).

Important

This option does not check wether the generated config will be placed in the root editorconfig. root=true must be set in the preamble of the .editorcofig file by the user if it is the root editorconfig.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 13, 2025

I don't think we're going to support this at this time

@LoKolbasz
Copy link
Author

In #2999 they said, that we could submit a PR 😞 .
But I understand.

@LoKolbasz LoKolbasz deleted the editorconfig branch October 13, 2025 22:49
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.

3 participants