Code quality updates (#2267)
This commit is contained in:
Родитель
6c8d9a84e4
Коммит
a8363e2c4e
|
@ -22,8 +22,12 @@ indent_size = 2
|
|||
|
||||
# Code style defaults
|
||||
csharp_using_directive_placement = outside_namespace:suggestion
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
|
||||
csharp_preferred_modifier_order.severity = suggestion
|
||||
dotnet_sort_system_directives_first = true
|
||||
dotnet_style_readonly_field = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
||||
|
||||
# License header
|
||||
file_header_template = Copyright (c) Microsoft Corporation.\nLicensed under the MIT License.
|
||||
|
@ -42,9 +46,17 @@ dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
|
|||
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
|
||||
csharp_prefer_simple_default_expression = true:suggestion
|
||||
|
||||
# Pattern matching
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
||||
csharp_style_prefer_not_pattern = true:suggestion
|
||||
csharp_style_prefer_switch_expression = false:none
|
||||
csharp_style_prefer_pattern_matching = false:none
|
||||
|
||||
# Prefer "var" everywhere
|
||||
csharp_style_var_for_built_in_types = true:suggestion
|
||||
csharp_style_var_when_type_is_apparent = true:suggestion
|
||||
csharp_style_inlined_variable_declaration = true:suggestion
|
||||
csharp_style_var_elsewhere = true:suggestion
|
||||
|
||||
# Define the 'private_fields' symbol group:
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace PSRule.Rules.Azure.BuildTool
|
|||
{
|
||||
get
|
||||
{
|
||||
return _Expanded.ZoneMappings == null ? null : _Expanded.ZoneMappings.Select(x => new AvailabilityZoneMappingMin { Location = x.Location, Zones = x.Zones }).ToArray();
|
||||
return _Expanded.ZoneMappings?.Select(x => new AvailabilityZoneMappingMin { Location = x.Location, Zones = x.Zones }).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace PSRule.Rules.Azure.BuildTool
|
||||
{
|
||||
class Program
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Entry point for build tool.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
@ -7,7 +7,7 @@ namespace PSRule.Rules.Azure
|
|||
{
|
||||
internal sealed class EnvironmentHelper
|
||||
{
|
||||
public static readonly EnvironmentHelper Default = new EnvironmentHelper();
|
||||
public static readonly EnvironmentHelper Default = new();
|
||||
|
||||
internal bool TryBool(string key, out bool value)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace PSRule.Rules.Azure
|
|||
return TryVariable(key, out var variable) && TryParseBool(variable, out value);
|
||||
}
|
||||
|
||||
private bool TryVariable(string key, out string variable)
|
||||
private static bool TryVariable(string key, out string variable)
|
||||
{
|
||||
variable = Environment.GetEnvironmentVariable(key);
|
||||
return variable != null;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
{
|
||||
private const string DEFAULT_NAME = "ps-rule-test-deployment";
|
||||
|
||||
internal readonly static DeploymentOption Default = new()
|
||||
internal static readonly DeploymentOption Default = new()
|
||||
{
|
||||
Name = DEFAULT_NAME
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
|
||||
private const string DEFAULT_TYPE = "/providers/Microsoft.Management/managementGroups";
|
||||
|
||||
internal readonly static ManagementGroupOption Default = new()
|
||||
internal static readonly ManagementGroupOption Default = new()
|
||||
{
|
||||
Name = DEFAULT_NAME,
|
||||
Properties = new ManagementGroupProperties(DEFAULT_DISPLAYNAME, DEFAULT_TENANTID),
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = "Not a generic dictionary.")]
|
||||
public sealed class ParameterDefaultsOption : IEquatable<ParameterDefaultsOption>, IDictionary<string, object>
|
||||
{
|
||||
internal readonly static ParameterDefaultsOption Default = new();
|
||||
internal static readonly ParameterDefaultsOption Default = new();
|
||||
|
||||
private readonly Dictionary<string, object> _Defaults;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
private const string ID_PREFIX = "/subscriptions/";
|
||||
private const string RGID_PREFIX = "/resourceGroups/";
|
||||
|
||||
internal readonly static ResourceGroupOption Default = new()
|
||||
internal static readonly ResourceGroupOption Default = new()
|
||||
{
|
||||
SubscriptionId = DEFAULT_SUBSCRIPTIONID,
|
||||
Name = DEFAULT_NAME,
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
|
||||
private const string ID_PREFIX = "/subscriptions/";
|
||||
|
||||
internal readonly static SubscriptionOption Default = new()
|
||||
internal static readonly SubscriptionOption Default = new()
|
||||
{
|
||||
SubscriptionId = DEFAULT_SUBSCRIPTIONID,
|
||||
TenantId = DEFAULT_TENANTID,
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace PSRule.Rules.Azure.Configuration
|
|||
|
||||
private const string ID_PREFIX = "/tenants/";
|
||||
|
||||
internal readonly static TenantOption Default = new()
|
||||
internal static readonly TenantOption Default = new()
|
||||
{
|
||||
CountryCode = DEFAULT_COUNTRYCODE,
|
||||
TenantId = DEFAULT_TENANTID,
|
||||
|
|
|
@ -407,7 +407,7 @@ namespace PSRule.Rules.Azure.Data.Bicep
|
|||
|
||||
try
|
||||
{
|
||||
using (var reader = new JsonTextReader(new StringReader(bicep.GetOutput())))
|
||||
using var reader = new JsonTextReader(new StringReader(bicep.GetOutput()));
|
||||
return JObject.Load(reader);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -132,6 +132,7 @@ namespace PSRule.Rules.Azure.Data.Policy
|
|||
/// Creates an empty condition exception based on an assignment and policy definition.
|
||||
/// </summary>
|
||||
/// <param name="message">The detail of the exception.</param>
|
||||
/// <param name="sourceFile">The source file.</param>
|
||||
/// <param name="assignmentId">Specifies Id of the assignment the exception relates to.</param>
|
||||
/// <param name="policyDefinitionId">Specifies the Id of the policy definition the exception relates to.</param>
|
||||
internal PolicyDefinitionEmptyConditionException(string message, string sourceFile, string assignmentId, string policyDefinitionId)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace PSRule.Rules.Azure.Data
|
|||
/// <summary>
|
||||
/// Create an instance of the resource loader.
|
||||
/// </summary>
|
||||
internal protected ResourceLoader() { }
|
||||
protected internal ResourceLoader() { }
|
||||
|
||||
/// <summary>
|
||||
/// Get the content of a resource stream by name.
|
||||
|
|
|
@ -36,8 +36,8 @@ namespace PSRule.Rules.Azure.Data.Template
|
|||
private const char ParenthesesClose = ')';
|
||||
private const char BracketOpen = '[';
|
||||
private const char BracketClose = ']';
|
||||
private readonly static char[] FunctionNameStopCharacter = new char[] { '(', ']', '[', ')', '\'', ' ', ',' };
|
||||
private readonly static char[] PropertyStopCharacters = new char[] { '(', ']', '[', ',', ')', ' ', '\'', '.', '\r', '\n' };
|
||||
private static readonly char[] FunctionNameStopCharacter = new char[] { '(', ']', '[', ')', '\'', ' ', ',' };
|
||||
private static readonly char[] PropertyStopCharacters = new char[] { '(', ']', '[', ',', ')', ' ', '\'', '.', '\r', '\n' };
|
||||
|
||||
internal ExpressionStream(string expression)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace PSRule.Rules.Azure.Data.Template
|
|||
private const char SINGLE_QUOTE = '\'';
|
||||
private const char DOUBLE_QUOTE = '"';
|
||||
|
||||
internal readonly static IFunctionDescriptor[] Common = new IFunctionDescriptor[]
|
||||
internal static readonly IFunctionDescriptor[] Common = new IFunctionDescriptor[]
|
||||
{
|
||||
// Array and object
|
||||
new FunctionDescriptor("array", Array),
|
||||
|
@ -168,7 +168,7 @@ namespace PSRule.Rules.Azure.Data.Template
|
|||
/// Functions specific to Azure Policy.
|
||||
/// See <seealso href="https://learn.microsoft.com/azure/governance/policy/concepts/definition-structure#policy-functions">Policy Functions</seealso>.
|
||||
/// </summary>
|
||||
internal readonly static IFunctionDescriptor[] Policy = new IFunctionDescriptor[]
|
||||
internal static readonly IFunctionDescriptor[] Policy = new IFunctionDescriptor[]
|
||||
{
|
||||
//new FunctionDescriptor("addDays", AddDays),
|
||||
//new FunctionDescriptor("field", Field),
|
||||
|
|
|
@ -307,7 +307,7 @@ namespace PSRule.Rules.Azure.Data.Template
|
|||
|
||||
public void UpdateResourceScope(JObject resource)
|
||||
{
|
||||
if (!TryResourceScope(resource, out string scopeId) &&
|
||||
if (!TryResourceScope(resource, out var scopeId) &&
|
||||
!TryParentScope(resource, out scopeId))
|
||||
return;
|
||||
|
||||
|
@ -1152,8 +1152,7 @@ namespace PSRule.Rules.Azure.Data.Template
|
|||
continue;
|
||||
|
||||
var r = ResourceInstance(context, instance, copyIndex);
|
||||
if (symbol != null)
|
||||
symbol.Configure(r);
|
||||
symbol?.Configure(r);
|
||||
|
||||
yield return r;
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ namespace PSRule.Rules.Azure.Pipeline.Output
|
|||
|
||||
protected override string Serialize(object[] o)
|
||||
{
|
||||
using (var stringWriter = new StringWriter())
|
||||
{
|
||||
using (var jsonTextWriter = new JsonCommentWriter(stringWriter))
|
||||
{
|
||||
using var stringWriter = new StringWriter();
|
||||
using var jsonTextWriter = new JsonCommentWriter(stringWriter);
|
||||
var jsonSerializer = new JsonSerializer
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
|
@ -32,5 +30,3 @@ namespace PSRule.Rules.Azure.Pipeline.Output
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,20 @@
|
|||
|
||||
namespace PSRule.Rules.Azure.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// A policy assignment source file.
|
||||
/// </summary>
|
||||
public sealed class PolicyAssignmentSource
|
||||
{
|
||||
/// <summary>
|
||||
/// The assignment source file.
|
||||
/// </summary>
|
||||
public string AssignmentFile { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an assignment instance.
|
||||
/// </summary>
|
||||
/// <param name="assignmentFile">The assignment source file.</param>
|
||||
public PolicyAssignmentSource(string assignmentFile)
|
||||
{
|
||||
AssignmentFile = assignmentFile;
|
||||
|
|
Загрузка…
Ссылка в новой задаче