mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 09:09:25 +08:00 
			
		
		
		
	 Phil Scott
					Phil Scott
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							c2b25eea8a
						
					
				
				
					commit
					170901f584
				
			| @@ -37,6 +37,12 @@ namespace Spectre.Console.Analyzer | ||||
|                         return; | ||||
|                     } | ||||
|  | ||||
|                     // if we aren't in a method then it might be too complex for us to handle. | ||||
|                     if (!invocationOperation.Syntax.Ancestors().OfType<MethodDeclarationSyntax>().Any()) | ||||
|                     { | ||||
|                         return; | ||||
|                     } | ||||
|  | ||||
|                     if (!HasFieldAnsiConsole(invocationOperation.Syntax) && | ||||
|                         !HasParameterAnsiConsole(invocationOperation.Syntax)) | ||||
|                     { | ||||
|   | ||||
| @@ -10,6 +10,28 @@ namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers | ||||
|             Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id, | ||||
|             DiagnosticSeverity.Info); | ||||
|  | ||||
|         [Fact] | ||||
|         public async void Should_only_warn_within_methods() | ||||
|         { | ||||
|             const string Source = @" | ||||
| using Spectre.Console; | ||||
|  | ||||
| internal sealed class Foo | ||||
| { | ||||
|     private readonly IAnsiConsole _console; | ||||
|  | ||||
|     public Foo(IAnsiConsole console = null) | ||||
|     { | ||||
|         _console = console ?? AnsiConsole.Create(new AnsiConsoleSettings()); | ||||
|     } | ||||
| } | ||||
| "; | ||||
|  | ||||
|             await SpectreAnalyzerVerifier<FavorInstanceAnsiConsoleOverStaticAnalyzer> | ||||
|                 .VerifyAnalyzerAsync(Source) | ||||
|                 .ConfigureAwait(false); | ||||
|         } | ||||
|          | ||||
|         [Fact] | ||||
|         public async void Instance_console_has_no_warnings() | ||||
|         { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user