Skip to content

Commit e305f8e

Browse files
committed
Merge pull request #368 from PowerShell/CustomRulePathFixBranch
Bug Fixes when using Recurse functionality. Fix to Binplace cmdlet help file
2 parents 48e2535 + 99e4c5e commit e305f8e

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private void ProcessPathOrScriptDefinition(string pathOrScriptDefinition)
220220

221221
if (String.Equals(this.ParameterSetName, "File", StringComparison.OrdinalIgnoreCase))
222222
{
223-
diagnosticsList = ScriptAnalyzer.Instance.AnalyzePath(pathOrScriptDefinition);
223+
diagnosticsList = ScriptAnalyzer.Instance.AnalyzePath(pathOrScriptDefinition, this.recurse);
224224
}
225225
else if (String.Equals(this.ParameterSetName, "ScriptDefinition", StringComparison.OrdinalIgnoreCase))
226226
{

Engine/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ public static string[] ProcessCustomRulePaths(string rulePath, SessionState sess
10101010
}
10111011
return outPaths.ToArray();
10121012
}
1013-
catch (Exception ex)
1013+
catch
10141014
{
10151015
// need to do this as the path validation takes place later in the hierarchy.
10161016
outPaths.Add(rulePath);

Engine/ScriptAnalyzer.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ private void LoadRules(Dictionary<string, List<string>> result, CommandInvocatio
474474

475475
// Gets external rules.
476476
if (result.ContainsKey("ValidModPaths") && result["ValidModPaths"].Count > 0)
477+
{
477478
ExternalRules = GetExternalRule(result["ValidModPaths"].ToArray());
479+
}
478480
}
479481

480482
internal string[] GetValidModulePaths()
@@ -495,8 +497,12 @@ public IEnumerable<IRule> GetRule(string[] moduleNames, string[] ruleNames)
495497
IEnumerable<IExternalRule> externalRules = null;
496498

497499
// Combines C# rules.
498-
IEnumerable<IRule> rules = ScriptRules.Union<IRule>(TokenRules)
499-
.Union<IRule>(DSCResourceRules);
500+
IEnumerable<IRule> rules = Enumerable.Empty<IRule>();
501+
502+
if (null != ScriptRules)
503+
{
504+
rules = ScriptRules.Union<IRule>(TokenRules).Union<IRule>(DSCResourceRules);
505+
}
500506

501507
// Gets PowerShell Rules.
502508
if (moduleNames != null)
@@ -565,9 +571,17 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
565571
posh.Commands.Clear();
566572

567573
FunctionInfo funcInfo = (FunctionInfo)psobject.ImmediateBaseObject;
568-
ParameterMetadata param = funcInfo.Parameters.Values
569-
.First<ParameterMetadata>(item => item.Name.EndsWith("ast", StringComparison.OrdinalIgnoreCase) ||
570-
item.Name.EndsWith("token", StringComparison.OrdinalIgnoreCase));
574+
ParameterMetadata param = null;
575+
576+
// Ignore any exceptions associated with finding functions that are ScriptAnalyzer rules
577+
try
578+
{
579+
param = funcInfo.Parameters.Values.First<ParameterMetadata>(item => item.Name.EndsWith("ast", StringComparison.OrdinalIgnoreCase) ||
580+
item.Name.EndsWith("token", StringComparison.OrdinalIgnoreCase));
581+
}
582+
catch
583+
{
584+
}
571585

572586
//Only add functions that are defined as rules.
573587
if (param != null)
@@ -746,7 +760,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
746760

747761
if (!string.IsNullOrEmpty(message))
748762
{
749-
diagnostics.Add(new DiagnosticRecord(message, extent, ruleName, severity, null));
763+
diagnostics.Add(new DiagnosticRecord(message, extent, ruleName, severity, filePath));
750764
}
751765
}
752766
}

Engine/ScriptAnalyzerEngine.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ copy /y "$(ProjectDir)\*.ps1xml" "$(SolutionDir)$(SolutionName)"
106106
copy /y "$(ProjectDir)\*.psd1" "$(SolutionDir)$(SolutionName)"
107107
copy /y "$(TargetPath)" "$(SolutionDir)$(SolutionName)"
108108
mkdir "$(SolutionDir)$(SolutionName)\en-US"
109-
copy /y "$(ProjectDir)\about_*.help.txt" "$(SolutionDir)$(SolutionName)\en-US"</PostBuildEvent>
109+
copy /y "$(ProjectDir)\about_*.help.txt" "$(SolutionDir)$(SolutionName)\en-US"
110+
copy /y "$(ProjectDir)\*Help.xml" "$(SolutionDir)$(SolutionName)\en-US"</PostBuildEvent>
110111
</PropertyGroup>
111112
</Project>

0 commit comments

Comments
 (0)