jsondoclint: Check links
field
This commit is contained in:
parent
cef44f5303
commit
c1b8eff4d3
@ -60,6 +60,8 @@ impl<'a> Validator<'a> {
|
||||
|
||||
fn check_item(&mut self, id: &'a Id) {
|
||||
if let Some(item) = &self.krate.index.get(id) {
|
||||
item.links.values().for_each(|id| self.add_any_id(id));
|
||||
|
||||
match &item.inner {
|
||||
ItemEnum::Import(x) => self.check_import(x),
|
||||
ItemEnum::Union(x) => self.check_union(x),
|
||||
@ -376,6 +378,10 @@ impl<'a> Validator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_any_id(&mut self, id: &'a Id) {
|
||||
self.add_id_checked(id, |_| true, "any kind of item");
|
||||
}
|
||||
|
||||
fn add_field_id(&mut self, id: &'a Id) {
|
||||
self.add_id_checked(id, Kind::is_struct_field, "StructField");
|
||||
}
|
||||
@ -446,3 +452,6 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
50
src/tools/jsondoclint/src/validator/tests.rs
Normal file
50
src/tools/jsondoclint/src/validator/tests.rs
Normal file
@ -0,0 +1,50 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rustdoc_json_types::{Crate, Item, Visibility};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[track_caller]
|
||||
fn check(krate: &Crate, errs: &[Error]) {
|
||||
let mut validator = Validator::new(krate);
|
||||
validator.check_crate();
|
||||
|
||||
assert_eq!(errs, &validator.errs[..]);
|
||||
}
|
||||
|
||||
fn id(s: &str) -> Id {
|
||||
Id(s.to_owned())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_on_missing_links() {
|
||||
let k = Crate {
|
||||
root: id("0"),
|
||||
crate_version: None,
|
||||
includes_private: false,
|
||||
index: HashMap::from_iter([(
|
||||
id("0"),
|
||||
Item {
|
||||
name: Some("root".to_owned()),
|
||||
id: id(""),
|
||||
crate_id: 0,
|
||||
span: None,
|
||||
visibility: Visibility::Public,
|
||||
docs: None,
|
||||
links: HashMap::from_iter([("Not Found".to_owned(), id("1"))]),
|
||||
attrs: vec![],
|
||||
deprecation: None,
|
||||
inner: ItemEnum::Module(Module {
|
||||
is_crate: true,
|
||||
items: vec![],
|
||||
is_stripped: false,
|
||||
}),
|
||||
},
|
||||
)]),
|
||||
paths: HashMap::new(),
|
||||
external_crates: HashMap::new(),
|
||||
format_version: rustdoc_json_types::FORMAT_VERSION,
|
||||
};
|
||||
|
||||
check(&k, &[Error { kind: ErrorKind::NotFound, id: id("1") }]);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user