diff --git a/Rules/AvoidUninitializedVariable.cs b/DeprecatedRules/AvoidUninitializedVariable.cs
similarity index 100%
rename from Rules/AvoidUninitializedVariable.cs
rename to DeprecatedRules/AvoidUninitializedVariable.cs
diff --git a/Engine/Helper.cs b/Engine/Helper.cs
index 89a33b354..3a09d2c56 100644
--- a/Engine/Helper.cs
+++ b/Engine/Helper.cs
@@ -224,6 +224,17 @@ public bool IsDscResourceModule(string filePath)
return false;
}
+ ///
+ /// Given a filePath. Returns true if it is a powershell help file
+ ///
+ ///
+ ///
+ public bool IsHelpFile(string filePath)
+ {
+ return filePath != null && File.Exists(filePath) && Path.GetFileName(filePath).StartsWith("about_", StringComparison.OrdinalIgnoreCase)
+ && Path.GetFileName(filePath).EndsWith(".help.txt", StringComparison.OrdinalIgnoreCase);
+ }
+
///
/// Given an AST, checks whether dsc resource is class based or not
///
diff --git a/Engine/ScriptAnalyzer.cs b/Engine/ScriptAnalyzer.cs
index 55b11ebb1..e3cdf8cc7 100644
--- a/Engine/ScriptAnalyzer.cs
+++ b/Engine/ScriptAnalyzer.cs
@@ -908,9 +908,9 @@ private void BuildScriptPathList(
bool searchRecursively,
IList scriptFilePaths)
{
- const string ps1Suffix = "ps1";
- const string psm1Suffix = "psm1";
- const string psd1Suffix = "psd1";
+ const string ps1Suffix = ".ps1";
+ const string psm1Suffix = ".psm1";
+ const string psd1Suffix = ".psd1";
if (Directory.Exists(path))
{
@@ -935,9 +935,14 @@ private void BuildScriptPathList(
}
else if (File.Exists(path))
{
- if ((path.Length > ps1Suffix.Length && path.Substring(path.Length - ps1Suffix.Length).Equals(ps1Suffix, StringComparison.OrdinalIgnoreCase)) ||
- (path.Length > psm1Suffix.Length && path.Substring(path.Length - psm1Suffix.Length).Equals(psm1Suffix, StringComparison.OrdinalIgnoreCase)) ||
- (path.Length > psd1Suffix.Length && path.Substring(path.Length - psd1Suffix.Length).Equals(psd1Suffix, StringComparison.OrdinalIgnoreCase)))
+ String fileName = Path.GetFileName(path);
+ if ((fileName.Length > ps1Suffix.Length && String.Equals(Path.GetExtension(path), ps1Suffix, StringComparison.OrdinalIgnoreCase)) ||
+ (fileName.Length > psm1Suffix.Length && String.Equals(Path.GetExtension(path), psm1Suffix, StringComparison.OrdinalIgnoreCase)) ||
+ (fileName.Length > psd1Suffix.Length && String.Equals(Path.GetExtension(path), psd1Suffix, StringComparison.OrdinalIgnoreCase)))
+ {
+ scriptFilePaths.Add(path);
+ }
+ else if (Helper.Instance.IsHelpFile(path))
{
scriptFilePaths.Add(path);
}
@@ -964,7 +969,28 @@ private IEnumerable AnalyzeFile(string filePath)
//Parse the file
if (File.Exists(filePath))
{
- scriptAst = Parser.ParseFile(filePath, out scriptTokens, out errors);
+ // processing for non help script
+ if (!(Path.GetFileName(filePath).StartsWith("about_") && Path.GetFileName(filePath).EndsWith(".help.txt")))
+ {
+ scriptAst = Parser.ParseFile(filePath, out scriptTokens, out errors);
+
+ if (errors != null && errors.Length > 0)
+ {
+ foreach (ParseError error in errors)
+ {
+ string parseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorFormat, error.Extent.File, error.Message.TrimEnd('.'), error.Extent.StartLineNumber, error.Extent.StartColumnNumber);
+ this.outputWriter.WriteError(new ErrorRecord(new ParseException(parseErrorMessage), parseErrorMessage, ErrorCategory.ParserError, error.ErrorId));
+ }
+ }
+
+ if (errors.Length > 10)
+ {
+ string manyParseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorMessage, System.IO.Path.GetFileName(filePath));
+ this.outputWriter.WriteError(new ErrorRecord(new ParseException(manyParseErrorMessage), manyParseErrorMessage, ErrorCategory.ParserError, filePath));
+
+ return new List();
+ }
+ }
}
else
{
@@ -975,23 +1001,6 @@ private IEnumerable AnalyzeFile(string filePath)
return null;
}
- if (errors != null && errors.Length > 0)
- {
- foreach (ParseError error in errors)
- {
- string parseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorFormat, error.Extent.File, error.Message.TrimEnd('.'), error.Extent.StartLineNumber, error.Extent.StartColumnNumber);
- this.outputWriter.WriteError(new ErrorRecord(new ParseException(parseErrorMessage), parseErrorMessage, ErrorCategory.ParserError, error.ErrorId));
- }
- }
-
- if (errors.Length > 10)
- {
- string manyParseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorMessage, System.IO.Path.GetFileName(filePath));
- this.outputWriter.WriteError(new ErrorRecord(new ParseException(manyParseErrorMessage), manyParseErrorMessage, ErrorCategory.ParserError, filePath));
-
- return new List();
- }
-
return this.AnalyzeSyntaxTree(scriptAst, scriptTokens, filePath);
}
@@ -1007,7 +1016,7 @@ public IEnumerable AnalyzeSyntaxTree(
Token[] scriptTokens,
string filePath)
{
- Dictionary> ruleSuppressions;
+ Dictionary> ruleSuppressions = new Dictionary>();
ConcurrentBag diagnostics = new ConcurrentBag();
ConcurrentBag suppressed = new ConcurrentBag();
BlockingCollection> verboseOrErrors = new BlockingCollection>();
@@ -1015,28 +1024,33 @@ public IEnumerable AnalyzeSyntaxTree(
// Use a List of KVP rather than dictionary, since for a script containing inline functions with same signature, keys clash
List> cmdInfoTable = new List>();
- ruleSuppressions = Helper.Instance.GetRuleSuppression(scriptAst);
+ bool helpFile = (scriptAst == null) && Helper.Instance.IsHelpFile(filePath);
- foreach (List ruleSuppressionsList in ruleSuppressions.Values)
+ if (!helpFile)
{
- foreach (RuleSuppression ruleSuppression in ruleSuppressionsList)
+ ruleSuppressions = Helper.Instance.GetRuleSuppression(scriptAst);
+
+ foreach (List ruleSuppressionsList in ruleSuppressions.Values)
{
- if (!String.IsNullOrWhiteSpace(ruleSuppression.Error))
+ foreach (RuleSuppression ruleSuppression in ruleSuppressionsList)
{
- this.outputWriter.WriteError(new ErrorRecord(new ArgumentException(ruleSuppression.Error), ruleSuppression.Error, ErrorCategory.InvalidArgument, ruleSuppression));
+ if (!String.IsNullOrWhiteSpace(ruleSuppression.Error))
+ {
+ this.outputWriter.WriteError(new ErrorRecord(new ArgumentException(ruleSuppression.Error), ruleSuppression.Error, ErrorCategory.InvalidArgument, ruleSuppression));
+ }
}
}
- }
- #region Run VariableAnalysis
- try
- {
- Helper.Instance.InitializeVariableAnalysis(scriptAst);
- }
- catch { }
- #endregion
+ #region Run VariableAnalysis
+ try
+ {
+ Helper.Instance.InitializeVariableAnalysis(scriptAst);
+ }
+ catch { }
+ #endregion
- Helper.Instance.Tokens = scriptTokens;
+ Helper.Instance.Tokens = scriptTokens;
+ }
#region Run ScriptRules
//Trim down to the leaf element of the filePath and pass it to Diagnostic Record
@@ -1067,6 +1081,8 @@ public IEnumerable AnalyzeSyntaxTree(
}
}
+ bool helpRule = String.Equals(scriptRule.GetName(), "PSUseUTF8EncodingForHelpFile", StringComparison.OrdinalIgnoreCase);
+
if ((includeRule == null || includeRegexMatch) && (excludeRule == null || !excludeRegexMatch))
{
List