mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
parent
c2b25eea8a
commit
170901f584
@ -37,6 +37,12 @@ namespace Spectre.Console.Analyzer
|
|||||||
return;
|
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) &&
|
if (!HasFieldAnsiConsole(invocationOperation.Syntax) &&
|
||||||
!HasParameterAnsiConsole(invocationOperation.Syntax))
|
!HasParameterAnsiConsole(invocationOperation.Syntax))
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,28 @@ namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers
|
|||||||
Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id,
|
Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id,
|
||||||
DiagnosticSeverity.Info);
|
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]
|
[Fact]
|
||||||
public async void Instance_console_has_no_warnings()
|
public async void Instance_console_has_no_warnings()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user