@@ -30,9 +30,8 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
30
30
#if ! CORECLR
31
31
[ Export ( typeof ( IScriptRule ) ) ]
32
32
#endif
33
- public class ProvideCommentHelp : SkipTypeDefinition , IScriptRule
33
+ public class ProvideCommentHelp : IScriptRule
34
34
{
35
- private HashSet < string > exportedFunctions ;
36
35
37
36
/// <summary>
38
37
/// AnalyzeScript: Analyzes the ast to check that cmdlets have help.
@@ -44,47 +43,20 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
44
43
{
45
44
if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
46
45
47
- DiagnosticRecords . Clear ( ) ;
48
- this . fileName = fileName ;
49
- exportedFunctions = Helper . Instance . GetExportedFunction ( ast ) ;
50
-
51
- ast . Visit ( this ) ;
52
-
53
- return DiagnosticRecords ;
54
- }
55
-
56
- /// <summary>
57
- /// Visit function and checks that it has comment help
58
- /// </summary>
59
- /// <param name="funcAst"></param>
60
- /// <returns></returns>
61
- public override AstVisitAction VisitFunctionDefinition ( FunctionDefinitionAst funcAst )
62
- {
63
- if ( funcAst == null )
64
- {
65
- return AstVisitAction . SkipChildren ;
66
- }
67
-
68
- if ( exportedFunctions . Contains ( funcAst . Name ) )
46
+ var exportedFunctions = Helper . Instance . GetExportedFunction ( ast ) ;
47
+ var violationFinder = new ViolationFinder ( exportedFunctions ) ;
48
+ ast . Visit ( violationFinder ) ;
49
+ foreach ( var functionDefinitionAst in violationFinder . FunctionDefinitionAsts )
69
50
{
70
- if ( funcAst . GetHelpContent ( ) == null )
71
- {
72
- // todo create auto correction
73
- // todo add option to add help for non exported members
74
- // todo add option to set help location
75
- DiagnosticRecords . Add (
76
- new DiagnosticRecord (
77
- string . Format ( CultureInfo . CurrentCulture , Strings . ProvideCommentHelpError , funcAst . Name ) ,
78
- Helper . Instance . GetScriptExtentForFunctionName ( funcAst ) ,
79
- GetName ( ) ,
80
- DiagnosticSeverity . Information ,
81
- fileName ,
82
- null ,
83
- GetCorrection ( funcAst ) . ToList ( ) ) ) ;
84
- }
51
+ yield return new DiagnosticRecord (
52
+ String . Format ( CultureInfo . CurrentCulture , Strings . ProvideCommentHelpError , functionDefinitionAst . Name ) ,
53
+ Helper . Instance . GetScriptExtentForFunctionName ( functionDefinitionAst ) ,
54
+ GetName ( ) ,
55
+ GetDiagnosticSeverity ( ) ,
56
+ fileName ,
57
+ null ,
58
+ GetCorrection ( functionDefinitionAst ) . ToList ( ) ) ;
85
59
}
86
-
87
- return AstVisitAction . Continue ;
88
60
}
89
61
90
62
/// <summary>
@@ -139,6 +111,11 @@ public string GetSourceName()
139
111
return string . Format ( CultureInfo . CurrentCulture , Strings . SourceName ) ;
140
112
}
141
113
114
+ private DiagnosticSeverity GetDiagnosticSeverity ( )
115
+ {
116
+ return DiagnosticSeverity . Information ;
117
+ }
118
+
142
119
private IEnumerable < CorrectionExtent > GetCorrection ( FunctionDefinitionAst funcDefnAst )
143
120
{
144
121
var helpBuilder = new CommentHelpBuilder ( ) ;
@@ -247,6 +224,7 @@ public override string ToString()
247
224
sb . Append ( notes . ToString ( ) ) ;
248
225
return sb . ToString ( ) ;
249
226
}
227
+
250
228
private class CommentHelpNode
251
229
{
252
230
public CommentHelpNode ( string nodeName , string description )
0 commit comments