Skip to content

Commit 188fa79

Browse files
authored
Fix method GetRootNamespace (RCS0015) (#1000)
1 parent 1a9c2c8 commit 188fa79

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Fix refactoring ([RR0180](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RR0180.md)) ([#988](https://github.com/josefpihrt/roslynator/pull/988)).
3737
- Recognize `ArgumentNullException.ThrowIfNull` ([RCS1227](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1227.md)) ([#992](https://github.com/josefpihrt/roslynator/pull/992)).
3838
- Detect pattern matching in [RCS1146](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1146.md) ([#999](https://github.com/josefpihrt/roslynator/pull/999)).
39+
- Handle `using` directive that starts with `global::` [RCS0015](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS0015.md) ([#1000](https://github.com/josefpihrt/roslynator/pull/1000)).
3940

4041
## [4.1.2] - 2022-10-31
4142

src/CSharp/CSharp/Extensions/SyntaxExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,10 +4211,15 @@ public static bool IsVoid(this TypeSyntax type)
42114211
#region UsingDirectiveSyntax
42124212
internal static IdentifierNameSyntax GetRootNamespace(this UsingDirectiveSyntax usingDirective)
42134213
{
4214-
if (usingDirective.Name is IdentifierNameSyntax identifierName)
4214+
NameSyntax name = usingDirective.Name;
4215+
4216+
if (name is AliasQualifiedNameSyntax aliasQualifiedName)
4217+
name = aliasQualifiedName.Name;
4218+
4219+
if (name is IdentifierNameSyntax identifierName)
42154220
return identifierName;
42164221

4217-
if (usingDirective.Name is QualifiedNameSyntax qualifiedName)
4222+
if (name is QualifiedNameSyntax qualifiedName)
42184223
{
42194224
NameSyntax left;
42204225

@@ -4233,7 +4238,7 @@ internal static IdentifierNameSyntax GetRootNamespace(this UsingDirectiveSyntax
42334238
}
42344239
else
42354240
{
4236-
SyntaxDebug.Fail(usingDirective.Name);
4241+
SyntaxDebug.Fail(name);
42374242
}
42384243

42394244
return null;

src/Tests/Formatting.Analyzers.Tests/RCS0015BlankLineBetweenUsingDirectivesTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ class C
3030
3131
using System.Threading;
3232
33+
class C
34+
{
35+
}
36+
", options: Options.AddConfigOption(ConfigOptionKeys.BlankLineBetweenUsingDirectives, ConfigOptionValues.BlankLineBetweenUsingDirectives_SeparateGroups));
37+
}
38+
39+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.BlankLineBetweenUsingDirectives)]
40+
public async Task Test_AddEmptyLine_GlobalAlias()
41+
{
42+
await VerifyDiagnosticAndFixAsync(@"
43+
using global::System;[||]
44+
using Microsoft.CodeAnalysis;[||]
45+
using System.Threading;
46+
47+
class C
48+
{
49+
}
50+
", @"
51+
using global::System;
52+
53+
using Microsoft.CodeAnalysis;
54+
55+
using System.Threading;
56+
3357
class C
3458
{
3559
}

0 commit comments

Comments
 (0)