@@ -31,7 +31,7 @@ public class ProvideDefaultParameterValue : IScriptRule
3131 /// </summary>
3232 public IEnumerable < DiagnosticRecord > AnalyzeScript ( Ast ast , string fileName )
3333 {
34- if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
34+ if ( ast == null ) throw new ArgumentNullException ( Strings . NullAstErrorMessage ) ;
3535
3636 // Finds all functionAst
3737 IEnumerable < Ast > functionAsts = ast . FindAll ( testAst => testAst is FunctionDefinitionAst , true ) ;
@@ -40,28 +40,32 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4040 {
4141 // Finds all ParamAsts.
4242 IEnumerable < Ast > varAsts = funcAst . FindAll ( testAst => testAst is VariableExpressionAst , true ) ;
43-
43+
4444 // Iterrates all ParamAsts and check if their names are on the list.
4545
4646 HashSet < string > paramVariables = new HashSet < string > ( ) ;
4747 // only raise the rules for variables in the param block.
4848 if ( funcAst . Body != null && funcAst . Body . ParamBlock != null && funcAst . Body . ParamBlock . Parameters != null )
4949 {
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+ }
5158 }
5259
5360 if ( funcAst . Parameters != null )
5461 {
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 )
6263 {
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+ }
6569 }
6670 }
6771 }
0 commit comments