@@ -40,83 +40,83 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
40
40
}
41
41
if ( Helper . IsModuleManifest ( fileName ) )
42
42
{
43
- var ps = System . Management . Automation . PowerShell . Create ( ) ;
44
- IEnumerable < PSObject > result = null ;
45
-
46
- // hash table in psd1
47
- var hashTableAst = ast . FindAll ( item => item is HashtableAst , false ) . FirstOrDefault ( ) ;
48
-
49
- // no hash table means not a module manifest
50
- if ( hashTableAst == null )
43
+ using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
51
44
{
52
- yield break ;
53
- }
45
+ IEnumerable < PSObject > result = null ;
54
46
55
- var table = hashTableAst as HashtableAst ;
47
+ // hash table in psd1
48
+ var hashTableAst = ast . FindAll ( item => item is HashtableAst , false ) . FirstOrDefault ( ) ;
56
49
57
- // needs to find the PowerShellVersion key
58
- foreach ( var kvp in table . KeyValuePairs )
59
- {
60
- if ( kvp . Item1 != null && kvp . Item1 is StringConstantExpressionAst )
50
+ // no hash table means not a module manifest
51
+ if ( hashTableAst == null )
61
52
{
62
- var key = ( kvp . Item1 as StringConstantExpressionAst ) . Value ;
53
+ yield break ;
54
+ }
63
55
64
- // find the powershellversion key in the hashtable
65
- if ( string . Equals ( key , "PowerShellVersion" , StringComparison . OrdinalIgnoreCase ) && kvp . Item2 != null )
56
+ var table = hashTableAst as HashtableAst ;
57
+
58
+ // needs to find the PowerShellVersion key
59
+ foreach ( var kvp in table . KeyValuePairs )
60
+ {
61
+ if ( kvp . Item1 != null && kvp . Item1 is StringConstantExpressionAst )
66
62
{
67
- // get the string value of the version
68
- var value = kvp . Item2 . Find ( item => item is StringConstantExpressionAst , false ) ;
63
+ var key = ( kvp . Item1 as StringConstantExpressionAst ) . Value ;
69
64
70
- if ( value != null )
65
+ // find the powershellversion key in the hashtable
66
+ if ( string . Equals ( key , "PowerShellVersion" , StringComparison . OrdinalIgnoreCase ) && kvp . Item2 != null )
71
67
{
72
- Version psVersion = null ;
68
+ // get the string value of the version
69
+ var value = kvp . Item2 . Find ( item => item is StringConstantExpressionAst , false ) ;
73
70
74
- // get the version
75
- if ( Version . TryParse ( ( value as StringConstantExpressionAst ) . Value , out psVersion ) )
71
+ if ( value != null )
76
72
{
77
- // if version exists and version less than 3, don't raise rule
78
- if ( psVersion . Major < 3 )
73
+ Version psVersion = null ;
74
+
75
+ // get the version
76
+ if ( Version . TryParse ( ( value as StringConstantExpressionAst ) . Value , out psVersion ) )
79
77
{
80
- yield break ;
78
+ // if version exists and version less than 3, don't raise rule
79
+ if ( psVersion . Major < 3 )
80
+ {
81
+ yield break ;
82
+ }
81
83
}
82
84
}
83
85
}
84
86
}
85
87
}
86
- }
87
88
88
- try
89
- {
90
- ps . AddCommand ( "Test-ModuleManifest" ) ;
91
- ps . AddParameter ( "Path" , fileName ) ;
92
-
93
- // Suppress warnings emitted during the execution of Test-ModuleManifest
94
- // ModuleManifest rule must catch any violations (warnings/errors) and generate DiagnosticRecord(s)
95
- ps . AddParameter ( "WarningAction" , ActionPreference . SilentlyContinue ) ;
96
- ps . AddParameter ( "WarningVariable" , "Message" ) ;
97
- ps . AddScript ( "$Message" ) ;
98
- result = ps . Invoke ( ) ;
99
- }
100
- catch
101
- { }
89
+ try
90
+ {
91
+ ps . AddCommand ( "Test-ModuleManifest" ) ;
92
+ ps . AddParameter ( "Path" , fileName ) ;
93
+
94
+ // Suppress warnings emitted during the execution of Test-ModuleManifest
95
+ // ModuleManifest rule must catch any violations (warnings/errors) and generate DiagnosticRecord(s)
96
+ ps . AddParameter ( "WarningAction" , ActionPreference . SilentlyContinue ) ;
97
+ ps . AddParameter ( "WarningVariable" , "Message" ) ;
98
+ ps . AddScript ( "$Message" ) ;
99
+ result = ps . Invoke ( ) ;
100
+ }
101
+ catch
102
+ { }
102
103
103
- if ( result != null )
104
- {
105
- foreach ( var warning in result )
104
+ if ( result != null )
106
105
{
107
- if ( warning . BaseObject != null )
106
+ foreach ( var warning in result )
108
107
{
109
- yield return
110
- new DiagnosticRecord (
111
- String . Format ( CultureInfo . CurrentCulture , warning . BaseObject . ToString ( ) ) , ast . Extent ,
112
- GetName ( ) , DiagnosticSeverity . Warning , fileName ) ;
108
+ if ( warning . BaseObject != null )
109
+ {
110
+ yield return
111
+ new DiagnosticRecord (
112
+ String . Format ( CultureInfo . CurrentCulture , warning . BaseObject . ToString ( ) ) , ast . Extent ,
113
+ GetName ( ) , DiagnosticSeverity . Warning , fileName ) ;
114
+ }
113
115
}
114
116
}
115
- }
116
117
117
- ps . Dispose ( ) ;
118
+ }
118
119
}
119
-
120
120
}
121
121
122
122
/// <summary>
0 commit comments