1- use std:: collections:: HashSet ;
1+ use std:: collections:: { HashMap , HashSet } ;
22
33use hemtt_common:: reporting:: { Code , Processed } ;
44
55use crate :: { Class , Config , Property } ;
66
7- use super :: { codes:: ce7_missing_parent:: MissingParrent , Analyze } ;
7+ use super :: {
8+ codes:: { ce7_missing_parent:: MissingParent , cw1_parent_case:: ParentCase } ,
9+ Analyze ,
10+ } ;
811
912impl Analyze for Config {
1013 fn valid ( & self ) -> bool {
1114 self . 0 . iter ( ) . all ( Analyze :: valid)
1215 }
1316
1417 fn warnings ( & self , processed : & Processed ) -> Vec < Box < dyn Code > > {
15- self . 0
18+ let mut warnings = self
19+ . 0
1620 . iter ( )
1721 . flat_map ( |p| p. warnings ( processed) )
18- . collect :: < Vec < _ > > ( )
22+ . collect :: < Vec < _ > > ( ) ;
23+ let mut defined = HashMap :: new ( ) ;
24+ warnings. extend ( external_missing_warn ( & self . 0 , & mut defined) ) ;
25+ warnings
1926 }
2027
2128 fn errors ( & self , processed : & Processed ) -> Vec < Box < dyn Code > > {
@@ -25,34 +32,84 @@ impl Analyze for Config {
2532 . flat_map ( |p| p. errors ( processed) )
2633 . collect :: < Vec < _ > > ( ) ;
2734 let mut defined = HashSet :: new ( ) ;
28- errors. extend ( external_missing ( & self . 0 , & mut defined) ) ;
35+ errors. extend ( external_missing_error ( & self . 0 , & mut defined) ) ;
2936 errors
3037 }
3138}
3239
33- fn external_missing ( properties : & [ Property ] , defined : & mut HashSet < String > ) -> Vec < Box < dyn Code > > {
40+ fn external_missing_error (
41+ properties : & [ Property ] ,
42+ defined : & mut HashSet < String > ,
43+ ) -> Vec < Box < dyn Code > > {
3444 let mut errors: Vec < Box < dyn Code > > = Vec :: new ( ) ;
3545 for property in properties {
3646 if let Property :: Class ( c) = property {
3747 match c {
3848 Class :: External { name } => {
39- if !defined. contains ( & name. value ) {
40- defined. insert ( name. value . clone ( ) ) ;
49+ let name = name. value . to_lowercase ( ) ;
50+ if !defined. contains ( & name) {
51+ defined. insert ( name) ;
4152 }
4253 }
4354 Class :: Local {
44- parent, properties, ..
55+ name,
56+ parent,
57+ properties,
4558 } => {
59+ let name = name. value . to_lowercase ( ) ;
4660 if let Some ( parent) = parent {
47- if !defined. contains ( & parent. value ) {
48- errors. push ( Box :: new ( MissingParrent :: new ( c. clone ( ) ) ) ) ;
61+ let parent = parent. value . to_lowercase ( ) ;
62+ if parent != name && !defined. contains ( & parent) {
63+ errors. push ( Box :: new ( MissingParent :: new ( c. clone ( ) ) ) ) ;
4964 }
5065 }
51- defined. insert ( c . name ( ) . value . clone ( ) ) ;
52- errors. extend ( external_missing ( properties, defined) ) ;
66+ defined. insert ( name) ;
67+ errors. extend ( external_missing_error ( properties, defined) ) ;
5368 }
5469 }
5570 }
5671 }
5772 errors
5873}
74+
75+ fn external_missing_warn (
76+ properties : & [ Property ] ,
77+ defined : & mut HashMap < String , Class > ,
78+ ) -> Vec < Box < dyn Code > > {
79+ let mut warnings: Vec < Box < dyn Code > > = Vec :: new ( ) ;
80+ for property in properties {
81+ if let Property :: Class ( c) = property {
82+ match c {
83+ Class :: External { name } => {
84+ let name = name. value . to_lowercase ( ) ;
85+ defined. entry ( name) . or_insert_with ( || c. clone ( ) ) ;
86+ }
87+ Class :: Local {
88+ name,
89+ parent,
90+ properties,
91+ } => {
92+ let name_lower = name. value . to_lowercase ( ) ;
93+ if let Some ( parent) = parent {
94+ let parent_lower = parent. value . to_lowercase ( ) ;
95+ if parent_lower != name_lower {
96+ if let Some ( parent_class) = defined. get ( & parent_lower) {
97+ if parent_class. name ( ) . value != parent. value {
98+ warnings. push ( Box :: new ( ParentCase :: new (
99+ c. clone ( ) ,
100+ parent_class. clone ( ) ,
101+ ) ) ) ;
102+ }
103+ }
104+ } else if parent. value != name. value {
105+ warnings. push ( Box :: new ( ParentCase :: new ( c. clone ( ) , c. clone ( ) ) ) ) ;
106+ }
107+ }
108+ defined. insert ( name_lower, c. clone ( ) ) ;
109+ warnings. extend ( external_missing_warn ( properties, defined) ) ;
110+ }
111+ }
112+ }
113+ }
114+ warnings
115+ }
0 commit comments