Skip to content

Commit

Permalink
Merge pull request #3135 from VitaliAntonov/issue-2618
Browse files Browse the repository at this point in the history
Improve SA1135 handling of static usings
  • Loading branch information
sharwell authored Jul 30, 2020
2 parents 1ee512c + 3e03710 commit d2bc750
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ namespace System.Threading
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestStaticUsingsAsync()
{
const string testCode = @"
namespace System.Threading
{
using static Console;
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestFixAllAsync()
{
Expand Down Expand Up @@ -455,5 +443,31 @@ namespace System

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(2618, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2618")]
public async Task TestUnqualifiedStaticUsingsAsync()
{
const string testCode = @"
namespace System.Threading
{
using static Console;
}
";

const string fixedCode = @"
namespace System.Threading
{
using static System.Console;
}
";

DiagnosticResult[] expected =
{
Diagnostic(SA1135UsingDirectivesMustBeQualified.DescriptorType).WithLocation(4, 5).WithArguments("System.Console"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ private static void CheckUsingDeclaration(SyntaxNodeAnalysisContext context, Usi
return;
}

if (!usingDirective.StaticKeyword.IsKind(SyntaxKind.None))
{
// using static types is not considered.
return;
}

if (usingDirective.HasNamespaceAliasQualifier())
{
// global qualified namespaces are OK.
Expand Down

0 comments on commit d2bc750

Please sign in to comment.