Skip to content

Enable a few whitespace enforcing IDE rules #40769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ csharp_style_namespace_declarations = file_scoped
# Brace settings
csharp_prefer_braces = true # Prefer curly braces even for one line of code

# Whitespace options
csharp_style_allow_embedded_statements_on_same_line_experimental = false
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if @dotnet/aspdoi has discussed these settings but this particular one is actively annoying and I'd much rather we didn't take it.

Comment on lines +58 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should wait until experimental features have been released for real before incorporating them in this repo. There's no reason to rush here.
I'd go further there and say we're in the weeds here; #24055 was about FxCop, not StyleCop, and certainly not teensy whitespace rules.


[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
indent_size = 2

Expand Down Expand Up @@ -263,6 +268,18 @@ dotnet_diagnostic.IDE0161.severity = warning
dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = warning

# IDE2001: Embedded statements must be on their own line
dotnet_diagnostic.IDE2001.severity = warning

# IDE2002: Consecutive braces must not have blank line between them
dotnet_diagnostic.IDE2002.severity = warning

# IDE2003: Blank line required between block and subsequent statement
dotnet_diagnostic.IDE2003.severity = warning

# IDE2004: Blank line not allowed after constructor initializer colon
dotnet_diagnostic.IDE2004.severity = warning

[{eng/tools/**.cs,**/{test,testassets,samples,Samples,perf}/**.cs}]
# CA1018: Mark attributes with AttributeUsageAttribute
dotnet_diagnostic.CA1018.severity = suggestion
Expand Down Expand Up @@ -320,6 +337,8 @@ dotnet_diagnostic.IDE0059.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion
# IDE0062: Make local function static
dotnet_diagnostic.IDE0062.severity = suggestion
# IDE2001: Embedded statements must be on their own line
dotnet_diagnostic.IDE2001.severity = suggestion

# CA2016: Forward the 'CancellationToken' parameter to methods that take one
dotnet_diagnostic.CA2016.severity = suggestion
Expand All @@ -339,6 +358,8 @@ dotnet_diagnostic.IDE0060.severity = silent
dotnet_diagnostic.IDE0062.severity = silent
# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = silent
# IDE2001: Embedded statements must be on their own line
dotnet_diagnostic.IDE2001.severity = silent

[{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
# IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included.
Expand Down
1 change: 0 additions & 1 deletion src/Analyzers/Analyzers/src/OptionsAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ operation.Target is IPropertyReferenceOperation property &&
{
options.Add(new OptionsItem(property.Property, operation.Value.ConstantValue.Value));
}

}, OperationKind.SimpleAssignment);

context.RegisterOperationBlockEndAction(context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void TryAddMapping(AzureADSchemeOptions o)
{
JwtBearerScheme = jwtBearerScheme
});
};
}
}

private static Action<AzureADSchemeOptions> TryAddOpenIDCookieSchemeMappings(string scheme, string openIdConnectScheme, string cookieScheme)
Expand Down Expand Up @@ -189,7 +189,7 @@ void TryAddMapping(AzureADSchemeOptions o)
OpenIdConnectScheme = openIdConnectScheme,
CookieScheme = cookieScheme
});
};
}
}

private static void AddAdditionalMvcApplicationParts(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void TryAddMapping(AzureADB2CSchemeOptions o)
{
JwtBearerScheme = jwtBearerScheme
});
};
}
}

private static Action<AzureADB2CSchemeOptions> TryAddOpenIDCookieSchemeMappings(string scheme, string openIdConnectScheme, string cookieScheme)
Expand Down Expand Up @@ -186,7 +186,7 @@ void TryAddMapping(AzureADB2CSchemeOptions o)
OpenIdConnectScheme = openIdConnectScheme,
CookieScheme = cookieScheme
});
};
}
}

private static void AddAdditionalMvcApplicationParts(IServiceCollection services)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Components/src/LayoutView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Render(RenderTreeBuilder builder)
builder.OpenComponent(0, layoutType);
builder.AddAttribute(1, LayoutComponentBase.BodyPropertyName, bodyParam);
builder.CloseComponent();
};
}

return Render;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public CircuitHandle GetCircuitHandle(IDictionary<object, object?> circuitHandle
return (CircuitHandle)circuitHandle;
}

return null; ;
return null;
}

public CircuitHost GetCircuit(IDictionary<object, object?> circuitHandles, object circuitKey)
Expand Down
1 change: 0 additions & 1 deletion src/Components/Shared/src/TransmitDataStreamToJS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ internal static async Task TransmitStreamAsync(IJSRuntime runtime, long streamId
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ private class TestRemoteAuthenticationService : RemoteAuthenticationService<Remo
public TestRemoteAuthenticationService(
IJSRuntime jsRuntime,
IOptionsSnapshot<RemoteAuthenticationOptions<OidcProviderOptions>> options,
TestNavigationManager navigationManager) :
base(jsRuntime, options, navigationManager, new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()))
TestNavigationManager navigationManager)
: base(jsRuntime, options, navigationManager, new AccountClaimsPrincipalFactory<RemoteUserAccount>(Mock.Of<IAccessTokenProviderAccessor>()))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public string? this[string key]
{
provider.Set(key, value);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public WebViewRenderer(
IpcSender ipcSender,
ILoggerFactory loggerFactory,
WebViewJSRuntime jsRuntime,
JSComponentInterop jsComponentInterop) :
base(serviceProvider, loggerFactory, jsRuntime.ReadJsonSerializerOptions(), jsComponentInterop)
JSComponentInterop jsComponentInterop)
: base(serviceProvider, loggerFactory, jsRuntime.ReadJsonSerializerOptions(), jsComponentInterop)
{
_dispatcher = dispatcher;
_ipcSender = ipcSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ private int InsertFrame(RenderBatch batch, ContainerNode parent, int childIndex,
InsertMarkup(parent, childIndex, frame);
return 1;
}

}

throw new Exception($"Unknown frame type: {frame.FrameType}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static WebAssemblyAuthenticationTests()
public WebAssemblyAuthenticationTests(
BrowserFixture browserFixture,
AspNetSiteServerFixture serverFixture,
ITestOutputHelper output) :
base(browserFixture, serverFixture, output)
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
_serverFixture.ApplicationAssembly = typeof(Program).Assembly;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class WebAssemblyConfigurationHostedTest : ServerTestBase<BasicTestAppSer
public WebAssemblyConfigurationHostedTest(
BrowserFixture browserFixture,
BasicTestAppServerSiteFixture<TestServer.ClientStartup> serverFixture,
ITestOutputHelper output) :
base(browserFixture, serverFixture, output)
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class WebAssemblyConfigurationTest : ServerTestBase<BlazorWasmTestAppFixt
public WebAssemblyConfigurationTest(
BrowserFixture browserFixture,
BlazorWasmTestAppFixture<BasicTestApp.Program> serverFixture,
ITestOutputHelper output) :
base(browserFixture, serverFixture, output)
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
_serverFixture.PathBase = "/subdir";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public KeyPerFileConfigurationProvider(KeyPerFileConfigurationSource source)
Load(reload: true);
});
}

}

private string NormalizeKey(string key)
Expand Down Expand Up @@ -98,7 +97,6 @@ private void Load(bool reload)
{
data.Add(NormalizeKey(file.Name), TrimNewLine(streamReader.ReadToEnd()));
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CngCbcAuthenticatedEncryptorFactory(ILoggerFactory loggerFactory)
private BCryptAlgorithmHandle GetHmacAlgorithmHandle(CngCbcAuthenticatedEncryptorConfiguration configuration)
{
// basic argument checking
if (String.IsNullOrEmpty(configuration.HashAlgorithm))
if (string.IsNullOrEmpty(configuration.HashAlgorithm))
{
throw Error.Common_PropertyCannotBeNullOrEmpty(nameof(configuration.HashAlgorithm));
}
Expand All @@ -77,9 +77,13 @@ private BCryptAlgorithmHandle GetHmacAlgorithmHandle(CngCbcAuthenticatedEncrypto
// Special-case cached providers
if (configuration.HashAlgorithmProvider == null)
{
if (configuration.HashAlgorithm == Constants.BCRYPT_SHA1_ALGORITHM) { algorithmHandle = CachedAlgorithmHandles.HMAC_SHA1; }
else if (configuration.HashAlgorithm == Constants.BCRYPT_SHA256_ALGORITHM) { algorithmHandle = CachedAlgorithmHandles.HMAC_SHA256; }
else if (configuration.HashAlgorithm == Constants.BCRYPT_SHA512_ALGORITHM) { algorithmHandle = CachedAlgorithmHandles.HMAC_SHA512; }
algorithmHandle = configuration.HashAlgorithm switch
{
Constants.BCRYPT_SHA1_ALGORITHM => CachedAlgorithmHandles.HMAC_SHA1,
Constants.BCRYPT_SHA256_ALGORITHM => CachedAlgorithmHandles.HMAC_SHA256,
Constants.BCRYPT_SHA512_ALGORITHM => CachedAlgorithmHandles.HMAC_SHA512,
_ => null,
};
}

// Look up the provider dynamically if we couldn't fetch a cached instance
Expand All @@ -100,7 +104,7 @@ private BCryptAlgorithmHandle GetHmacAlgorithmHandle(CngCbcAuthenticatedEncrypto
private BCryptAlgorithmHandle GetSymmetricBlockCipherAlgorithmHandle(CngCbcAuthenticatedEncryptorConfiguration configuration)
{
// basic argument checking
if (String.IsNullOrEmpty(configuration.EncryptionAlgorithm))
if (string.IsNullOrEmpty(configuration.EncryptionAlgorithm))
{
throw Error.Common_PropertyCannotBeNullOrEmpty(nameof(EncryptionAlgorithm));
}
Expand All @@ -116,7 +120,10 @@ private BCryptAlgorithmHandle GetSymmetricBlockCipherAlgorithmHandle(CngCbcAuthe
// Special-case cached providers
if (configuration.EncryptionAlgorithmProvider == null)
{
if (configuration.EncryptionAlgorithm == Constants.BCRYPT_AES_ALGORITHM) { algorithmHandle = CachedAlgorithmHandles.AES_CBC; }
if (configuration.EncryptionAlgorithm == Constants.BCRYPT_AES_ALGORITHM)
{
algorithmHandle = CachedAlgorithmHandles.AES_CBC;
}
}

// Look up the provider dynamically if we couldn't fetch a cached instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ private BCryptAlgorithmHandle GetSymmetricBlockCipherAlgorithmHandle(CngGcmAuthe
// Special-case cached providers
if (configuration.EncryptionAlgorithmProvider == null)
{
if (configuration.EncryptionAlgorithm == Constants.BCRYPT_AES_ALGORITHM) { algorithmHandle = CachedAlgorithmHandles.AES_GCM; }
if (configuration.EncryptionAlgorithm == Constants.BCRYPT_AES_ALGORITHM)
{
algorithmHandle = CachedAlgorithmHandles.AES_GCM;
}
}

// Look up the provider dynamically if we couldn't fetch a cached instance
Expand Down
5 changes: 4 additions & 1 deletion src/DataProtection/DataProtection/src/Secret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ private static SecureLocalAllocHandle Protect(byte* pbPlaintext, uint cbPlaintex
{
numBytesPaddingRequired = 0; // we're already a proper multiple of the block size
}
checked { numTotalBytesToAllocate += numBytesPaddingRequired; }
checked
{
numTotalBytesToAllocate += numBytesPaddingRequired;
}
CryptoUtil.Assert(numTotalBytesToAllocate % CRYPTPROTECTMEMORY_BLOCK_SIZE == 0, "numTotalBytesToAllocate % CRYPTPROTECTMEMORY_BLOCK_SIZE == 0");

// Allocate and copy plaintext data; padding is uninitialized / undefined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,5 @@ public async Task XmlRoundTripsToActualRedisServer()
await redis.GetDatabase().KeyDeleteAsync(key);
}
}

}
}
6 changes: 3 additions & 3 deletions src/Features/JsonPatch/src/Adapters/ObjectAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand All @@ -18,8 +18,8 @@ public class ObjectAdapter : IObjectAdapterWithTest
/// <param name="logErrorAction">The <see cref="Action"/> for logging <see cref="JsonPatchError"/>.</param>
public ObjectAdapter(
IContractResolver contractResolver,
Action<JsonPatchError> logErrorAction) :
this(contractResolver, logErrorAction, Adapters.AdapterFactory.Default)
Action<JsonPatchError> logErrorAction)
: this(contractResolver, logErrorAction, Adapters.AdapterFactory.Default)
{
}

Expand Down
1 change: 0 additions & 1 deletion src/FileProviders/Embedded/test/Manifest/TestEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ public IEnumerable<TestEntry> GetFiles()

return files.Concat(otherFiles).ToArray();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, IInvocationO

return Diagnostic.Create(descriptor, location);
}

}, OperationKind.Invocation);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, Canc
{
return Task.FromResult(HealthCheckResult.Unhealthy("failed", e));
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override string ToString()
if (_cachedToString == null)
{
var request = _request;
_cachedToString = $"{LogPreamble}{request.Protocol} {request.Method} {request.Scheme}://{request.Host.Value}{request.PathBase.Value}{request.Path.Value}{request.QueryString.Value} {EscapedValueOrEmptyMarker(request.ContentType)} {ValueOrEmptyMarker(request.ContentLength)}"; ;
_cachedToString = $"{LogPreamble}{request.Protocol} {request.Method} {request.Scheme}://{request.Host.Value}{request.PathBase.Value}{request.Path.Value}{request.QueryString.Value} {EscapedValueOrEmptyMarker(request.ContentType)} {ValueOrEmptyMarker(request.ContentLength)}";
}

return _cachedToString;
Expand Down
2 changes: 1 addition & 1 deletion src/Hosting/Hosting/src/Internal/StartupLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void InvokeStartup(IServiceCollection serviceCollection)
$"Use a void returning ConfigureServices method instead or a ConfigureContainer method.";
#pragma warning restore CS0612 // Type or member is obsolete
throw new InvalidOperationException(message);
};
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Hosting/TestHost/test/TestServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public void Configure(IApplicationBuilder app)
await context.Response.WriteAsync("ApplicationServicesEqual:" + (applicationServices == Services));
});
}

}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,4 @@ public Task SignOutAsync(AuthenticationProperties? properties)
throw new NotImplementedException();
}
}

}
1 change: 0 additions & 1 deletion src/Http/Authentication.Core/test/TokenExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,4 @@ public Task SignOutAsync(AuthenticationProperties properties)
throw new NotImplementedException();
}
}

}
4 changes: 2 additions & 2 deletions src/Http/Http.Results/src/ConflictObjectResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Microsoft.AspNetCore.Http.Result;

internal sealed class ConflictObjectResult : ObjectResult
{
public ConflictObjectResult(object? error) :
base(error, StatusCodes.Status409Conflict)
public ConflictObjectResult(object? error)
: base(error, StatusCodes.Status409Conflict)
{
}
}
1 change: 0 additions & 1 deletion src/Http/Http.Results/test/FileStreamResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ public void Constructor_SetsLastModifiedAndEtag()
Assert.Equal(entityTag, result.EntityTag);
Assert.Equal(expectedMediaType, result.ContentType);
}

}
1 change: 0 additions & 1 deletion src/Http/Http/test/BindingAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ public void UnixSocketUrlsAreParsedCorrectlyOnWindows(string url, string scheme,

Assert.Equal(toString ?? url, serverAddress.ToString());
}

}
1 change: 0 additions & 1 deletion src/Http/Http/test/DefaultHttpContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ void TestCachedFeaturesAreSet(object value, IFeatureCollection features)
Assert.NotNull(v);
}
}

}

private static void TestFeatureProperties(object value, IFeatureCollection features, IEnumerable<PropertyInfo> properties)
Expand Down
Loading