Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EditorConfig hierarchy not working as expected #987

Closed
parched opened this issue Nov 7, 2023 · 2 comments · Fixed by #991
Closed

EditorConfig hierarchy not working as expected #987

parched opened this issue Nov 7, 2023 · 2 comments · Fixed by #991
Labels
type:bug Something isn't working
Milestone

Comments

@parched
Copy link
Contributor

parched commented Nov 7, 2023

In the root directory I have .csharperrc.yaml which specifies the line length as 120.
Also, in the root directory I have .editorconfig which doesn't specify the line length.
In subdirectory A I have an .editorconfig which doesn't specify the line length either. (Note it also does not have root = true)

When I run dotnet csharpier . in the root directory, all the files in A get formatted with line length 100 (the default).

I expected the line length in the root .csharpierrc.yaml to be used, but it only does this when the A/.editorconfig doesn't exist.

I've now added max_line_length = 120 to the root .editorconfig and it works, but this was a surprise when upgrading to 0.26.

@belav
Copy link
Owner

belav commented Nov 7, 2023

The logic for this is currently

  1. Starting from the directory for a given file being formatted
  2. If the current directory contains a .csharpierrc use that
  3. Else if the current directory contains a .editorconfig use that. Take into account any .editorconfig files in parent folders until root = true is found
  4. Else move up to the parent directory and repeat

I'm thinking there are two possible fixes.

  1. If there is a .csharpierrc in or above the file being formatted, that will take priority over any .editorconfig file.
  2. In the case where an .editorconfig is found, merge the settings from it with the first .csharpierrc file that is found above a given .editorconfig

The first option is definitely easier to implement and also a lot easier to understand how it works. It seems like the correct way to handle this.

@belav belav added this to the 0.26.0 milestone Nov 7, 2023
@belav belav added the type:bug Something isn't working label Nov 7, 2023
@parched
Copy link
Contributor Author

parched commented Nov 7, 2023

Option 1 sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants