11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4- using Microsoft . Windows . PowerShell . ScriptAnalyzer . Generic ;
54using System ;
65using System . Collections . Generic ;
7- using System . Globalization ;
8- using System . Management . Automation . Language ;
9- using System . Text . RegularExpressions ;
10-
116#if ! CORECLR
127using System . ComponentModel . Composition ;
138#endif
9+ using System . Globalization ;
10+ using System . Management . Automation . Language ;
11+ using Microsoft . Windows . PowerShell . ScriptAnalyzer . Generic ;
12+ using System . Text . RegularExpressions ;
1413
1514namespace Microsoft . Windows . PowerShell . ScriptAnalyzer . BuiltinRules
1615{
16+ /// <summary>
17+ /// AvoidUsingArrayList: Checks for use of the ArrayList class
18+ /// </summary>
1719#if ! CORECLR
1820 [ Export ( typeof ( IScriptRule ) ) ]
1921#endif
20-
21- /// <summary>
22- /// Rule that warns when the ArrayList class is used in a PowerShell script.
23- /// </summary>
24- public class AvoidUsingArrayListAsFunctionNames : IScriptRule
22+ public class AvoidUsingArrayList : ConfigurableRule
2523 {
2624
2725 /// <summary>
28- /// Analyzes the PowerShell AST for uses of the ArrayList class .
26+ /// Construct an object of AvoidUsingArrayList type .
2927 /// </summary>
30- /// <param name="ast">The PowerShell Abstract Syntax Tree to analyze.</param>
31- /// <param name="fileName">The name of the file being analyzed (for diagnostic reporting).</param>
32- /// <returns>A collection of diagnostic records for each violation.</returns>
28+ public AvoidUsingArrayList ( ) {
29+ Enable = true ;
30+ }
3331
34- public IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
32+ /// <summary>
33+ /// Analyzes the given ast to find the [violation]
34+ /// </summary>
35+ /// <param name="ast">AST to be analyzed. This should be non-null</param>
36+ /// <param name="fileName">Name of file that corresponds to the input AST.</param>
37+ /// <returns>A an enumerable type containing the violations</returns>
38+ public override IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
3539 {
3640 if ( ast == null ) { throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ; }
3741
@@ -118,26 +122,69 @@ testAst is CommandAst cmdAst &&
118122 fileName
119123 ) ;
120124 }
121-
122125 }
123-
124-
125126 }
126127
127- public string GetCommonName ( ) => Strings . AvoidUsingArrayListCommonName ;
128+ /// <summary>
129+ /// Retrieves the common name of this rule.
130+ /// </summary>
131+ public override string GetCommonName ( )
132+ {
133+ return string . Format ( CultureInfo . CurrentCulture , Strings . AvoidUsingArrayListCommonName ) ;
134+ }
128135
129- public string GetDescription ( ) => Strings . AvoidUsingArrayListDescription ;
136+ /// <summary>
137+ /// Retrieves the description of this rule.
138+ /// </summary>
139+ public override string GetDescription ( )
140+ {
141+ return string . Format ( CultureInfo . CurrentCulture , Strings . AvoidUsingArrayListDescription ) ;
142+ }
130143
131- public string GetName ( ) => string . Format (
144+ /// <summary>
145+ /// Retrieves the name of this rule.
146+ /// </summary>
147+ public override string GetName ( )
148+ {
149+ return string . Format (
132150 CultureInfo . CurrentCulture ,
133151 Strings . NameSpaceFormat ,
134152 GetSourceName ( ) ,
135153 Strings . AvoidUsingArrayListName ) ;
154+ }
136155
137- public RuleSeverity GetSeverity ( ) => RuleSeverity . Warning ;
156+ /// <summary>
157+ /// Retrieves the severity of the rule: error, warning or information.
158+ /// </summary>
159+ public override RuleSeverity GetSeverity ( )
160+ {
161+ return RuleSeverity . Warning ;
162+ }
138163
139- public string GetSourceName ( ) => Strings . SourceName ;
164+ /// <summary>
165+ /// Gets the severity of the returned diagnostic record: error, warning, or information.
166+ /// </summary>
167+ /// <returns></returns>
168+ public DiagnosticSeverity GetDiagnosticSeverity ( )
169+ {
170+ return DiagnosticSeverity . Warning ;
171+ }
172+
173+ /// <summary>
174+ /// Retrieves the name of the module/assembly the rule is from.
175+ /// </summary>
176+ public override string GetSourceName ( )
177+ {
178+ return string . Format ( CultureInfo . CurrentCulture , Strings . SourceName ) ;
179+ }
140180
141- public SourceType GetSourceType ( ) => SourceType . Builtin ;
181+ /// <summary>
182+ /// Retrieves the type of the rule, Builtin, Managed or Module.
183+ /// </summary>
184+ public override SourceType GetSourceType ( )
185+ {
186+ return SourceType . Builtin ;
187+ }
142188 }
143- }
189+ }
190+
0 commit comments