1212
1313using System ;
1414using System . Collections . Generic ;
15+ using System . Linq ;
1516using System . Management . Automation . Language ;
1617using Microsoft . Windows . Powershell . ScriptAnalyzer . Generic ;
1718using System . ComponentModel . Composition ;
1819using System . Globalization ;
20+ using System . Management . Automation ;
1921
2022namespace Microsoft . Windows . Powershell . ScriptAnalyzer . BuiltinRules
2123{
@@ -33,11 +35,11 @@ public class ProvideVerboseMessage : SkipNamedBlock, IScriptRule
3335 public IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
3436 {
3537 if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
36-
38+
3739 ClearList ( ) ;
3840 this . AddNames ( new List < string > ( ) { "Configuration" , "Workflow" } ) ;
3941 DiagnosticRecords . Clear ( ) ;
40-
42+
4143 this . fileName = fileName ;
4244 //We only check that advanced functions should have Write-Verbose
4345 ast . Visit ( this ) ;
@@ -57,6 +59,17 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
5759 return AstVisitAction . SkipChildren ;
5860 }
5961
62+ //Write-Verbose is not required for non-advanced functions
63+ if ( funcAst . Body != null && funcAst . Body . ParamBlock != null
64+ && funcAst . Body . ParamBlock . Attributes != null &&
65+ funcAst . Body . ParamBlock . Parameters != null )
66+ {
67+ if ( ! funcAst . Body . ParamBlock . Attributes . Any ( attr => attr . TypeName . GetReflectionType ( ) == typeof ( CmdletBindingAttribute ) ) )
68+ {
69+ return AstVisitAction . Continue ;
70+ }
71+ }
72+
6073 var commandAsts = funcAst . Body . FindAll ( testAst => testAst is CommandAst , false ) ;
6174 bool hasVerbose = false ;
6275
0 commit comments