Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/materializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use phenopackets::schema::v2::core::{
pub(crate) struct NodeMaterializer;

impl NodeMaterializer {
pub fn materialize_nodes(&mut self, dyn_node: &DynamicNode, repo: &mut NodeRepository) {
pub fn materialize_nodes(&self, dyn_node: &DynamicNode, repo: &mut NodeRepository) {
if let Some(oc) = OntologyClass::parse(dyn_node) {
Self::push_to_repo(oc, dyn_node, repo);
} else if let Some(pf) = PhenotypicFeature::parse(dyn_node) {
Expand Down
4 changes: 2 additions & 2 deletions src/patches/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait PatchFromContext {
) -> Result<Box<dyn RegisterablePatch>, FromContextError>;
}

impl<T: CompilePatches + Send + RulePatch> RegisterablePatch for T {
impl<T: CompilePatches + RulePatch> RegisterablePatch for T {
fn compile_patches(&self, value: &dyn Node, lint_violation: &LintViolation) -> Vec<Patch> {
CompilePatches::compile_patches(self, value, lint_violation)
}
Expand All @@ -30,6 +30,6 @@ pub trait RulePatch: PatchFromContext + RegisterablePatch + CompilePatches {
}

/// Tries to compile patches for a given rule.
pub trait CompilePatches: Send + Sync {
pub trait CompilePatches {
fn compile_patches(&self, node: &dyn Node, lint_violation: &LintViolation) -> Vec<Patch>;
}
6 changes: 3 additions & 3 deletions src/phenolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Phenolint {
}

impl Lint<str> for Phenolint {
fn lint(&mut self, phenostr: &str, patch: bool, quiet: bool) -> LintResult {
fn lint(&self, phenostr: &str, patch: bool, quiet: bool) -> LintResult {
let mut report = LintReport::default();

let (values, spans, input_type) = match PhenopacketParser::to_abstract_tree(phenostr) {
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Lint<str> for Phenolint {
}

impl Lint<PathBuf> for Phenolint {
fn lint(&mut self, phenopath: &PathBuf, patch: bool, quit: bool) -> LintResult {
fn lint(&self, phenopath: &PathBuf, patch: bool, quit: bool) -> LintResult {
let phenodata = match fs::read(phenopath) {
Ok(phenodata) => phenodata,
Err(err) => {
Expand All @@ -155,7 +155,7 @@ impl Lint<PathBuf> for Phenolint {
}

impl Lint<[u8]> for Phenolint {
fn lint(&mut self, phenodata: &[u8], patch: bool, quit: bool) -> LintResult {
fn lint(&self, phenodata: &[u8], patch: bool, quit: bool) -> LintResult {
let (phenostr, input_type) = match PhenopacketParser::to_string(phenodata) {
Ok(phenostr) => phenostr,
Err(err) => {
Expand Down
4 changes: 2 additions & 2 deletions src/report/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub trait RuleReport: ReportFromContext + RegisterableReport + CompileReport {
const RULE_ID: &'static str;
}

pub trait RegisterableReport {
pub trait RegisterableReport: Send + Sync {
fn compile_report(&self, value: &dyn Node, lint_violation: &LintViolation) -> ReportSpecs;
fn rule_id(&self) -> String;
}

impl<T: CompileReport + Send + RuleReport> RegisterableReport for T {
impl<T: CompileReport + RuleReport> RegisterableReport for T {
fn compile_report(&self, value: &dyn Node, lint_violation: &LintViolation) -> ReportSpecs {
CompileReport::compile_report(self, value, lint_violation)
}
Expand Down
6 changes: 3 additions & 3 deletions src/rules/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait LintRule: RuleFromContext + Send + Sync {
fn check_erased(&self, board: &NodeRepository) -> Vec<LintViolation>;
}

pub trait RuleMetaData: Send + Sync {
pub trait RuleMetaData {
fn rule_id(&self) -> &str;
}

Expand All @@ -19,12 +19,12 @@ pub trait RuleFromContext {
Self: Sized;
}

pub trait RuleCheck: Send + Sync + 'static {
pub trait RuleCheck: 'static {
type Data<'a>: LintData<'a> + ?Sized;
fn check(&self, data: Self::Data<'_>) -> Vec<LintViolation>;
}

impl<T> LintRule for T
impl<T: Send + Sync> LintRule for T
where
T: RuleCheck + RuleFromContext + RuleMetaData,
for<'a> <T as RuleCheck>::Data<'a>: Sized,
Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::LintResult;

pub trait Lint<T: ?Sized> {
fn lint(&mut self, phenodata: &T, patch: bool, quit: bool) -> LintResult;
fn lint(&self, phenodata: &T, patch: bool, quit: bool) -> LintResult;
}
30 changes: 30 additions & 0 deletions tests/use_cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use phenolint::LinterContext;
use phenolint::phenolint::Phenolint;
use phenolint::traits::Lint;
use serde_json::json;
use std::path::PathBuf;
use std::sync::OnceLock;

static PHENOLINT: OnceLock<Phenolint> = OnceLock::new();

#[test]
fn lint_minimal_valid_phenopacket() {
let phenolint = PHENOLINT.get_or_init(init_phenolint);

let value = json!({
"id": "phenopacket",
});
let payload_str = serde_json::to_string(&value).unwrap();

// TODO: is it absolutely necessary for `lint` to take `&mut self`?
let result = phenolint.lint(payload_str.as_str(), true, true);

// TODO: assert properly
eprintln!("{:?}", result);
}

fn init_phenolint() -> Phenolint {
let context = LinterContext::new(Some(PathBuf::from("tests/assets/hp.toy.json")));
let rule_ids = vec!["CURIE001".into(), "INTER001".into()];
Phenolint::new(context, rule_ids)
}
Loading