11use crate :: config:: ConfigOption ;
22use crate :: linter:: { SyntaxRule , SyntaxRuleResult } ;
3- use sv_parser:: { unwrap_locate, unwrap_node , NodeEvent , RefNode , SyntaxTree } ;
3+ use sv_parser:: { unwrap_locate, NodeEvent , RefNode , SyntaxTree } ;
44
55#[ derive( Default ) ]
6- pub struct ParameterInPackage ;
6+ pub struct ParameterInPackage {
7+ inside_param_port_list : bool ,
8+ }
79
810impl SyntaxRule for ParameterInPackage {
911 fn check (
@@ -12,24 +14,22 @@ impl SyntaxRule for ParameterInPackage {
1214 event : & NodeEvent ,
1315 _option : & ConfigOption ,
1416 ) -> SyntaxRuleResult {
15- let node = match event {
16- NodeEvent :: Enter ( x) => x,
17- NodeEvent :: Leave ( _) => {
18- return SyntaxRuleResult :: Pass ;
19- }
20- } ;
21- match node {
22- RefNode :: PackageDeclaration ( x) => {
23- let param = unwrap_node ! ( * x, ParameterDeclaration ) ;
24- if let Some ( param) = param {
25- let param_locate = unwrap_locate ! ( param) . unwrap ( ) ;
26- SyntaxRuleResult :: FailLocate ( * param_locate)
27- } else {
28- SyntaxRuleResult :: Pass
17+ match event {
18+ NodeEvent :: Enter ( RefNode :: ParameterPortList ( _) ) => {
19+ self . inside_param_port_list = true ;
20+ } ,
21+ NodeEvent :: Leave ( RefNode :: ParameterPortList ( _) ) => {
22+ self . inside_param_port_list = false ;
23+ } ,
24+ NodeEvent :: Enter ( RefNode :: ParameterDeclaration ( & ref x) ) => {
25+ if !self . inside_param_port_list {
26+ let param_locate = unwrap_locate ! ( x) . unwrap ( ) ;
27+ return SyntaxRuleResult :: FailLocate ( * param_locate)
2928 }
30- }
31- _ => SyntaxRuleResult :: Pass ,
32- }
29+ } ,
30+ _ => { }
31+ } ;
32+ return SyntaxRuleResult :: Pass
3333 }
3434
3535 fn name ( & self ) -> String {
0 commit comments