Skip to content

Commit

Permalink
Fix method GetRootNamespace (RCS0015) (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Nov 26, 2022
1 parent 1a9c2c8 commit 188fa79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix refactoring ([RR0180](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RR0180.md)) ([#988](https://github.com/josefpihrt/roslynator/pull/988)).
- Recognize `ArgumentNullException.ThrowIfNull` ([RCS1227](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1227.md)) ([#992](https://github.com/josefpihrt/roslynator/pull/992)).
- Detect pattern matching in [RCS1146](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1146.md) ([#999](https://github.com/josefpihrt/roslynator/pull/999)).
- 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)).

## [4.1.2] - 2022-10-31

Expand Down
11 changes: 8 additions & 3 deletions src/CSharp/CSharp/Extensions/SyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4211,10 +4211,15 @@ public static bool IsVoid(this TypeSyntax type)
#region UsingDirectiveSyntax
internal static IdentifierNameSyntax GetRootNamespace(this UsingDirectiveSyntax usingDirective)
{
if (usingDirective.Name is IdentifierNameSyntax identifierName)
NameSyntax name = usingDirective.Name;

if (name is AliasQualifiedNameSyntax aliasQualifiedName)
name = aliasQualifiedName.Name;

if (name is IdentifierNameSyntax identifierName)
return identifierName;

if (usingDirective.Name is QualifiedNameSyntax qualifiedName)
if (name is QualifiedNameSyntax qualifiedName)
{
NameSyntax left;

Expand All @@ -4233,7 +4238,7 @@ internal static IdentifierNameSyntax GetRootNamespace(this UsingDirectiveSyntax
}
else
{
SyntaxDebug.Fail(usingDirective.Name);
SyntaxDebug.Fail(name);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ class C
using System.Threading;
class C
{
}
", options: Options.AddConfigOption(ConfigOptionKeys.BlankLineBetweenUsingDirectives, ConfigOptionValues.BlankLineBetweenUsingDirectives_SeparateGroups));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.BlankLineBetweenUsingDirectives)]
public async Task Test_AddEmptyLine_GlobalAlias()
{
await VerifyDiagnosticAndFixAsync(@"
using global::System;[||]
using Microsoft.CodeAnalysis;[||]
using System.Threading;
class C
{
}
", @"
using global::System;
using Microsoft.CodeAnalysis;
using System.Threading;
class C
{
}
Expand Down

0 comments on commit 188fa79

Please sign in to comment.