@@ -31,7 +31,7 @@ public class ProvideDefaultParameterValue : IScriptRule
31
31
/// </summary>
32
32
public IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
33
33
{
34
- if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
34
+ if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
35
35
36
36
// Finds all functionAst
37
37
IEnumerable < Ast > functionAsts = ast . FindAll ( testAst => testAst is FunctionDefinitionAst , true ) ;
@@ -40,28 +40,32 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
40
40
{
41
41
// Finds all ParamAsts.
42
42
IEnumerable < Ast > varAsts = funcAst . FindAll ( testAst => testAst is VariableExpressionAst , true ) ;
43
-
43
+
44
44
// Iterrates all ParamAsts and check if their names are on the list.
45
45
46
46
HashSet < string > paramVariables = new HashSet < string > ( ) ;
47
47
// only raise the rules for variables in the param block.
48
48
if ( funcAst . Body != null && funcAst . Body . ParamBlock != null && funcAst . Body . ParamBlock . Parameters != null )
49
49
{
50
- paramVariables . UnionWith ( funcAst . Body . ParamBlock . Parameters . Select ( paramAst => paramAst . Name . VariablePath . UserPath ) ) ;
50
+ foreach ( var paramAst in funcAst . Body . ParamBlock . Parameters )
51
+ {
52
+ if ( Helper . Instance . IsUninitialized ( paramAst . Name , funcAst ) )
53
+ {
54
+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . ProvideDefaultParameterValueError , paramAst . Name . VariablePath . UserPath ) ,
55
+ paramAst . Name . Extent , GetName ( ) , DiagnosticSeverity . Warning , fileName , paramAst . Name . VariablePath . UserPath ) ;
56
+ }
57
+ }
51
58
}
52
59
53
60
if ( funcAst . Parameters != null )
54
61
{
55
- paramVariables . UnionWith ( funcAst . Parameters . Select ( paramAst => paramAst . Name . VariablePath . UserPath ) ) ;
56
- }
57
-
58
- // Iterates all VariableExpressionAst and check the command name.
59
- foreach ( VariableExpressionAst varAst in varAsts )
60
- {
61
- if ( Helper . Instance . IsUninitialized ( varAst , funcAst ) && paramVariables . Contains ( varAst . VariablePath . UserPath ) )
62
+ foreach ( var paramAst in funcAst . Parameters )
62
63
{
63
- yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . ProvideDefaultParameterValueError , varAst . VariablePath . UserPath ) ,
64
- varAst . Extent , GetName ( ) , DiagnosticSeverity . Warning , fileName , varAst . VariablePath . UserPath ) ;
64
+ if ( Helper . Instance . IsUninitialized ( paramAst . Name , funcAst ) )
65
+ {
66
+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . ProvideDefaultParameterValueError , paramAst . Name . VariablePath . UserPath ) ,
67
+ paramAst . Name . Extent , GetName ( ) , DiagnosticSeverity . Warning , fileName , paramAst . Name . VariablePath . UserPath ) ;
68
+ }
65
69
}
66
70
}
67
71
}
0 commit comments