From 2af901a814b6a60bc9fb534a0f1f7afc76e9bb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Wed, 12 Jul 2023 14:15:41 +0200 Subject: [PATCH] Remove unnecessary [NotNull] attributes When subclassing `Command` which has the [NotNull] attributes, Rider/ReSharper gives this warning: > Nullability of type of parameter 'context' in method does not match overridden member `int Spectre.Console.Cli.Command.Execute(CommandContext, TSettings)` (possibly because of nullability attributes) When subclassing `Command` which does not have the [NotNull] attributes, Rider/ReSharper gives this warning: > The nullability attribute has no effect and can be safely removed The solution is simply to remove the [NotNull] attributes. Since `enable` is set in the project, they are actually not necessary. By the way, the non-generic `Command` class does not have the [NotNull] attributes. --- src/Spectre.Console.Cli/CommandOfT.cs | 4 ++-- src/Spectre.Console.Cli/Internal/Commands/ExplainCommand.cs | 2 +- src/Spectre.Console.Cli/Internal/Commands/VersionCommand.cs | 2 +- src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs | 2 +- .../Spectre.Console.Cli.Tests/Data/Commands/GreeterCommand.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Spectre.Console.Cli/CommandOfT.cs b/src/Spectre.Console.Cli/CommandOfT.cs index 3415e3289..e2be58ef1 100644 --- a/src/Spectre.Console.Cli/CommandOfT.cs +++ b/src/Spectre.Console.Cli/CommandOfT.cs @@ -14,7 +14,7 @@ public abstract class Command : ICommand /// The command context. /// The settings. /// The validation result. - public virtual ValidationResult Validate([NotNull] CommandContext context, [NotNull] TSettings settings) + public virtual ValidationResult Validate(CommandContext context, TSettings settings) { return ValidationResult.Success(); } @@ -25,7 +25,7 @@ public virtual ValidationResult Validate([NotNull] CommandContext context, [NotN /// The command context. /// The settings. /// An integer indicating whether or not the command executed successfully. - public abstract int Execute([NotNull] CommandContext context, [NotNull] TSettings settings); + public abstract int Execute(CommandContext context, TSettings settings); /// ValidationResult ICommand.Validate(CommandContext context, CommandSettings settings) diff --git a/src/Spectre.Console.Cli/Internal/Commands/ExplainCommand.cs b/src/Spectre.Console.Cli/Internal/Commands/ExplainCommand.cs index 85467a17c..832872d0c 100644 --- a/src/Spectre.Console.Cli/Internal/Commands/ExplainCommand.cs +++ b/src/Spectre.Console.Cli/Internal/Commands/ExplainCommand.cs @@ -34,7 +34,7 @@ public Settings(string[]? commands, bool? detailed, bool includeHidden) public bool IncludeHidden { get; } } - public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings) + public override int Execute(CommandContext context, Settings settings) { var tree = new Tree("CLI Configuration"); tree.AddNode(ValueMarkup("Application Name", _commandModel.ApplicationName, "no application name")); diff --git a/src/Spectre.Console.Cli/Internal/Commands/VersionCommand.cs b/src/Spectre.Console.Cli/Internal/Commands/VersionCommand.cs index 4a944e393..20f3e70d6 100644 --- a/src/Spectre.Console.Cli/Internal/Commands/VersionCommand.cs +++ b/src/Spectre.Console.Cli/Internal/Commands/VersionCommand.cs @@ -15,7 +15,7 @@ public sealed class Settings : CommandSettings { } - public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings) + public override int Execute(CommandContext context, Settings settings) { _writer.MarkupLine( "[yellow]Spectre.Cli[/] version [aqua]{0}[/]", diff --git a/src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs b/src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs index fb6cadc08..807251833 100644 --- a/src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs +++ b/src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs @@ -17,7 +17,7 @@ public sealed class Settings : CommandSettings { } - public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings) + public override int Execute(CommandContext context, Settings settings) { _writer.Write(Serialize(_model), Style.Plain); return 0; diff --git a/test/Spectre.Console.Cli.Tests/Data/Commands/GreeterCommand.cs b/test/Spectre.Console.Cli.Tests/Data/Commands/GreeterCommand.cs index 7e3e653ed..cb7bddae0 100644 --- a/test/Spectre.Console.Cli.Tests/Data/Commands/GreeterCommand.cs +++ b/test/Spectre.Console.Cli.Tests/Data/Commands/GreeterCommand.cs @@ -9,7 +9,7 @@ public GreeterCommand(IAnsiConsole console) _console = console; } - public override int Execute([NotNull] CommandContext context, [NotNull] OptionalArgumentWithDefaultValueSettings settings) + public override int Execute(CommandContext context, OptionalArgumentWithDefaultValueSettings settings) { _console.WriteLine(settings.Greeting); return 0;