Skip to content

Take latest Master to Development #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
06ac3ce
Merge pull request #169 from PowerShell/master
yutingc May 15, 2015
9f2564c
Added Build status for BugFixes and Development branches
raghushantha May 15, 2015
506da93
Update README.md
raghushantha May 15, 2015
f1b8484
Update README.md
raghushantha May 15, 2015
368309d
Merge pull request #172 from PowerShell/BuildStatusBranch
raghushantha May 15, 2015
13ce922
Optimize DSC interface invocations - Class interface is only called f…
raghushantha May 18, 2015
cfbeb7b
Fixed parameter name in the comment section of the helper method
raghushantha May 18, 2015
f7e7e47
Merge pull request #178 from PowerShell/DSCClassResourceEngineFixBranch
raghushantha May 19, 2015
f4ff1ae
Add checks for XPath for AvoidUsingInternalURL
yutingc May 19, 2015
1d4f3f6
Add more checks for any methods that take XPathExpression
yutingc May 19, 2015
32e2f61
Fix avoiduninitializedvariable not recognizing switchparameter
May 19, 2015
55db24f
Change to only check one ParentAst
yutingc May 19, 2015
c29d7fb
Merge pull request #183 from PowerShell/SwitchParameterUninitialized
May 19, 2015
f29e0fc
Change severity level to information
yutingc May 19, 2015
fe6d977
Update the tests
yutingc May 19, 2015
301fa8a
Merge branch 'XPath' into BugFixes
yutingc May 19, 2015
d15e701
Merge branch 'BugFixes' of https://github.com/PowerShell/PSScriptAnal…
yutingc May 19, 2015
f6ba095
Update GetScriptAnalyzerRule.tests.ps1
yutingc May 19, 2015
2849549
Merge pull request #186 from PowerShell/development
yutingc May 19, 2015
221933f
Merge pull request #185 from PowerShell/BugFixes
yutingc May 19, 2015
2bc754d
Rename License.txt to LICENSE.md
raghushantha May 20, 2015
5f677e9
Rename LICENSE.md to LICENSE
raghushantha May 20, 2015
1e78842
Add check for builtin variables for GlobalVar rule
yutingc May 21, 2015
7a1215a
Modify the comment
yutingc May 21, 2015
98e8d3a
Merge pull request #191 from PowerShell/FixGlobalVars
yutingc May 22, 2015
6c9b9cf
Fix AvoidUsingPlainTextForPassword raised for types other than string…
May 23, 2015
1b15e84
Fix UseDeclaredVarsMoreThanAssignment not recognizing script variables
May 23, 2015
4c45a16
Fix UseDeclaredVarsMoreThanAssignments being raised for setting prope…
May 23, 2015
ba547fc
Merge pull request #205 from PowerShell/FixUseDeclaredVarsMoreThanAss…
May 26, 2015
d69fe7f
Merge pull request #204 from PowerShell/FixAvoidUsingPlainTextForPass…
May 26, 2015
ef0db7f
Add check for both IsPlural and IsSingular for nouns
yutingc May 26, 2015
36cb31f
Merge pull request #220 from PowerShell/SingularNouns
yutingc May 26, 2015
1e2be1e
Update ScriptRuleDocumentation.md
yutingc May 26, 2015
0bb0143
Update Powershell to PowerShell
yutingc May 26, 2015
f6f07e9
More changes to Powershell namespace
yutingc May 26, 2015
2aaa17e
Move tests of TrapStatement to DisabledRules folder
yutingc May 26, 2015
b10fb39
Merge pull request #221 from PowerShell/NameSpaceChanges
yutingc May 27, 2015
8a71a97
Fix parameters missing in a conditional statement of the rule
May 29, 2015
5a58464
Add test
May 29, 2015
962246d
Merge pull request #226 from PowerShell/FixAvoidUsingPlainTextForPass…
May 29, 2015
785e4b8
Merge branch 'BugFixes'
yutingc May 29, 2015
46fcb59
Merge branch 'master' of https://github.com/PowerShell/PSScriptAnalyzer
yutingc May 29, 2015
24d4515
Fix a bug in the flow graphs for throw statements
May 29, 2015
be47a8e
Merge pull request #227 from PowerShell/FixAvoidUninitializedVariable…
May 29, 2015
8b973b9
Simplifies logic of suppressing rule and fix a bug where rule suppres…
May 29, 2015
11507fc
Merge pull request #231 from PowerShell/FixRuleSuppressionErrorsForMo…
May 29, 2015
c4ae0a5
Merge pull request #229 from PowerShell/BugFixes
raghushantha Jun 1, 2015
76200c9
Fix for failing RuleSuppressionID tests
raghushantha Jun 2, 2015
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
5 changes: 2 additions & 3 deletions Engine/Commands/GetScriptAnalyzerRuleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
// THE SOFTWARE.
//

using Microsoft.PowerShell.Commands;
using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Management.Automation;
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Commands
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
{
/// <summary>
/// GetScriptAnalyzerRuleCommand: Cmdlet to list all the analyzer rule names and descriptions.
Expand Down
103 changes: 51 additions & 52 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
//

using System.Text.RegularExpressions;
using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Language;
using System.Resources;
using System.Threading;
using System.Reflection;
using System.IO;
using System.Text;
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Commands
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
{
/// <summary>
/// InvokeScriptAnalyzerCommand: Cmdlet to statically check PowerShell scripts.
Expand Down Expand Up @@ -129,8 +124,8 @@ public SwitchParameter SuppressedOnly
#region Private Members

Dictionary<string, List<string>> validationResults = new Dictionary<string, List<string>>();
private ScriptBlockAst ast = null;
private IEnumerable<IRule> rules = null;
private ScriptBlockAst ast = null;
private IEnumerable<IRule> rules = null;

#endregion

Expand Down Expand Up @@ -163,9 +158,9 @@ protected override void BeginProcessing()
}
else
{
validationResults.Add("InvalidPaths", new List<string>());
validationResults.Add("InvalidPaths", new List<string>());
validationResults.Add("ValidModPaths", new List<string>());
validationResults.Add("ValidDllPaths", new List<string>());
validationResults.Add("ValidDllPaths", new List<string>());
}

#endregion
Expand All @@ -174,7 +169,7 @@ protected override void BeginProcessing()

try
{
if (validationResults["ValidDllPaths"].Count == 0 &&
if (validationResults["ValidDllPaths"].Count == 0 &&
validationResults["ValidModPaths"].Count == 0)
{
ScriptAnalyzer.Instance.Initialize();
Expand All @@ -185,7 +180,7 @@ protected override void BeginProcessing()
}
}
catch (Exception ex)
{
{
ThrowTerminatingError(new ErrorRecord(ex, ex.HResult.ToString("X", CultureInfo.CurrentCulture),
ErrorCategory.NotSpecified, this));
}
Expand Down Expand Up @@ -228,8 +223,8 @@ private void ProcessPath(string path)

if (path == null)
{
ThrowTerminatingError(new ErrorRecord(new FileNotFoundException(),
string.Format(CultureInfo.CurrentCulture, Strings.FileNotFound, path),
ThrowTerminatingError(new ErrorRecord(new FileNotFoundException(),
string.Format(CultureInfo.CurrentCulture, Strings.FileNotFound, path),
ErrorCategory.InvalidArgument, this));
}

Expand Down Expand Up @@ -315,11 +310,11 @@ private void AnalyzeFile(string filePath)
else
{
ThrowTerminatingError(new ErrorRecord(new FileNotFoundException(),
string.Format(CultureInfo.CurrentCulture, Strings.InvalidPath, filePath),
string.Format(CultureInfo.CurrentCulture, Strings.InvalidPath, filePath),
ErrorCategory.InvalidArgument, filePath));
}

if (errors != null && errors.Length > 0)
if (errors != null && errors.Length > 0)
{
foreach (ParseError error in errors)
{
Expand Down Expand Up @@ -362,7 +357,7 @@ private void AnalyzeFile(string filePath)
#region Run ScriptRules
//Trim down to the leaf element of the filePath and pass it to Diagnostic Record
string fileName = System.IO.Path.GetFileName(filePath);

if (ScriptAnalyzer.Instance.ScriptRules != null)
{
foreach (IScriptRule scriptRule in ScriptAnalyzer.Instance.ScriptRules)
Expand Down Expand Up @@ -433,7 +428,7 @@ private void AnalyzeFile(string filePath)
break;
}
}
if ((includeRule == null || includeRegexMatch) && (excludeRule == null || !excludeRegexMatch))
if ((includeRule == null || includeRegexMatch) && (excludeRule == null || !excludeRegexMatch))
{
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, tokenRule.GetName()));

Expand All @@ -448,7 +443,7 @@ private void AnalyzeFile(string filePath)
catch (Exception tokenRuleException)
{
WriteError(new ErrorRecord(tokenRuleException, Strings.RuleErrorMessage, ErrorCategory.InvalidOperation, fileName));
}
}
}
}
}
Expand All @@ -458,46 +453,50 @@ private void AnalyzeFile(string filePath)
#region DSC Resource Rules
if (ScriptAnalyzer.Instance.DSCResourceRules != null)
{
// Run DSC Class rule
foreach (IDSCResourceRule dscResourceRule in ScriptAnalyzer.Instance.DSCResourceRules)
// Invoke AnalyzeDSCClass only if the ast is a class based resource
if (Helper.Instance.IsDscResourceClassBased(ast))
{
bool includeRegexMatch = false;
bool excludeRegexMatch = false;

foreach (Regex include in includeRegexList)
// Run DSC Class rule
foreach (IDSCResourceRule dscResourceRule in ScriptAnalyzer.Instance.DSCResourceRules)
{
if (include.IsMatch(dscResourceRule.GetName()))
bool includeRegexMatch = false;
bool excludeRegexMatch = false;

foreach (Regex include in includeRegexList)
{
includeRegexMatch = true;
break;
if (include.IsMatch(dscResourceRule.GetName()))
{
includeRegexMatch = true;
break;
}
}
}

foreach (Regex exclude in excludeRegexList)
{
if (exclude.IsMatch(dscResourceRule.GetName()))
foreach (Regex exclude in excludeRegexList)
{
excludeRegexMatch = true;
break;
if (exclude.IsMatch(dscResourceRule.GetName()))
{
excludeRegexMatch = true;
break;
}
}
}

if ((includeRule == null || includeRegexMatch) && (excludeRule == null || excludeRegexMatch))
{
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, dscResourceRule.GetName()));

// Ensure that any unhandled errors from Rules are converted to non-terminating errors
// We want the Engine to continue functioning even if one or more Rules throws an exception
try
if ((includeRule == null || includeRegexMatch) && (excludeRule == null || excludeRegexMatch))
{
var records = Helper.Instance.SuppressRule(dscResourceRule.GetName(), ruleSuppressions, dscResourceRule.AnalyzeDSCClass(ast, filePath).ToList());
diagnostics.AddRange(records.Item2);
suppressed.AddRange(records.Item1);
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, dscResourceRule.GetName()));

// Ensure that any unhandled errors from Rules are converted to non-terminating errors
// We want the Engine to continue functioning even if one or more Rules throws an exception
try
{
var records = Helper.Instance.SuppressRule(dscResourceRule.GetName(), ruleSuppressions, dscResourceRule.AnalyzeDSCClass(ast, filePath).ToList());
diagnostics.AddRange(records.Item2);
suppressed.AddRange(records.Item1);
}
catch (Exception dscResourceRuleException)
{
WriteError(new ErrorRecord(dscResourceRuleException, Strings.RuleErrorMessage, ErrorCategory.InvalidOperation, filePath));
}
}
catch (Exception dscResourceRuleException)
{
WriteError(new ErrorRecord(dscResourceRuleException, Strings.RuleErrorMessage, ErrorCategory.InvalidOperation, filePath));
}
}
}

Expand Down Expand Up @@ -543,7 +542,7 @@ private void AnalyzeFile(string filePath)
}
}

}
}
}
#endregion

Expand Down Expand Up @@ -607,4 +606,4 @@ private void AnalyzeFile(string filePath)

#endregion
}
}
}
6 changes: 2 additions & 4 deletions Engine/Generic/AvoidCmdletGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an abstract class for rule that checks whether the script
Expand All @@ -38,7 +36,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
// Finds all CommandAsts.
IEnumerable<Ast> commandAsts = ast.FindAll(testAst => testAst is CommandAst, true);

List<String> cmdletNameAndAliases = Microsoft.Windows.Powershell.ScriptAnalyzer.Helper.Instance.CmdletNameAndAliases(GetCmdletName());
List<String> cmdletNameAndAliases = Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.Instance.CmdletNameAndAliases(GetCmdletName());

// Iterrates all CommandAsts and check the command name.
foreach (CommandAst cmdAst in commandAsts)
Expand Down
5 changes: 1 addition & 4 deletions Engine/Generic/AvoidParameterGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an abstract class for rule that checks that
Expand Down
7 changes: 1 addition & 6 deletions Engine/Generic/DiagnosticRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents a result from a PSScriptAnalyzer rule.
Expand Down
7 changes: 1 addition & 6 deletions Engine/Generic/ExternalRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
internal class ExternalRule : IExternalRule
{
Expand Down
2 changes: 1 addition & 1 deletion Engine/Generic/IDSCResourceRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Collections.Generic;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an interface for a DSC rule that analyzes a DSC resource
Expand Down
7 changes: 1 addition & 6 deletions Engine/Generic/IExternalRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an interface for an external analyzer rule.
Expand Down
8 changes: 2 additions & 6 deletions Engine/Generic/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Windows.Powershell.ScriptAnalyzer.Commands;
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// ILogger: An interface for a PSScriptAnalyzer logger to output the results of PSScriptAnalyzer rules.
Expand Down
2 changes: 1 addition & 1 deletion Engine/Generic/IRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// THE SOFTWARE.
//

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// An interface for an analyzer rule that analyzes the Ast.
Expand Down
2 changes: 1 addition & 1 deletion Engine/Generic/IScriptRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using System.Threading.Tasks;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an interface for an analyzer rule that analyzes the Ast.
Expand Down
2 changes: 1 addition & 1 deletion Engine/Generic/ITokenRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Collections.Generic;
using System.Management.Automation.Language;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an interface for an analyzer rule that analyzes the tokens of a script.
Expand Down
7 changes: 1 addition & 6 deletions Engine/Generic/LoggerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an internal class to properly display the name and description of a logger.
Expand Down
7 changes: 1 addition & 6 deletions Engine/Generic/RuleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Windows.Powershell.ScriptAnalyzer.Generic
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
{
/// <summary>
/// Represents an internal class to properly display the name and description of a rule.
Expand Down
Loading