Skip to content

Commit e22d1b4

Browse files
author
Kapil Borle
authored
Merge pull request #616 from PowerShell/kapilmb/FixAstVisitForExternalRule
Fix AST visitor for external rules
2 parents 650b5c2 + 02b0a89 commit e22d1b4

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,6 @@ private IEnumerable<T> GetInterfaceImplementationsFromAssembly<T>(string ruleDll
861861
"Creating Instance of {0}", type.Name));
862862

863863
var ruleObj = Activator.CreateInstance(type);
864-
outputWriter.WriteVerbose(
865-
string.Format(
866-
"Created Instance of {0}", type.Name));
867-
868864
T rule = ruleObj as T;
869865
if (rule == null)
870866
{
@@ -1164,7 +1160,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
11641160
{
11651161
// Find all AstTypes that appeared in rule groups.
11661162
IEnumerable<Ast> childAsts = ast.FindAll(new Func<Ast, bool>((testAst) =>
1167-
(astRuleGroup.Key.IndexOf(testAst.GetType().FullName, StringComparison.OrdinalIgnoreCase) != -1)), false);
1163+
(astRuleGroup.Key.IndexOf(testAst.GetType().FullName, StringComparison.OrdinalIgnoreCase) != -1)), true);
11681164

11691165
foreach (Ast childAst in childAsts)
11701166
{

Rules/AvoidAlias.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public List<string> WhiteList
3737
get { return whiteList; }
3838
}
3939

40-
AvoidAlias()
40+
public AvoidAlias()
4141
{
4242
isPropertiesSet = false;
4343
}

Rules/UseLiteralInitializerForHashtable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2828
#if !CORECLR
2929
[Export(typeof(IScriptRule))]
3030
#endif
31-
class UseLiteralInitializerForHashtable : AstVisitor, IScriptRule
31+
public class UseLiteralInitializerForHashtable : AstVisitor, IScriptRule
3232
{
3333
private List<DiagnosticRecord> diagnosticRecords;
3434
private HashSet<string> presetTypeNameSet;

Tests/Rules/AvoidUsingAlias.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Describe "AvoidUsingAlias" {
3333
}
3434

3535
Context "Settings file provides whitelist" {
36-
$whiteListTestScriptDef = 'gci; cd; iwr'
36+
$whiteListTestScriptDef = 'gci; cd;'
3737

3838
It "honors the whitelist provided as hashtable" {
3939
$settings = @{
@@ -44,14 +44,14 @@ Describe "AvoidUsingAlias" {
4444
}
4545
}
4646
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $whiteListTestScriptDef -Settings $settings -IncludeRule $violationName
47-
$violations.Count | Should Be 2
47+
$violations.Count | Should Be 1
4848
}
4949

5050
It "honors the whitelist provided through settings file" {
5151
# even though join-path returns string, if we do not use tostring, then invoke-scriptanalyzer cannot cast it to string type
5252
$settingsFilePath = (Join-Path $directory (Join-Path 'TestSettings' 'AvoidAliasSettings.psd1')).ToString()
5353
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $whiteListTestScriptDef -Settings $settingsFilePath -IncludeRule $violationName
54-
$violations.Count | Should be 2
54+
$violations.Count | Should be 1
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)