21
21
namespace Microsoft . Windows . PowerShell . ScriptAnalyzer . BuiltinRules
22
22
{
23
23
/// <summary>
24
- /// AvoidUsingNullOrEmptyHelpMessageParameter : Check if the HelpMessage parameter is set to a non-empty string.
24
+ /// AvoidUsingNullOrEmptyHelpMessageAttribute : Check if the HelpMessage parameter is set to a non-empty string.
25
25
/// </summary>
26
26
[ Export ( typeof ( IScriptRule ) ) ]
27
27
public class AvoidNullOrEmptyHelpMessageAttribute : IScriptRule
28
28
{
29
29
/// <summary>
30
- /// AvoidUsingNullOrEmptyHelpMessageParameter : Check if the HelpMessage parameter is set to a non-empty string.
30
+ /// AvoidUsingNullOrEmptyHelpMessageAttribute : Check if the HelpMessage parameter is set to a non-empty string.
31
31
/// </summary>
32
32
public IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
33
33
{
@@ -39,32 +39,41 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
39
39
foreach ( FunctionDefinitionAst funcAst in functionAsts )
40
40
{
41
41
if ( funcAst . Body == null || funcAst . Body . ParamBlock == null
42
- || funcAst . Body . ParamBlock . Attributes == null || funcAst . Body . ParamBlock . Parameters == null )
42
+ || funcAst . Body . ParamBlock . Attributes == null || funcAst . Body . ParamBlock . Parameters == null )
43
+ {
43
44
continue ;
45
+ }
44
46
45
47
foreach ( var paramAst in funcAst . Body . ParamBlock . Parameters )
46
48
{
47
49
foreach ( var paramAstAttribute in paramAst . Attributes )
48
50
{
49
51
if ( ! ( paramAstAttribute is AttributeAst ) )
52
+ {
50
53
continue ;
54
+ }
51
55
52
56
var namedArguments = ( paramAstAttribute as AttributeAst ) . NamedArguments ;
53
57
54
58
if ( namedArguments == null )
59
+ {
55
60
continue ;
61
+ }
56
62
57
63
foreach ( NamedAttributeArgumentAst namedArgument in namedArguments )
58
64
{
59
- if ( ! ( String . Equals ( namedArgument . ArgumentName , "HelpMessage" , StringComparison . OrdinalIgnoreCase ) )
60
- || namedArgument . ExpressionOmitted )
65
+ if ( ! ( namedArgument . ArgumentName . Equals ( "HelpMessage" , StringComparison . OrdinalIgnoreCase ) ) )
66
+ {
61
67
continue ;
68
+ }
62
69
63
70
string errCondition ;
64
- if ( namedArgument . Argument . Extent . Text . Equals ( "\" \" " ) )
71
+ if ( namedArgument . ExpressionOmitted
72
+ || namedArgument . Argument . Extent . Text . Equals ( "\" \" " )
73
+ || namedArgument . Argument . Extent . Text . Equals ( "\' \' " ) )
65
74
{
66
75
errCondition = "empty" ;
67
- }
76
+ }
68
77
else if ( namedArgument . Argument . Extent . Text . Equals ( "$null" , StringComparison . OrdinalIgnoreCase ) )
69
78
{
70
79
errCondition = "null" ;
@@ -134,7 +143,7 @@ public SourceType GetSourceType()
134
143
/// <returns></returns>
135
144
public RuleSeverity GetSeverity ( )
136
145
{
137
- return RuleSeverity . Error ;
146
+ return RuleSeverity . Warning ;
138
147
}
139
148
140
149
/// <summary>
0 commit comments