Skip to content

Commit

Permalink
Fix code style to adhere to editorconfig rules
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Sep 12, 2019
1 parent e272ad1 commit 396257f
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 121 deletions.
54 changes: 53 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ csharp_new_line_between_query_expression_clauses = true # vs-default: true
csharp_indent_block_contents = true # vs-default: true
csharp_indent_braces = false # vs-default: false
csharp_indent_case_contents = true # vs-default: true
csharp_indent_case_contents_when_block = true
csharp_indent_switch_labels = true # vs-default: true
csharp_indent_labels = one_less_than_current # vs-default: one_less_than_current

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion # vs-default: false:none
dotnet_style_qualification_for_property = false:suggestion # vs-default: false:none
Expand Down Expand Up @@ -77,16 +81,32 @@ dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# Code style defaults
csharp_using_directive_placement = outside_namespace:suggestion
dotnet_sort_system_directives_first = true # vs-default: true
csharp_prefer_braces = true:refactoring
csharp_preserve_single_line_blocks = true # vs-default: true
csharp_preserve_single_line_statements = false # vs-default: true
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_simple_using_statement = false:none
csharp_style_prefer_switch_expression = true:suggestion

# Code quality
dotnet_style_readonly_field = true:suggestion
dotnet_code_quality_unused_parameters = non_public:suggestion

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion # vs-default: true:suggestion
dotnet_style_collection_initializer = true:suggestion # vs-default: true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion # vs-default: true:suggestion
dotnet_style_coalesce_expression = true:suggestion # vs-default: true:suggestion
dotnet_style_null_propagation = true:suggestion # vs-default: true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring
dotnet_style_prefer_conditional_expression_over_return = true:refactoring
csharp_prefer_simple_default_expression = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = false:none # vs-default: false:none
Expand All @@ -95,6 +115,8 @@ csharp_style_expression_bodied_operators = false:none # vs-default: false:none
csharp_style_expression_bodied_properties = true:none # vs-default: true:none
csharp_style_expression_bodied_indexers = true:none # vs-default: true:none
csharp_style_expression_bodied_accessors = true:none # vs-default: true:none
csharp_style_expression_bodied_lambdas = true:refactoring
csharp_style_expression_bodied_local_functions = true:refactoring

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion # vs-default: true:suggestion
Expand All @@ -105,6 +127,11 @@ csharp_style_inlined_variable_declaration = true:suggestion # vs-default: true:s
csharp_style_throw_expression = true:suggestion # vs-default: true:suggestion
csharp_style_conditional_delegate_call = true:suggestion # vs-default: true:suggestion

# Other features
csharp_style_prefer_index_operator = false:none
csharp_style_prefer_range_operator = false:none
csharp_style_pattern_local_over_anonymous_function = false:none

# Space preferences
csharp_space_after_cast = false # vs-default: false
csharp_space_after_colon_in_inheritance_clause = true # vs-default: true
Expand All @@ -130,4 +157,29 @@ csharp_space_between_parentheses = false # vs-default: false
csharp_space_between_square_brackets = false # vs-default: false

# Require accessibility modifiers
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion # vs-default: for_non_interface_members:none
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion # vs-default: for_non_interface_members:none

# Analyzers
dotnet_code_quality.ca1802.api_surface = private, internal

# Xml project files
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
indent_size = 2

# Xml build files
[*.builds]
indent_size = 2

# Xml files
[*.{xml,stylecop,resx,ruleset}]
indent_size = 2

# Xml config files
[*.{props,targets,config,nuspec}]
indent_size = 2

# Shell scripts
[*.sh]
end_of_line = lf
[*.{cmd, bat}]
end_of_line = crlf
15 changes: 5 additions & 10 deletions sdk/core/Azure.Core/src/Shared/NullableAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace System.Diagnostics.CodeAnalysis
#else
public
#endif
sealed class AllowNullAttribute : Attribute
{ }
sealed class AllowNullAttribute : Attribute { }

/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
Expand All @@ -22,8 +21,7 @@ sealed class AllowNullAttribute : Attribute
#else
public
#endif
sealed class DisallowNullAttribute : Attribute
{ }
sealed class DisallowNullAttribute : Attribute { }

/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
Expand All @@ -32,8 +30,7 @@ sealed class DisallowNullAttribute : Attribute
#else
public
#endif
sealed class MaybeNullAttribute : Attribute
{ }
sealed class MaybeNullAttribute : Attribute { }

/// <summary>Specifies that an output will not be null even if the corresponding type allows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
Expand All @@ -42,8 +39,7 @@ sealed class MaybeNullAttribute : Attribute
#else
public
#endif
sealed class NotNullAttribute : Attribute
{ }
sealed class NotNullAttribute : Attribute { }

/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
Expand Down Expand Up @@ -109,8 +105,7 @@ sealed class NotNullIfNotNullAttribute : Attribute
#else
public
#endif
sealed class DoesNotReturnAttribute : Attribute
{ }
sealed class DoesNotReturnAttribute : Attribute { }

/// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
Expand Down
10 changes: 5 additions & 5 deletions sdk/identity/Azure.Identity/src/AadIdentityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Azure.Identity
{
internal class AadIdentityClient
{
private static Lazy<AadIdentityClient> s_sharedClient = new Lazy<AadIdentityClient>(() => new AadIdentityClient(null));
private static readonly Lazy<AadIdentityClient> s_sharedClient = new Lazy<AadIdentityClient>(() => new AadIdentityClient(null));

private readonly IdentityClientOptions _options;
private readonly HttpPipeline _pipeline;
Expand Down Expand Up @@ -142,11 +142,11 @@ public virtual AccessToken Authenticate(string tenantId, string clientId, X509Ce

private async Task<AccessToken> SendAuthRequestAsync(Request request, CancellationToken cancellationToken)
{
var response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

if (response.Status == 200 || response.Status == 201)
{
var result = await DeserializeAsync(response.ContentStream, cancellationToken).ConfigureAwait(false);
AccessToken result = await DeserializeAsync(response.ContentStream, cancellationToken).ConfigureAwait(false);

return new Response<AccessToken>(response, result);
}
Expand All @@ -156,11 +156,11 @@ private async Task<AccessToken> SendAuthRequestAsync(Request request, Cancellati

private AccessToken SendAuthRequest(Request request, CancellationToken cancellationToken)
{
var response = _pipeline.SendRequest(request, cancellationToken);
Response response = _pipeline.SendRequest(request, cancellationToken);

if (response.Status == 200 || response.Status == 201)
{
var result = Deserialize(response.ContentStream);
AccessToken result = Deserialize(response.ContentStream);

return new Response<AccessToken>(response, result);
}
Expand Down
6 changes: 5 additions & 1 deletion sdk/identity/Azure.Identity/src/ChainedTokenCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Azure.Identity
/// </summary>
public class ChainedTokenCredential : TokenCredential
{
private TokenCredential[] _sources;
private readonly TokenCredential[] _sources;

/// <summary>
/// Creates an instance with the specified <see cref="TokenCredential"/> sources.
Expand All @@ -24,10 +24,14 @@ public class ChainedTokenCredential : TokenCredential
public ChainedTokenCredential(params TokenCredential[] sources)
{
if (sources == null)
{
throw new ArgumentNullException(nameof(sources));
}

if (sources.Length == 0)
{
throw new ArgumentException("sources must not be empty", nameof(sources));
}

for (int i = 0; i < sources.Length; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/Azure.Identity/src/ClientSecretCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ClientSecretCredential(string tenantId, string clientId, string clientSec
/// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns>
public override async Task<AccessToken> GetTokenAsync(string[] scopes, CancellationToken cancellationToken = default)
{
return await this._client.AuthenticateAsync(TenantId, ClientId, ClientSecret, scopes, cancellationToken).ConfigureAwait(false);
return await _client.AuthenticateAsync(TenantId, ClientId, ClientSecret, scopes, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -78,7 +78,7 @@ public override async Task<AccessToken> GetTokenAsync(string[] scopes, Cancellat
/// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns>
public override AccessToken GetToken(string[] scopes, CancellationToken cancellationToken = default)
{
return this._client.Authenticate(TenantId, ClientId, ClientSecret, scopes, cancellationToken);
return _client.Authenticate(TenantId, ClientId, ClientSecret, scopes, cancellationToken);
}
}
}
10 changes: 5 additions & 5 deletions sdk/identity/Azure.Identity/src/DefaultAzureCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class DefaultAzureCredential : ChainedTokenCredential
{
// TODO: Currently this is piggybacking off the Azure CLI client ID, but needs to be switched once the Developer Sign On application is available
private const string DeveloperSignOnClientId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46";
private static readonly string AzureUsername = Environment.GetEnvironmentVariable("AZURE_USERNAME");
private static readonly string AzurePassword = Environment.GetEnvironmentVariable("AZURE_PASSWORD");
private static TokenCredential[] s_defaultCredentialChain = GetDefaultAzureCredentialChain();
private static readonly string s_azureUsername = Environment.GetEnvironmentVariable("AZURE_USERNAME");
private static readonly string s_azurePassword = Environment.GetEnvironmentVariable("AZURE_PASSWORD");
private static readonly TokenCredential[] s_defaultCredentialChain = GetDefaultAzureCredentialChain();

/// <summary>
/// Creates an instance of the DefaultAzureCredential class.
Expand All @@ -37,12 +37,12 @@ private static TokenCredential[] GetDefaultAzureCredentialChain()
{
// if only the username is specified via the enviornment (not password as well) and we're running on windows add the SharedTokenCacheCredential to the
// default credential to enable SSO
if (!string.IsNullOrEmpty(AzureUsername) && string.IsNullOrEmpty(AzurePassword) && (Environment.OSVersion.Platform == PlatformID.Win32NT))
if (!string.IsNullOrEmpty(s_azureUsername) && string.IsNullOrEmpty(s_azurePassword) && (Environment.OSVersion.Platform == PlatformID.Win32NT))
{
return new TokenCredential[] {
new EnvironmentCredential(),
new ManagedIdentityCredential(),
new SharedTokenCacheCredential(DeveloperSignOnClientId, AzureUsername),
new SharedTokenCacheCredential(DeveloperSignOnClientId, s_azureUsername),
new CredentialNotFoundGuard()
};
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/identity/Azure.Identity/src/DeviceCodeCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ namespace Azure.Identity
/// </summary>
public class DeviceCodeCredential : TokenCredential
{
private IPublicClientApplication _pubApp = null;
private HttpPipeline _pipeline = null;
private readonly IPublicClientApplication _pubApp = null;
private readonly HttpPipeline _pipeline = null;
private IAccount _account = null;
private IdentityClientOptions _options;
private string _clientId;
private Func<DeviceCodeInfo, CancellationToken, Task> _deviceCodeCallback;
private readonly IdentityClientOptions _options;
private readonly string _clientId;
private readonly Func<DeviceCodeInfo, CancellationToken, Task> _deviceCodeCallback;

/// <summary>
/// Protected constructor for mocking
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/Azure.Identity/src/EnvironmentCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Azure.Identity
/// </summary>
public class EnvironmentCredential : TokenCredential
{
private TokenCredential _credential = null;
private readonly TokenCredential _credential = null;

/// <summary>
/// Creates an instance of the EnvironmentCredential class and reads client secret details from environment variables.
Expand Down Expand Up @@ -73,7 +73,7 @@ public override AccessToken GetToken(string[] scopes, CancellationToken cancella
/// <param name="scopes">The list of scopes for which the token will have access.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls, or a default <see cref="AccessToken"/>.</returns>
public async override Task<AccessToken> GetTokenAsync(string[] scopes, CancellationToken cancellationToken = default)
public override async Task<AccessToken> GetTokenAsync(string[] scopes, CancellationToken cancellationToken = default)
{
return (_credential != null) ? await _credential.GetTokenAsync(scopes, cancellationToken).ConfigureAwait(false) : default;
}
Expand Down
13 changes: 7 additions & 6 deletions sdk/identity/Azure.Identity/src/HttpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task<Request> ToPipelineRequestAsync(this HttpRequestMessage

pipelineRequest.Content = await request.Content.ToPipelineRequestContentAsync().ConfigureAwait(false);

foreach (var header in request.Headers)
foreach (System.Collections.Generic.KeyValuePair<string, System.Collections.Generic.IEnumerable<string>> header in request.Headers)
{
foreach (var value in header.Value)
{
Expand All @@ -47,13 +47,14 @@ private static void AddHeader(HttpResponseMessage request, HttpHeader header)

public static HttpResponseMessage ToHttpResponseMessage(this Response response)
{
HttpResponseMessage responseMessage = new HttpResponseMessage();

responseMessage.StatusCode = (HttpStatusCode)response.Status;
HttpResponseMessage responseMessage = new HttpResponseMessage
{
StatusCode = (HttpStatusCode)response.Status,

responseMessage.Content = new StreamContent(response.ContentStream);
Content = new StreamContent(response.ContentStream)
};

foreach (var header in response.Headers)
foreach (HttpHeader header in response.Headers)
{
if (!responseMessage.Headers.TryAddWithoutValidation(header.Name, header.Value))
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/Azure.Identity/src/HttpPipelineClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Azure.Identity
/// </summary>
internal class HttpPipelineClientFactory : IMsalHttpClientFactory
{
private HttpPipeline _pipeline;
private readonly HttpPipeline _pipeline;

public HttpPipelineClientFactory(HttpPipeline pipeline)
{
Expand All @@ -33,7 +33,7 @@ public HttpClient GetHttpClient()
/// </summary>
private class PipelineHttpMessageHandler : HttpMessageHandler
{
private HttpPipeline _pipeline;
private readonly HttpPipeline _pipeline;

public PipelineHttpMessageHandler(HttpPipeline pipeline)
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/Azure.Identity/src/IdentityClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Azure.Identity
/// </summary>
public class IdentityClientOptions : ClientOptions
{
private static readonly Uri DefaultAuthorityHost = new Uri("https://login.microsoftonline.com/");
private static readonly Uri s_defaultAuthorityHost = new Uri("https://login.microsoftonline.com/");

/// <summary>
/// The host of the Azure Active Directory authority. The default is https://login.microsoft.com
Expand All @@ -23,7 +23,7 @@ public class IdentityClientOptions : ClientOptions
/// </summary>
public IdentityClientOptions()
{
AuthorityHost = DefaultAuthorityHost;
AuthorityHost = s_defaultAuthorityHost;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace Azure.Identity
/// </summary>
public class InteractiveBrowserCredential : TokenCredential
{
private IPublicClientApplication _pubApp = null;
private readonly IPublicClientApplication _pubApp = null;
private IAccount _account = null;
private IdentityClientOptions _options;
private string _clientId;
private readonly IdentityClientOptions _options;
private readonly string _clientId;

/// <summary>
/// Creates a new InteractiveBrowserCredential which will authenticate users with the specified application.
Expand All @@ -44,7 +44,7 @@ public InteractiveBrowserCredential(string clientId, IdentityClientOptions optio

_options = options ??= new IdentityClientOptions();

var pipeline = HttpPipelineBuilder.Build(_options);
HttpPipeline pipeline = HttpPipelineBuilder.Build(_options);

_pubApp = PublicClientApplicationBuilder.Create(_clientId).WithHttpClientFactory(new HttpPipelineClientFactory(pipeline)).WithRedirectUri("http://localhost").Build();
}
Expand Down
Loading

0 comments on commit 396257f

Please sign in to comment.