Skip to content

Commit

Permalink
finish up check
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Sep 20, 2023
1 parent 9336ad8 commit 3ec8c3a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
18 changes: 12 additions & 6 deletions libs/config/src/analyze/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ fn external_missing_warn(
}

fn duplicate_properties(properties: &[Property]) -> Vec<Box<dyn Code>> {
let mut seen: HashMap<String, Vec<Ident>> = HashMap::new();
let mut seen: HashMap<String, Vec<(bool, Ident)>> = HashMap::new();
duplicate_properties_inner("", properties, &mut seen);
let mut errors: Vec<Box<dyn Code>> = Vec::new();
for (_, idents) in seen {
if idents.len() > 1 {
errors.push(Box::new(DuplicateProperty::new(idents)));
if idents.len() > 1 && !idents.iter().all(|(class, _)| *class) {
errors.push(Box::new(DuplicateProperty::new(
idents.into_iter().map(|(_, i)| i).collect(),
)));
}
}
errors
Expand All @@ -133,7 +135,7 @@ fn duplicate_properties(properties: &[Property]) -> Vec<Box<dyn Code>> {
fn duplicate_properties_inner(
scope: &str,
properties: &[Property],
seen: &mut HashMap<String, Vec<Ident>>,
seen: &mut HashMap<String, Vec<(bool, Ident)>>,
) {
for property in properties {
match property {
Expand All @@ -145,12 +147,16 @@ fn duplicate_properties_inner(
properties,
seen,
);
let entry = seen
.entry(format!("{}.{}", scope, name.value.to_lowercase()))
.or_default();
entry.push((true, name.clone()));
}
Property::Entry { name, .. } => {
Property::Entry { name, .. } | Property::MissingSemicolon(name, _) => {
let entry = seen
.entry(format!("{}.{}", scope, name.value.to_lowercase()))
.or_default();
entry.push(name.clone());
entry.push((false, name.clone()));
}
_ => (),
}
Expand Down
12 changes: 6 additions & 6 deletions libs/config/tests/errors/simple/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#define QPATHTO(x) QUOTE(PATHTO(x))

class Test {
data = something;
outer = something;
path = PATHTO(thing);
data = "nosemi"
class data {
data = "something";
outer = "nosemi"
class outer {
inner = "something";
};
class Child {
data = "something";
inner = "something";
};
class Child {
data = "something";
inner = "something";
};
};
43 changes: 29 additions & 14 deletions libs/config/tests/errors/simple/stdout.ansi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[CE1] Error: property's value could not be parsed.
╭─[/source.hpp:6:12]
╭─[/source.hpp:6:13]
│
6 │     data = something;
 │ ────┬────
 │ ╰────── invalid value
6 │     outer = something;
 │ ────┬────
 │ ╰────── invalid value
 │
 │ Help: use quotes `"` around the value, or a QUOTE macro if it contains #define values
───╯
Expand All @@ -21,23 +21,38 @@
───╯

[CE4] Error: property is missing a semicolon
╭─[/source.hpp:8:20]
╭─[/source.hpp:8:21]
│
8 │     data = "nosemi"
 │ ┬
 │ ╰── missing semicolon
8 │     outer = "nosemi"
 │ ┬
 │ ╰── missing semicolon
 │
 │ Help: add a semicolon `;` to the end of the property
───╯

[CE3] Error: property was defined more than once
╭─[/source.hpp:6:5]
│
6 │     outer = something;
 │ ──┬──
 │ ╰──── first defined here
 │
8 │     outer = "nosemi"
 │ ──┬──
 │ ╰──── also defined here
9 │     class outer {
 │ ──┬──
 │ ╰──── also defined here
───╯

[CE3] Error: property was defined more than once
╭─[/source.hpp:13:9]
│
13 │         data = "something";
 │ ──┬─
 │ ╰─── first defined here
13 │         inner = "something";
 │ ──┬──
 │ ╰──── first defined here
 │
16 │         data = "something";
 │ ──┬─
 │ ╰─── also defined here
16 │         inner = "something";
 │ ──┬──
 │ ╰──── also defined here
────╯

0 comments on commit 3ec8c3a

Please sign in to comment.