Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
40 changes: 40 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ dotnet_diagnostic.CA1305.severity = warning
# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = warning

# CA1510: Use ArgumentNullException throw helper
dotnet_diagnostic.CA1510.severity = warning

# CA1511: Use ArgumentException throw helper
dotnet_diagnostic.CA1511.severity = warning

# CA1512: Use ArgumentOutOfRangeException throw helper
dotnet_diagnostic.CA1512.severity = warning

# CA1513: Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1513.severity = warning

# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = suggestion

Expand Down Expand Up @@ -187,6 +199,18 @@ dotnet_diagnostic.CA1852.severity = warning
# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
dotnet_diagnostic.CA1854.severity = warning

# CA1855: Prefer 'Clear' over 'Fill'
dotnet_diagnostic.CA1855.severity = warning

# CA1856: Incorrect usage of ConstantExpected attribute
dotnet_diagnostic.CA1856.severity = error

# CA1857: A constant is expected for the parameter
dotnet_diagnostic.CA1857.severity = warning

# CA1858: Use 'StartsWith' instead of 'IndexOf'
dotnet_diagnostic.CA1858.severity = warning

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = warning

Expand Down Expand Up @@ -295,6 +319,14 @@ dotnet_diagnostic.IDE2000.severity = warning
dotnet_diagnostic.CA1018.severity = suggestion
# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = suggestion
# CA1510: Use ArgumentNullException throw helper
dotnet_diagnostic.CA1510.severity = suggestion
# CA1511: Use ArgumentException throw helper
dotnet_diagnostic.CA1511.severity = suggestion
# CA1512: Use ArgumentOutOfRangeException throw helper
dotnet_diagnostic.CA1512.severity = suggestion
# CA1513: Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1513.severity = suggestion
# CA1802: Use literals where appropriate
dotnet_diagnostic.CA1802.severity = suggestion
# CA1805: Do not initialize unnecessarily
Expand Down Expand Up @@ -333,6 +365,14 @@ dotnet_diagnostic.CA1847.severity = suggestion
dotnet_diagnostic.CA1852.severity = suggestion
# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
dotnet_diagnostic.CA1854.severity = suggestion
# CA1855: Prefer 'Clear' over 'Fill'
dotnet_diagnostic.CA1855.severity = suggestion
# CA1856: Incorrect usage of ConstantExpected attribute
dotnet_diagnostic.CA1856.severity = suggestion
# CA1857: A constant is expected for the parameter
dotnet_diagnostic.CA1857.severity = suggestion
# CA1858: Use 'StartsWith' instead of 'IndexOf'
dotnet_diagnostic.CA1858.severity = suggestion
# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = suggestion
# CA2008: Do not create tasks without passing a TaskScheduler
Expand Down
6 changes: 6 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<!-- Ignore API doc requirements for test assets -->
<NoWarn Condition="'$(IsTestAssetProject)' == 'true' or '$(IsSampleProject)' == 'true' or '$(IsBenchmarkProject)' == 'true' or
'$(IsMicrobenchmarksProject)' == 'true'">$(NoWarn);CS1591</NoWarn>

<!-- Ignore analyzers that recommend APIs introduced in .NET Core when targeting frameworks that lack those APIs
to avoid issues with multitargeting.
Some projects only build DefaultNetCoreTargetFramework when DotNetBuildFromSource is true so also suppress for source build.
-->
<NoWarn Condition="$(TargetFrameworks.Contains('NetFramework')) or $(TargetFrameworks.Contains('netstandard')) or '$(DotNetBuildFromSource)' == 'true'">$(NoWarn);CA1510;CA1511;CA1512;CA1513</NoWarn>
</PropertyGroup>

<PropertyGroup Label="Resx settings">
Expand Down
16 changes: 3 additions & 13 deletions src/Antiforgery/src/AntiforgeryServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public static class AntiforgeryServiceCollectionExtensions
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddAntiforgery(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
ArgumentNullException.ThrowIfNull(services);

services.AddDataProtection();

Expand Down Expand Up @@ -57,15 +54,8 @@ public static IServiceCollection AddAntiforgery(this IServiceCollection services
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddAntiforgery(this IServiceCollection services, Action<AntiforgeryOptions> setupAction)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(setupAction);

services.AddAntiforgery();
services.Configure(setupAction);
Expand Down
5 changes: 1 addition & 4 deletions src/Antiforgery/src/AntiforgeryTokenSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public AntiforgeryTokenSet(
string formFieldName,
string? headerName)
{
if (formFieldName == null)
{
throw new ArgumentNullException(nameof(formFieldName));
}
ArgumentNullException.ThrowIfNull(formFieldName);

RequestToken = requestToken;
CookieToken = cookieToken;
Expand Down
5 changes: 1 addition & 4 deletions src/Antiforgery/src/Internal/AntiforgeryOptionsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public AntiforgeryOptionsSetup(IOptions<DataProtectionOptions> dataProtectionOpt

public void Configure(AntiforgeryOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);

if (options.Cookie.Name == null)
{
Expand Down
25 changes: 5 additions & 20 deletions src/Antiforgery/src/Internal/DefaultAntiforgery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public DefaultAntiforgery(
/// <inheritdoc />
public AntiforgeryTokenSet GetAndStoreTokens(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

CheckSSLConfig(httpContext);

Expand Down Expand Up @@ -79,10 +76,7 @@ public AntiforgeryTokenSet GetAndStoreTokens(HttpContext httpContext)
/// <inheritdoc />
public AntiforgeryTokenSet GetTokens(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

CheckSSLConfig(httpContext);

Expand All @@ -93,10 +87,7 @@ public AntiforgeryTokenSet GetTokens(HttpContext httpContext)
/// <inheritdoc />
public async Task<bool> IsRequestValidAsync(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

CheckSSLConfig(httpContext);

Expand Down Expand Up @@ -151,10 +142,7 @@ public async Task<bool> IsRequestValidAsync(HttpContext httpContext)
/// <inheritdoc />
public async Task ValidateRequestAsync(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

CheckSSLConfig(httpContext);

Expand Down Expand Up @@ -220,10 +208,7 @@ private void ValidateTokens(HttpContext httpContext, AntiforgeryTokenSet antifor
/// <inheritdoc />
public void SetCookieTokenAndHeader(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

CheckSSLConfig(httpContext);

Expand Down
16 changes: 3 additions & 13 deletions src/Antiforgery/src/Internal/DefaultAntiforgeryTokenGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ public AntiforgeryToken GenerateRequestToken(
HttpContext httpContext,
AntiforgeryToken cookieToken)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}

if (cookieToken == null)
{
throw new ArgumentNullException(nameof(cookieToken));
}
ArgumentNullException.ThrowIfNull(httpContext);
ArgumentNullException.ThrowIfNull(cookieToken);

if (!IsCookieTokenValid(cookieToken))
{
Expand Down Expand Up @@ -112,10 +105,7 @@ public bool TryValidateTokenSet(
AntiforgeryToken requestToken,
[NotNullWhen(false)] out string? message)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
ArgumentNullException.ThrowIfNull(httpContext);

if (cookieToken == null)
{
Expand Down
16 changes: 3 additions & 13 deletions src/Antiforgery/src/Internal/DefaultAntiforgeryTokenSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ public DefaultAntiforgeryTokenSerializer(
IDataProtectionProvider provider,
ObjectPool<AntiforgerySerializationContext> pool)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}

if (pool == null)
{
throw new ArgumentNullException(nameof(pool));
}
ArgumentNullException.ThrowIfNull(provider);
ArgumentNullException.ThrowIfNull(pool);

_cryptoSystem = provider.CreateProtector(Purpose);
_pool = pool;
Expand Down Expand Up @@ -131,10 +124,7 @@ public AntiforgeryToken Deserialize(string serializedToken)

public string Serialize(AntiforgeryToken token)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);

var serializationContext = _pool.Get();

Expand Down
5 changes: 1 addition & 4 deletions src/Antiforgery/src/Internal/DefaultAntiforgeryTokenStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ internal sealed class DefaultAntiforgeryTokenStore : IAntiforgeryTokenStore

public DefaultAntiforgeryTokenStore(IOptions<AntiforgeryOptions> optionsAccessor)
{
if (optionsAccessor == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}
ArgumentNullException.ThrowIfNull(optionsAccessor);

_options = optionsAccessor.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public static class AppServicesWebHostBuilderExtensions
/// <returns></returns>
public static IWebHostBuilder UseAzureAppServices(this IWebHostBuilder hostBuilder)
{
if (hostBuilder == null)
{
throw new ArgumentNullException(nameof(hostBuilder));
}
ArgumentNullException.ThrowIfNull(hostBuilder);
#pragma warning disable 618
hostBuilder.ConfigureLogging(builder => builder.AddAzureWebAppDiagnostics());
#pragma warning restore 618
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public abstract class AuthenticationStateProvider
/// <param name="task">A <see cref="Task"/> that supplies the updated <see cref="AuthenticationState"/>.</param>
protected void NotifyAuthenticationStateChanged(Task<AuthenticationState> task)
{
if (task == null)
{
throw new ArgumentNullException(nameof(task));
}
ArgumentNullException.ThrowIfNull(task);

AuthenticationStateChanged?.Invoke(task);
}
Expand Down
17 changes: 3 additions & 14 deletions src/Components/Components/src/BindElementAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,9 @@ public sealed class BindElementAttribute : Attribute
/// <param name="changeAttribute">The name of an attribute that will register an associated change event.</param>
public BindElementAttribute(string element, string? suffix, string valueAttribute, string changeAttribute)
{
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}

if (valueAttribute == null)
{
throw new ArgumentNullException(nameof(valueAttribute));
}

if (changeAttribute == null)
{
throw new ArgumentNullException(nameof(changeAttribute));
}
ArgumentNullException.ThrowIfNull(element);
ArgumentNullException.ThrowIfNull(valueAttribute);
ArgumentNullException.ThrowIfNull(changeAttribute);

Element = element;
ValueAttribute = valueAttribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public sealed class CascadingTypeParameterAttribute : Attribute
/// <param name="name">The name of the type parameter.</param>
public CascadingTypeParameterAttribute(string name)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
ArgumentNullException.ThrowIfNull(name);

Name = name;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Components/Components/src/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public void AssertAccess()
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/>.</param>
protected void OnUnhandledException(UnhandledExceptionEventArgs e)
{
if (e is null)
{
throw new ArgumentNullException(nameof(e));
}
ArgumentNullException.ThrowIfNull(e);

UnhandledException?.Invoke(this, e);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Components/Components/src/ErrorBoundaryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ public void Recover()

void IErrorBoundary.HandleException(Exception exception)
{
if (exception is null)
{
// This would be a framework bug if it happened. It should not be possible.
throw new ArgumentNullException(nameof(exception));
}
ArgumentNullException.ThrowIfNull(exception);

// If rendering the error content itself causes an error, then re-rendering on error risks creating an
// infinite error loop. Unfortunately it's very hard to distinguish whether the error source is "child content"
Expand Down
Loading