Skip to content
Open
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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[**Rules/**.cs]
csharp_style_expression_bodied_methods = true:error
6 changes: 1 addition & 5 deletions Engine/Generic/ExternalRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public string GetParameter()
return this.param;
}

public SourceType GetSourceType()
{
return SourceType.Module;
}
public SourceType GetSourceType() => SourceType.Module;

public string GetParameterType()
{
Expand All @@ -71,7 +68,6 @@ public string GetFullModulePath()
#endregion

#region Constructors

public ExternalRule()
{

Expand Down
38 changes: 9 additions & 29 deletions Rules/AlignAssignmentStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ var member in enumTypeDefAst.Members.Where(
// Next we need to find the location of the equals sign for this
// member. We know the line it should be on. We can
// search all of the equals signs on that line.
//
//
// Unlike hashtables, we don't have an extent for the LHS and
// RHS of the member. We have the extent of the entire
// member, the name of the member, and the extent of the
Expand Down Expand Up @@ -636,13 +636,12 @@ private List<CorrectionExtent> GetCorrectionExtent(
IScriptExtent lhsExtent,
IScriptExtent equalsExtent,
int targetColumn
)
{
) =>
// We generate a correction extent which replaces the text between
// the end of the lhs and the start of the equals sign with the
// appropriate number of spaces to align the equals sign to the
// target column.
return new List<CorrectionExtent>
new List<CorrectionExtent>
{
new CorrectionExtent(
lhsExtent.EndLineNumber,
Expand All @@ -653,58 +652,39 @@ int targetColumn
string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementError)
)
};
}

/// <summary>
/// Retrieves the common name of this rule.
/// </summary>
public override string GetCommonName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementCommonName);
}
public override string GetCommonName() => string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementCommonName);

/// <summary>
/// Retrieves the description of this rule.
/// </summary>
public override string GetDescription()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementDescription);
}
public override string GetDescription() => string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementDescription);

/// <summary>
/// Retrieves the name of this rule.
/// </summary>
public override string GetName()
{
return string.Format(
public override string GetName() => string.Format(
CultureInfo.CurrentCulture,
Strings.NameSpaceFormat,
GetSourceName(),
Strings.AlignAssignmentStatementName);
}

/// <summary>
/// Retrieves the severity of the rule: error, warning or information.
/// </summary>
public override RuleSeverity GetSeverity()
{
return RuleSeverity.Warning;
}
public override RuleSeverity GetSeverity() => RuleSeverity.Warning;

/// <summary>
/// Retrieves the name of the module/assembly the rule is from.
/// </summary>
public override string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
public override string GetSourceName() => string.Format(CultureInfo.CurrentCulture, Strings.SourceName);

/// <summary>
/// Retrieves the type of the rule, Builtin, Managed or Module.
/// </summary>
public override SourceType GetSourceType()
{
return SourceType.Builtin;
}
public override SourceType GetSourceType() => SourceType.Builtin;
}
}
32 changes: 7 additions & 25 deletions Rules/AvoidAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void SetProperties()
{
return;
}
// Fallback for object from legacy allowlist argument name
// Fallback for object from legacy allowlist argument name
if (obj == null) {
obj = objLegacy;
}
Expand Down Expand Up @@ -237,52 +237,34 @@ private List<CorrectionExtent> GetCorrectionExtent(CommandAst cmdAst, string cmd
/// GetName: Retrieves the name of this rule.
/// </summary>
/// <returns>The name of this rule</returns>
public string GetName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidUsingCmdletAliasesName);
}
public string GetName() => string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidUsingCmdletAliasesName);

/// <summary>
/// GetCommonName: Retrieves the common name of this rule.
/// </summary>
/// <returns>The common name of this rule</returns>
public string GetCommonName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesCommonName);
}
public string GetCommonName() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesCommonName);

/// <summary>
/// GetDescription: Retrieves the description of this rule.
/// </summary>
/// <returns>The description of this rule</returns>
public string GetDescription()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesDescription);
}
public string GetDescription() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesDescription);

/// <summary>
/// GetSourceType: Retrieves the type of the rule, Builtin, Managed or Module.
/// </summary>
public SourceType GetSourceType()
{
return SourceType.Builtin;
}
public SourceType GetSourceType() => SourceType.Builtin;

/// <summary>
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.
/// </summary>
/// <returns></returns>
public RuleSeverity GetSeverity()
{
return RuleSeverity.Warning;
}
public RuleSeverity GetSeverity() => RuleSeverity.Warning;

/// <summary>
/// GetSourceName: Retrieves the name of the module/assembly the rule is from.
/// </summary>
public string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
public string GetSourceName() => string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
}
30 changes: 6 additions & 24 deletions Rules/AvoidAssignmentToAutomaticVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,53 +155,35 @@ private bool IsPowerShellVersion6OrGreater()
/// GetName: Retrieves the name of this rule.
/// </summary>
/// <returns>The name of this rule</returns>
public string GetName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidAssignmentToAutomaticVariableName);
}
public string GetName() => string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidAssignmentToAutomaticVariableName);

/// <summary>
/// GetCommonName: Retrieves the common name of this rule.
/// </summary>
/// <returns>The common name of this rule</returns>
public string GetCommonName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidAssignmentToReadOnlyAutomaticVariableCommonName);
}
public string GetCommonName() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidAssignmentToReadOnlyAutomaticVariableCommonName);

/// <summary>
/// GetDescription: Retrieves the description of this rule.
/// </summary>
/// <returns>The description of this rule</returns>
public string GetDescription()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidAssignmentToReadOnlyAutomaticVariableDescription);
}
public string GetDescription() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidAssignmentToReadOnlyAutomaticVariableDescription);

/// <summary>
/// GetSourceType: Retrieves the type of the rule: builtin, managed or module.
/// </summary>
public SourceType GetSourceType()
{
return SourceType.Builtin;
}
public SourceType GetSourceType() => SourceType.Builtin;

/// <summary>
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.
/// </summary>
/// <returns></returns>
public RuleSeverity GetSeverity()
{
return RuleSeverity.Warning;
}
public RuleSeverity GetSeverity() => RuleSeverity.Warning;

/// <summary>
/// GetSourceName: Retrieves the module/assembly name the rule is from.
/// </summary>
public string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
public string GetSourceName() => string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}

}
32 changes: 7 additions & 25 deletions Rules/AvoidDefaultTrueValueSwitchParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,53 +57,35 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
/// GetName: Retrieves the name of this rule.
/// </summary>
/// <returns>The name of this rule</returns>
public string GetName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidDefaultValueSwitchParameterName);
}
public string GetName() => string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidDefaultValueSwitchParameterName);

/// <summary>
/// GetCommonName: Retrieves the common name of this rule.
/// </summary>
/// <returns>The common name of this rule</returns>
public string GetCommonName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueSwitchParameterCommonName);
}
public string GetCommonName() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueSwitchParameterCommonName);

/// <summary>
/// GetDescription: Retrieves the description of this rule.
/// </summary>
/// <returns>The description of this rule</returns>
public string GetDescription()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueSwitchParameterDescription);
}
public string GetDescription() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueSwitchParameterDescription);

/// <summary>
/// GetSourceType: Retrieves the type of the rule, builtin, managed or module.
/// GetSourceType: Retrieves the type of the rule: builtin, managed or module.
/// </summary>
public SourceType GetSourceType()
{
return SourceType.Builtin;
}
public SourceType GetSourceType() => SourceType.Builtin;

/// <summary>
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.
/// </summary>
/// <returns></returns>
public RuleSeverity GetSeverity()
{
return RuleSeverity.Warning;
}
public RuleSeverity GetSeverity() => RuleSeverity.Warning;

/// <summary>
/// GetSourceName: Retrieves the module/assembly name the rule is from.
/// </summary>
public string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
public string GetSourceName() => string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
}

Expand Down
36 changes: 9 additions & 27 deletions Rules/AvoidDefaultValueForMandatoryParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
/// <param name="paramAst">The parameter AST to examine</param>
/// <param name="comparer">String comparer for case-insensitive attribute name matching</param>
/// <returns>
/// True if the parameter has at least one [Parameter] attribute and ALL of them
/// True if the parameter has at least one [Parameter] attribute and ALL of them
/// have the Mandatory named argument set to true (explicitly or implicitly).
/// False if the parameter has no [Parameter] attributes or if any [Parameter]
/// False if the parameter has no [Parameter] attributes or if any [Parameter]
/// attribute does not have Mandatory=true.
/// </returns>
private static bool HasMandatoryInAllParameterAttributes(ParameterAst paramAst)
Expand All @@ -99,53 +99,35 @@ private static bool HasMandatoryInAllParameterAttributes(ParameterAst paramAst)
/// GetName: Retrieves the name of this rule.
/// </summary>
/// <returns>The name of this rule</returns>
public string GetName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidDefaultValueForMandatoryParameterName);
}
public string GetName() => string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidDefaultValueForMandatoryParameterName);

/// <summary>
/// GetCommonName: Retrieves the common name of this rule.
/// </summary>
/// <returns>The common name of this rule</returns>
public string GetCommonName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueForMandatoryParameterCommonName);
}
public string GetCommonName() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueForMandatoryParameterCommonName);

/// <summary>
/// GetDescription: Retrieves the description of this rule.
/// </summary>
/// <returns>The description of this rule</returns>
public string GetDescription()
{
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueForMandatoryParameterDescription);
}
public string GetDescription() => string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueForMandatoryParameterDescription);

/// <summary>
/// Method: Retrieves the type of the rule: builtin, managed or module.
/// GetSourceType: Retrieves the type of the rule: builtin, managed or module.
/// </summary>
public SourceType GetSourceType()
{
return SourceType.Builtin;
}
public SourceType GetSourceType() => SourceType.Builtin;

/// <summary>
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.
/// </summary>
/// <returns></returns>
public RuleSeverity GetSeverity()
{
return RuleSeverity.Warning;
}
public RuleSeverity GetSeverity() => RuleSeverity.Warning;

/// <summary>
/// Method: Retrieves the module/assembly name the rule is from.
/// </summary>
public string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
public string GetSourceName() => string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
}

Loading