@@ -40,83 +40,83 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4040            } 
4141            if  ( Helper . IsModuleManifest ( fileName ) ) 
4242            { 
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 ( ) ) 
5144                { 
52-                     yield  break ; 
53-                 } 
45+                     IEnumerable < PSObject >  result  =  null ; 
5446
55-                 var  table  =  hashTableAst  as  HashtableAst ; 
47+                     // hash table in psd1 
48+                     var  hashTableAst  =  ast . FindAll ( item =>  item  is  HashtableAst ,  false ) . FirstOrDefault ( ) ; 
5649
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 ) 
6152                    { 
62-                         var  key  =  ( kvp . Item1  as  StringConstantExpressionAst ) . Value ; 
53+                         yield  break ; 
54+                     } 
6355
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 ) 
6662                        { 
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 ; 
6964
70-                             if  ( value  !=  null ) 
65+                             // find the powershellversion key in the hashtable 
66+                             if  ( string . Equals ( key ,  "PowerShellVersion" ,  StringComparison . OrdinalIgnoreCase )  &&  kvp . Item2  !=  null ) 
7167                            { 
72-                                 Version  psVersion  =  null ; 
68+                                 // get the string value of the version 
69+                                 var  value  =  kvp . Item2 . Find ( item =>  item  is  StringConstantExpressionAst ,  false ) ; 
7370
74-                                 // get the version 
75-                                 if  ( Version . TryParse ( ( value  as  StringConstantExpressionAst ) . Value ,  out  psVersion ) ) 
71+                                 if  ( value  !=  null ) 
7672                                { 
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 ) ) 
7977                                    { 
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+                                         } 
8183                                    } 
8284                                } 
8385                            } 
8486                        } 
8587                    } 
86-                 } 
8788
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+                      { } 
102103
103-                 if  ( result  !=  null ) 
104-                 { 
105-                     foreach  ( var  warning  in  result ) 
104+                     if  ( result  !=  null ) 
106105                    { 
107-                         if   ( warning . BaseObject   !=   null ) 
106+                         foreach   ( var   warning   in   result ) 
108107                        { 
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+                             } 
113115                        } 
114116                    } 
115-                 } 
116117
117-                 ps . Dispose ( ) ; 
118+                 } 
118119            } 
119- 
120120        } 
121121
122122        /// <summary> 
0 commit comments