@@ -30,9 +30,8 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
3030#if ! CORECLR
3131 [ Export ( typeof ( IScriptRule ) ) ]
3232#endif
33- public class ProvideCommentHelp : SkipTypeDefinition , IScriptRule
33+ public class ProvideCommentHelp : IScriptRule
3434 {
35- private HashSet < string > exportedFunctions ;
3635
3736 /// <summary>
3837 /// AnalyzeScript: Analyzes the ast to check that cmdlets have help.
@@ -44,47 +43,20 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4443 {
4544 if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
4645
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 )
6950 {
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 ( ) ) ;
8559 }
86-
87- return AstVisitAction . Continue ;
8860 }
8961
9062 /// <summary>
@@ -139,6 +111,11 @@ public string GetSourceName()
139111 return string . Format ( CultureInfo . CurrentCulture , Strings . SourceName ) ;
140112 }
141113
114+ private DiagnosticSeverity GetDiagnosticSeverity ( )
115+ {
116+ return DiagnosticSeverity . Information ;
117+ }
118+
142119 private IEnumerable < CorrectionExtent > GetCorrection ( FunctionDefinitionAst funcDefnAst )
143120 {
144121 var helpBuilder = new CommentHelpBuilder ( ) ;
@@ -247,6 +224,7 @@ public override string ToString()
247224 sb . Append ( notes . ToString ( ) ) ;
248225 return sb . ToString ( ) ;
249226 }
227+
250228 private class CommentHelpNode
251229 {
252230 public CommentHelpNode ( string nodeName , string description )
0 commit comments