@@ -33,6 +33,9 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
3333#endif
3434 public class ProvideCommentHelp : ConfigurableRule
3535 {
36+ // todo rearrange members
37+ private CommentHelpPlacement placement ;
38+
3639 [ ConfigurableRuleProperty ( defaultValue : true ) ]
3740 public bool ExportedOnly { get ; protected set ; }
3841
@@ -44,14 +47,30 @@ public class ProvideCommentHelp : ConfigurableRule
4447
4548 // possible options: before, begin, end
4649 [ ConfigurableRuleProperty ( defaultValue : "before" ) ]
47- public string Placement { get ; protected set ; }
50+ public string Placement
51+ {
52+ get
53+ {
54+ return placement . ToString ( ) ;
55+ }
56+ set
57+ {
58+ if ( String . IsNullOrWhiteSpace ( value ) ||
59+ ! Enum . TryParse < CommentHelpPlacement > ( value , true , out placement ) )
60+ {
61+ placement = CommentHelpPlacement . Before ;
62+ }
63+ }
64+ }
4865
4966 public ProvideCommentHelp ( ) : base ( )
5067 {
5168 // Enable the rule by default
5269 Enable = true ;
5370 }
5471
72+ private enum CommentHelpPlacement { Before , Begin , End } ;
73+
5574 /// <summary>
5675 /// AnalyzeScript: Analyzes the ast to check that cmdlets have help.
5776 /// </summary>
@@ -163,13 +182,13 @@ private IEnumerable<CorrectionExtent> GetCorrection(FunctionDefinitionAst funcDe
163182
164183 private string ProcessCorrectionForPlacement ( string correction )
165184 {
166- switch ( Placement . ToLower ( ) )
185+ switch ( placement )
167186 {
168- case "begin" :
187+ case CommentHelpPlacement . Begin :
169188 return "{" + Environment . NewLine + correction + Environment . NewLine ;
170- case "end" :
189+ case CommentHelpPlacement . End :
171190 return Environment . NewLine + correction + Environment . NewLine ;
172- default :
191+ default : // CommentHelpPlacement.Before
173192 return correction + Environment . NewLine ;
174193 }
175194 }
@@ -182,23 +201,23 @@ private void GetCorrectionPosition(
182201 out int endColumn )
183202 {
184203 // the better thing to do is get the line/column from corresponding tokens
185- switch ( Placement . ToLower ( ) )
204+ switch ( placement )
186205 {
187- case "begin" :
206+ case CommentHelpPlacement . Begin :
188207 startLine = funcDefnAst . Body . Extent . StartLineNumber ;
189208 endLine = startLine ;
190209 startColumn = funcDefnAst . Body . Extent . StartColumnNumber ;
191210 endColumn = startColumn + 1 ;
192211 break ;
193212
194- case "end" :
213+ case CommentHelpPlacement . End :
195214 startLine = funcDefnAst . Body . Extent . EndLineNumber ;
196215 endLine = startLine ;
197216 startColumn = funcDefnAst . Body . Extent . EndColumnNumber - 1 ;
198217 endColumn = startColumn ;
199218 break ;
200219
201- default : // before
220+ default : // CommentHelpPlacement.Before
202221 startLine = funcDefnAst . Extent . StartLineNumber ;
203222 endLine = startLine ;
204223 startColumn = funcDefnAst . Extent . StartColumnNumber ;
0 commit comments