dotnet / dotnet/roslyn

Creating a new class doesn't respect `csharp_style_namespace_declarations` from .globalconfig

Open
#81,801 0 comments 0 reactions 0 assignees View on GitHub
Area-IDE IDE-Formatter
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

Create `.globalconfig` file setting `csharp_style_namespace_declarations` to `file_scoped`. Then create a new class in VS.

The new class should respect it. It alreayd does when the setting is in .editorconfig but not when in .globalconfig.

This probably comes from https://github.com/dotnet/roslyn/blob/7857fc6f40efbfd7b8d3f472e7139a35342e2204/src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs#L314 that explicitly looks at .editorconfig files.

I'm not sure if [this condition](https://github.com/dotnet/roslyn/blob/7857fc6f40efbfd7b8d3f472e7139a35342e2204/src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs#L304) is some how true (i.e, the above loop didn't find the project), and then `AddEditorConfigFiles` gets called which seems like a not super accurate implementation.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with a .globalconfig setting csharp_style_namespace_declarations to file_scoped, then create a class in Visual Studio. Read src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs around lines 304 and 314, including AddEditorConfigFiles, and verify that new class creation honors the global configuration as it already does for .editorconfig.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.