@@ -33,7 +33,6 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
33
33
IEnumerable < Ast > paramAsts = ast . FindAll ( testAst => testAst is ParameterAst , true ) ;
34
34
Ast parentAst ;
35
35
36
- string funcName ;
37
36
string paramName ;
38
37
39
38
PropertyInfo [ ] commonParams = typeof ( CommonParameters ) . GetProperties ( ) ;
@@ -55,14 +54,20 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
55
54
parentAst = parentAst . Parent ;
56
55
}
57
56
58
- if ( parentAst is FunctionDefinitionAst ) {
59
- funcName = string . Format ( CultureInfo . CurrentCulture , Strings . ReservedParamsCmdletPrefix , ( parentAst as FunctionDefinitionAst ) . Name ) ;
57
+ if ( parentAst is FunctionDefinitionAst )
58
+ {
59
+ IEnumerable < Ast > attrs = parentAst . FindAll ( testAttr => testAttr is AttributeAst , true ) ;
60
+ foreach ( AttributeAst attr in attrs )
61
+ {
62
+ if ( string . Equals ( attr . Extent . Text , "[CmdletBinding()]" ,
63
+ StringComparison . OrdinalIgnoreCase ) )
64
+ {
65
+ string funcName = string . Format ( CultureInfo . CurrentCulture , Strings . ReservedParamsCmdletPrefix , ( parentAst as FunctionDefinitionAst ) . Name ) ;
66
+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . ReservedParamsError , funcName , paramName ) , paramAst . Extent , GetName ( ) , DiagnosticSeverity . Warning , fileName ) ;
67
+
68
+ }
69
+ }
60
70
}
61
- else {
62
- funcName = Strings . ReservedParamsScriptPrefix ;
63
- }
64
-
65
- yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . ReservedParamsError , funcName , paramName ) , paramAst . Extent , GetName ( ) , DiagnosticSeverity . Warning , fileName ) ;
66
71
}
67
72
}
68
73
}
0 commit comments