@@ -33,6 +33,9 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
33
33
#endif
34
34
public class ProvideCommentHelp : ConfigurableRule
35
35
{
36
+ // todo rearrange members
37
+ private CommentHelpPlacement placement ;
38
+
36
39
[ ConfigurableRuleProperty ( defaultValue : true ) ]
37
40
public bool ExportedOnly { get ; protected set ; }
38
41
@@ -44,14 +47,30 @@ public class ProvideCommentHelp : ConfigurableRule
44
47
45
48
// possible options: before, begin, end
46
49
[ 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
+ }
48
65
49
66
public ProvideCommentHelp ( ) : base ( )
50
67
{
51
68
// Enable the rule by default
52
69
Enable = true ;
53
70
}
54
71
72
+ private enum CommentHelpPlacement { Before , Begin , End } ;
73
+
55
74
/// <summary>
56
75
/// AnalyzeScript: Analyzes the ast to check that cmdlets have help.
57
76
/// </summary>
@@ -163,13 +182,13 @@ private IEnumerable<CorrectionExtent> GetCorrection(FunctionDefinitionAst funcDe
163
182
164
183
private string ProcessCorrectionForPlacement ( string correction )
165
184
{
166
- switch ( Placement . ToLower ( ) )
185
+ switch ( placement )
167
186
{
168
- case "begin" :
187
+ case CommentHelpPlacement . Begin :
169
188
return "{" + Environment . NewLine + correction + Environment . NewLine ;
170
- case "end" :
189
+ case CommentHelpPlacement . End :
171
190
return Environment . NewLine + correction + Environment . NewLine ;
172
- default :
191
+ default : // CommentHelpPlacement.Before
173
192
return correction + Environment . NewLine ;
174
193
}
175
194
}
@@ -182,23 +201,23 @@ private void GetCorrectionPosition(
182
201
out int endColumn )
183
202
{
184
203
// the better thing to do is get the line/column from corresponding tokens
185
- switch ( Placement . ToLower ( ) )
204
+ switch ( placement )
186
205
{
187
- case "begin" :
206
+ case CommentHelpPlacement . Begin :
188
207
startLine = funcDefnAst . Body . Extent . StartLineNumber ;
189
208
endLine = startLine ;
190
209
startColumn = funcDefnAst . Body . Extent . StartColumnNumber ;
191
210
endColumn = startColumn + 1 ;
192
211
break ;
193
212
194
- case "end" :
213
+ case CommentHelpPlacement . End :
195
214
startLine = funcDefnAst . Body . Extent . EndLineNumber ;
196
215
endLine = startLine ;
197
216
startColumn = funcDefnAst . Body . Extent . EndColumnNumber - 1 ;
198
217
endColumn = startColumn ;
199
218
break ;
200
219
201
- default : // before
220
+ default : // CommentHelpPlacement.Before
202
221
startLine = funcDefnAst . Extent . StartLineNumber ;
203
222
endLine = startLine ;
204
223
startColumn = funcDefnAst . Extent . StartColumnNumber ;
0 commit comments