Skip to content
Merged
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Formatting-only commits, skipped by `git blame` (GitHub applies this file
# automatically; locally: git config blame.ignoreRevsFile .git-blame-ignore-revs).

# style: cargo fmt --all
b9b520d74562afa6e7f32606df5d3e480604639d
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ on:
- main

jobs:
lint:
name: Format and Clippy
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all --check

- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings

build-native:
name: Build and Test (Native)
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ members = [
resolver = "2"
exclude = ["turtle"]

[workspace.lints.clippy]
# Bevy systems take their data as parameters, so system signatures naturally
# have many parameters and nested `Query<(…), (…)>` types.
type_complexity = "allow"
too_many_arguments = "allow"
3 changes: 3 additions & 0 deletions components-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = tr
anyhow = { version = "1", optional = true }
rdf-parsers.workspace = true
url = "2"

[lints]
workspace = true
14 changes: 8 additions & 6 deletions components-rs/src/components/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ struct CollectedNode {
resolver: ContextResolver,
}

impl Default for ComponentRegistry {
fn default() -> Self {
Self::new()
}
}

impl ComponentRegistry {
pub fn new() -> Self {
Self {
Expand All @@ -162,8 +168,7 @@ impl ComponentRegistry {
state: &ModuleState,
) -> Result<()> {
let mut all_nodes: HashMap<String, CollectedNode> = HashMap::new();
let mut visited_files: std::collections::HashSet<Url> =
std::collections::HashSet::new();
let mut visited_files: std::collections::HashSet<Url> = std::collections::HashSet::new();
let mut id_spans: HashMap<String, Range<usize>> = HashMap::new();
let mut id_source_files: HashMap<String, String> = HashMap::new();
let mut file_sources: HashMap<String, String> = HashMap::new();
Expand All @@ -187,10 +192,7 @@ impl ComponentRegistry {
)
.await?;
} else {
tracing::warn!(
"Component file does not exist: {}",
component_url.as_str()
);
tracing::warn!("Component file does not exist: {}", component_url.as_str());
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions components-rs/src/components/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use std::ops::Range;

use rdf_parsers::jsonld::convert::JsonLdVal;

pub const PREFIX_OO: &str =
"https://linkedsoftwaredependencies.org/vocabularies/object-oriented#";
pub const PREFIX_OM: &str =
"https://linkedsoftwaredependencies.org/vocabularies/object-mapping#";
pub const PREFIX_OO: &str = "https://linkedsoftwaredependencies.org/vocabularies/object-oriented#";
pub const PREFIX_OM: &str = "https://linkedsoftwaredependencies.org/vocabularies/object-mapping#";
pub const PREFIX_RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
pub const PREFIX_RDFS: &str = "http://www.w3.org/2000/01/rdf-schema#";
pub const PREFIX_XSD: &str = "http://www.w3.org/2001/XMLSchema#";
Expand Down
9 changes: 8 additions & 1 deletion components-rs/src/config/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub struct ConfigRegistry {
pub configs: Vec<ConfigInstance>,
}

impl Default for ConfigRegistry {
fn default() -> Self {
Self::new()
}
}

impl ConfigRegistry {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -76,7 +82,8 @@ impl ConfigRegistry {
let mut id_spans: HashMap<String, Range<usize>> = HashMap::new();
collect_id_spans(&doc, &resolver, &mut id_spans);

self.process_imports(fs, &doc, &resolver, state, url).await?;
self.process_imports(fs, &doc, &resolver, state, url)
.await?;

let entries: Vec<&JsonLdVal> = if let Some(graph) = doc.get("@graph") {
match graph.as_array() {
Expand Down
44 changes: 32 additions & 12 deletions components-rs/src/context/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ impl ContextResolver {
Ok(())
}

fn load_context_object(&mut self, obj: &JsonLdVal, known_contexts: &HashMap<String, JsonLdVal>) -> Result<()> {
fn load_context_object(
&mut self,
obj: &JsonLdVal,
known_contexts: &HashMap<String, JsonLdVal>,
) -> Result<()> {
let members = obj
.as_object()
.ok_or_else(|| ComponentsJsError::ContextResolution("Expected object".into()))?;
Expand Down Expand Up @@ -124,8 +128,10 @@ impl ContextResolver {
if let Some(id) = val.get("@id").and_then(|v| v.as_str()) {
let type_coercion =
val.get("@type").and_then(|v| v.as_str()).map(String::from);
let container =
val.get("@container").and_then(|v| v.as_str()).map(String::from);
let container = val
.get("@container")
.and_then(|v| v.as_str())
.map(String::from);
self.terms.insert(
key.clone(),
TermDef {
Expand Down Expand Up @@ -196,7 +202,7 @@ impl ContextResolver {
let expanded_base = self.expand_term(base_iri);
if let Some(suffix) = iri.strip_prefix(expanded_base.as_str()) {
let base_len = expanded_base.len();
if best.as_ref().is_none_or(|(_, bl)| base_len > *bl) {
if best.as_ref().map_or(true, |(_, bl)| base_len > *bl) {
best = Some((format!("{prefix}:{suffix}"), base_len));
}
}
Expand Down Expand Up @@ -249,7 +255,7 @@ impl IriCompactor {
(name.clone(), expanded)
})
.collect();
prefixes.sort_by(|a, b| b.1.len().cmp(&a.1.len()));
prefixes.sort_by_key(|p| std::cmp::Reverse(p.1.len()));

let terms: Vec<(String, String)> = resolver
.terms
Expand Down Expand Up @@ -411,7 +417,8 @@ mod tests {
use rdf_parsers::jsonld::convert::parse_json;

fn make_cjs_context() -> HashMap<String, JsonLdVal> {
let ctx_json = parse_json(r#"{
let ctx_json = parse_json(
r#"{
"@context": {
"oo": "https://linkedsoftwaredependencies.org/vocabularies/object-oriented#",
"Module": { "@id": "oo:Module" },
Expand All @@ -426,7 +433,8 @@ mod tests {
"requireElement": { "@id": "oo:componentPath" },
"import": { "@id": "rdfs:seeAlso", "@type": "@id" }
}
}"#)
}"#,
)
.unwrap();
let mut known = HashMap::new();
known.insert(
Expand Down Expand Up @@ -473,8 +481,14 @@ mod tests {
]"#).unwrap();
let resolver = ContextResolver::from_context_value(&ctx_ref, &known).unwrap();

assert_eq!(resolver.expand_term("ex:MyModule"), "http://example.org/MyModule");
assert_eq!(resolver.expand_term("hello:say"), "http://example.org/hello/say");
assert_eq!(
resolver.expand_term("ex:MyModule"),
"http://example.org/MyModule"
);
assert_eq!(
resolver.expand_term("hello:say"),
"http://example.org/hello/say"
);
}

#[test]
Expand Down Expand Up @@ -508,7 +522,10 @@ mod tests {
let nodes = extract_graph_nodes(&doc, &known).unwrap();
assert_eq!(nodes.len(), 1);
let module = &nodes[0];
assert_eq!(module.id.as_deref(), Some("http://example.org/HelloWorldModule"));
assert_eq!(
module.id.as_deref(),
Some("http://example.org/HelloWorldModule")
);
assert_eq!(
module.types,
vec!["https://linkedsoftwaredependencies.org/vocabularies/object-oriented#Module"]
Expand All @@ -518,10 +535,13 @@ mod tests {
#[test]
fn test_vocab_expansion() {
let known = HashMap::new();
let ctx = parse_json(r#"{
let ctx = parse_json(
r#"{
"@vocab": "https://linkedsoftwaredependencies.org/vocabularies/object-oriented#",
"ex": "http://example.org/"
}"#).unwrap();
}"#,
)
.unwrap();
let resolver = ContextResolver::from_context_value(&ctx, &known).unwrap();

assert_eq!(
Expand Down
51 changes: 27 additions & 24 deletions components-rs/src/discovery/node_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ pub fn build_node_module_import_paths(main_module_path: &Url) -> Vec<Url> {
let mut paths = Vec::new();
let mut current = main_module_path.clone();
paths.push(current.clone());
loop {
let parent = match current.join("..") {
Ok(p) => p,
Err(_) => break,
};
while let Ok(parent) = current.join("..") {
if parent == current {
break;
}
Expand All @@ -35,11 +31,7 @@ pub fn build_node_module_import_paths(main_module_path: &Url) -> Vec<Url> {
// findFiles to scan the entire filesystem, which hangs the build.
// Two non-empty path segments (/home/user/) is the practical floor
// for any project-relevant node_modules location.
let depth = current
.path()
.split('/')
.filter(|s| !s.is_empty())
.count();
let depth = current.path().split('/').filter(|s| !s.is_empty()).count();
if depth < 2 {
break;
}
Expand Down Expand Up @@ -78,7 +70,10 @@ pub async fn build_node_module_paths(
result.len(),
);
}
tracing::info!("[node_modules] build_node_module_paths returning {} paths", result.len());
tracing::info!(
"[node_modules] build_node_module_paths returning {} paths",
result.len()
);
Ok(result)
}

Expand All @@ -92,16 +87,20 @@ async fn scan_import_path(
visited: &mut HashSet<Url>,
recursive: bool,
) -> Result<()> {
let flat = fs.glob(import_path, "node_modules/*/package.json")
let flat = fs
.glob(import_path, "node_modules/*/package.json")
.await
.unwrap_or_default();
let scoped = fs.glob(import_path, "node_modules/@*/*/package.json")
let scoped = fs
.glob(import_path, "node_modules/@*/*/package.json")
.await
.unwrap_or_default();

tracing::info!(
"[node_modules] scan_import_path {}: flat={} scoped={}",
import_path.as_str(), flat.len(), scoped.len(),
import_path.as_str(),
flat.len(),
scoped.len(),
);

let mut added = 0usize;
Expand All @@ -110,7 +109,10 @@ async fn scan_import_path(
// from the glob result. Using rfind('/') is unambiguous; url.join(".")
// can misbehave depending on whether the URL has a trailing slash.
let Some(pkg_dir) = package_json_url_to_dir(&entry.path) else {
tracing::warn!("[node_modules] failed to derive dir from {}", entry.path.as_str());
tracing::warn!(
"[node_modules] failed to derive dir from {}",
entry.path.as_str()
);
continue;
};
if visited.insert(pkg_dir.clone()) {
Expand All @@ -121,7 +123,11 @@ async fn scan_import_path(
}
}
}
tracing::info!("[node_modules] scan_import_path {} added {} new packages", import_path.as_str(), added);
tracing::info!(
"[node_modules] scan_import_path {} added {} new packages",
import_path.as_str(),
added
);

Ok(())
}
Expand All @@ -143,19 +149,16 @@ mod tests {

#[test]
fn test_package_json_url_to_dir() {
let flat = Url::parse(
"file:///home/user/project/node_modules/lodash/package.json",
)
.unwrap();
let flat =
Url::parse("file:///home/user/project/node_modules/lodash/package.json").unwrap();
assert_eq!(
package_json_url_to_dir(&flat).unwrap().as_str(),
"file:///home/user/project/node_modules/lodash/",
);

let scoped = Url::parse(
"file:///home/user/project/node_modules/%40types/node/package.json",
)
.unwrap();
let scoped =
Url::parse("file:///home/user/project/node_modules/%40types/node/package.json")
.unwrap();
assert_eq!(
package_json_url_to_dir(&scoped).unwrap().as_str(),
"file:///home/user/project/node_modules/%40types/node/",
Expand Down
16 changes: 13 additions & 3 deletions components-rs/src/discovery/package_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ pub async fn read_package_jsons(
fs: &dyn Fs,
module_paths: &[Url],
) -> Result<HashMap<Url, PackageJson>> {
tracing::info!("[package_json] read_package_jsons called with {} paths", module_paths.len());
tracing::info!(
"[package_json] read_package_jsons called with {} paths",
module_paths.len()
);
let mut result = HashMap::new();
for module_path in module_paths {
let pkg_url = match module_path.join("package.json") {
Ok(u) => u,
Err(e) => {
tracing::warn!("[package_json] failed to join package.json onto {}: {}", module_path.as_str(), e);
tracing::warn!(
"[package_json] failed to join package.json onto {}: {}",
module_path.as_str(),
e
);
continue;
}
};
Expand All @@ -122,7 +129,10 @@ pub async fn read_package_jsons(
};
result.insert(module_path.clone(), pkg);
}
tracing::info!("[package_json] read_package_jsons parsed {} package.json files", result.len());
tracing::info!(
"[package_json] read_package_jsons parsed {} package.json files",
result.len()
);
Ok(result)
}

Expand Down
3 changes: 3 additions & 0 deletions conformance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ sophia_api.workspace = true
sophia_iri.workspace = true
sophia_turtle = "0.9.0"
sophia_inmem = "0.9.0"

[lints]
workspace = true
Loading
Loading