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

Global System using directives should be sorted first #1003

Closed
vipentti opened this issue Nov 10, 2023 · 2 comments · Fixed by #1004 or #1035
Closed

Global System using directives should be sorted first #1003

vipentti opened this issue Nov 10, 2023 · 2 comments · Fixed by #1004 or #1035
Milestone

Comments

@vipentti
Copy link
Contributor

vipentti commented Nov 10, 2023

First of all, great project and big fan of automating formatting.

I noticed an inconsistency when it comes to sorting regular using System* directives vs global using System* directives:

When sorting the regular using directives the System using directives are ordered before the non-system using directives.

However when sorting global using all the directives are grouped together and sorted as one set.

Basically sorting the following:

using Library;
using System;
using AnotherLibrary;

Results in

using System;
using AnotherLibrary;
using Library;

Where as sorting the following:

global using Library;
global using System;
global using AnotherLibrary;

Results in

global using AnotherLibrary;
global using Library;
global using System;

My suggestion would be to use the same pattern with global System using directives so that they would be sorted before other non-System global using directives.

I don't mind doing the work if this sounds like a reasonable idea.

yield return globalUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return globalAliasUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return systemUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return aliasNameUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return regularUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return staticUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return aliasUsings.OrderBy(o => o.Using, Comparer).ToList();

@JamieJamesJamie
Copy link

This issue also highlights a conflict between CSharpier and StyleCop Analyzers SA1208. The inconsistency mentioned is picked up by that rule.

@belav belav added this to the 0.27.0 milestone Nov 15, 2023
@will-molloy
Copy link

Yeah this is inconsistent with dotnet format style so it conflicts with dotnet format (according to this page https://csharpier.com/docs/IntegratingWithLinters)

@belav belav modified the milestones: 0.27.0, 0.26.2 Nov 16, 2023
belav added a commit that referenced this issue Nov 21, 2023
belav added a commit that referenced this issue Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants