File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
src/Meziantou.Analyzer/Rules
tests/Meziantou.Analyzer.Test/Rules Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,9 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
8686 var isFirstType = true ;
8787 foreach ( var node in root . DescendantNodesAndSelf ( descendIntoChildren : node => ! IsTypeDeclaration ( node ) ) )
8888 {
89+ if ( ! IsTypeDeclaration ( node ) )
90+ continue ;
91+
8992 if ( node . SpanStart < symbolNode . SpanStart )
9093 {
9194 isFirstType = false ;
Original file line number Diff line number Diff line change @@ -247,6 +247,36 @@ struct Bar {}
247247 . ValidateAsync ( ) ;
248248 }
249249
250+ [ Fact ]
251+ public async Task MatchOnlyFirstType_TypeWithBlockScopedNamespaceDeclaration ( )
252+ {
253+ await CreateProjectBuilder ( )
254+ . WithSourceCode ( fileName : "Test0.cs" , """
255+ namespace Sample
256+ {
257+ struct [||]Foo {}
258+ struct Bar {}
259+ }
260+ """ )
261+ . AddAnalyzerConfiguration ( "MA0048.only_validate_first_type" , "true" )
262+ . ValidateAsync ( ) ;
263+ }
264+
265+ #if CSHARP10_OR_GREATER
266+ [ Fact ]
267+ public async Task MatchOnlyFirstType_TypeWithFileScopedNamespaceDeclaration ( )
268+ {
269+ await CreateProjectBuilder ( )
270+ . WithSourceCode ( fileName : "Test0.cs" , """
271+ namespace Sample;
272+ struct [||]Foo {}
273+ struct Bar {}
274+ """ )
275+ . AddAnalyzerConfiguration ( "MA0048.only_validate_first_type" , "true" )
276+ . ValidateAsync ( ) ;
277+ }
278+ #endif
279+
250280 [ Theory ]
251281 [ InlineData ( "Sample" ) ]
252282 [ InlineData ( "T:MyNamespace.Sample" ) ]
You can’t perform that action at this time.
0 commit comments