Skip to content

Commit

Permalink
Merge pull request #3 from NikiforovAll/2-analyzer-should-check-that-…
Browse files Browse the repository at this point in the history
…elasticclient-type-is-from-nest-namespace-1

feat: check containing namespace
  • Loading branch information
NikiforovAll authored Sep 20, 2024
2 parents f6a7a3f + 99093f7 commit 0fb66c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ public ElasticsearchService()

await VerifyCS.VerifyCodeFixAsync(test, [expected1, expected2], fixtest);
}

[TestMethod]
public async Task SameNameButNotFromNamespaceShouldNotAddDiagnostic()
{
var test = """
public class ElasticClient
{
}
public class IElasticClient
{
}
public class MyService{
private readonly ElasticClient _client1;
private readonly IElasticClient _client2;
}
""";

await VerifyCS.VerifyAnalyzerAsync(test, []);
}
}

public static class VerifyCS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
return;
}

//var symbolInfo = context.SemanticModel.GetSymbolInfo(identifierNode);
//if (symbolInfo.Symbol == null)
//{
// return;
//}
//
//var containingNamespace = symbolInfo.Symbol.ContainingNamespace;
//if (containingNamespace == null || containingNamespace.ToString() != "Nest")
//{
// return;
//}
var symbolInfo = context.SemanticModel.GetSymbolInfo(identifierNode);
if (symbolInfo.Symbol == null)
{
return;
}

var containingNamespace = symbolInfo.Symbol.ContainingNamespace;
if (containingNamespace == null || containingNamespace.ToString() != "Nest")
{
return;
}

var diagnostic = Diagnostic.Create(s_rule, identifierNode.GetLocation());
context.ReportDiagnostic(diagnostic);
Expand Down
Binary file modified assets/elastic-search-playground-demo2.mp4
Binary file not shown.

0 comments on commit 0fb66c9

Please sign in to comment.