@@ -33,6 +33,9 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
33
33
public class ProvideCommentHelp : ConfigurableRule
34
34
{
35
35
36
+ [ ConfigurableRuleProperty ( defaultValue : true ) ]
37
+ public bool ExportedOnly { get ; protected set ; }
38
+
36
39
public ProvideCommentHelp ( ) : base ( )
37
40
{
38
41
// Enable the rule by default
@@ -50,7 +53,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
50
53
if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
51
54
52
55
var exportedFunctions = Helper . Instance . GetExportedFunction ( ast ) ;
53
- var violationFinder = new ViolationFinder ( exportedFunctions ) ;
56
+ var violationFinder = new ViolationFinder ( exportedFunctions , ExportedOnly ) ;
54
57
ast . Visit ( violationFinder ) ;
55
58
foreach ( var functionDefinitionAst in violationFinder . FunctionDefinitionAsts )
56
59
{
@@ -146,12 +149,13 @@ private IEnumerable<CorrectionExtent> GetCorrection(FunctionDefinitionAst funcDe
146
149
147
150
private class ViolationFinder : AstVisitor
148
151
{
149
- private HashSet < string > exportedFunctions ;
152
+ private HashSet < string > functionWhitelist ;
150
153
private List < FunctionDefinitionAst > functionDefinitionAsts ;
154
+ private bool useFunctionWhitelist ;
151
155
152
156
public ViolationFinder ( )
153
157
{
154
- exportedFunctions = new HashSet < string > ( ) ;
158
+ functionWhitelist = new HashSet < string > ( ) ;
155
159
functionDefinitionAsts = new List < FunctionDefinitionAst > ( ) ;
156
160
}
157
161
@@ -162,7 +166,12 @@ public ViolationFinder(HashSet<string> exportedFunctions) : this()
162
166
throw new ArgumentNullException ( nameof ( exportedFunctions ) ) ;
163
167
}
164
168
165
- this . exportedFunctions = exportedFunctions ;
169
+ this . functionWhitelist = exportedFunctions ;
170
+ }
171
+
172
+ public ViolationFinder ( HashSet < string > exportedFunctions , bool exportedOnly ) : this ( exportedFunctions )
173
+ {
174
+ this . useFunctionWhitelist = exportedOnly ;
166
175
}
167
176
168
177
public IEnumerable < FunctionDefinitionAst > FunctionDefinitionAsts { get { return functionDefinitionAsts ; } }
@@ -174,7 +183,7 @@ public ViolationFinder(HashSet<string> exportedFunctions) : this()
174
183
/// <returns></returns>
175
184
public override AstVisitAction VisitFunctionDefinition ( FunctionDefinitionAst funcAst )
176
185
{
177
- if ( exportedFunctions . Contains ( funcAst . Name )
186
+ if ( ( ! useFunctionWhitelist || functionWhitelist . Contains ( funcAst . Name ) )
178
187
&& funcAst . GetHelpContent ( ) == null )
179
188
{
180
189
functionDefinitionAsts . Add ( funcAst ) ;
0 commit comments