Skip to content

Commit

Permalink
Remove unnecessary [NotNull] attributes
Browse files Browse the repository at this point in the history
When subclassing `Command<TSettings>` 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<TSettings>.Execute(CommandContext, TSettings)` (possibly because of nullability attributes)

When subclassing `Command<TSettings>` 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 `<Nullable>enable</Nullable>` is set in the project, they are actually not necessary. By the way, the non-generic `Command` class does not have the [NotNull] attributes.
  • Loading branch information
0xced authored and patriksvensson committed Jul 12, 2023
1 parent 83afa97 commit 2af901a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/CommandOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class Command<TSettings> : ICommand<TSettings>
/// <param name="context">The command context.</param>
/// <param name="settings">The settings.</param>
/// <returns>The validation result.</returns>
public virtual ValidationResult Validate([NotNull] CommandContext context, [NotNull] TSettings settings)
public virtual ValidationResult Validate(CommandContext context, TSettings settings)
{
return ValidationResult.Success();
}
Expand All @@ -25,7 +25,7 @@ public virtual ValidationResult Validate([NotNull] CommandContext context, [NotN
/// <param name="context">The command context.</param>
/// <param name="settings">The settings.</param>
/// <returns>An integer indicating whether or not the command executed successfully.</returns>
public abstract int Execute([NotNull] CommandContext context, [NotNull] TSettings settings);
public abstract int Execute(CommandContext context, TSettings settings);

/// <inheritdoc/>
ValidationResult ICommand.Validate(CommandContext context, CommandSettings settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}[/]",
Expand Down
2 changes: 1 addition & 1 deletion src/Spectre.Console.Cli/Internal/Commands/XmlDocCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2af901a

Please sign in to comment.