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 clippy_check.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cargo clippy --workspace --locked -- -D warnings -A clippy::too_many_arguments -A clippy::let-and-return -A clippy::module-inception -A clippy::new-ret-no-self -A clippy::wrong-self-convention -A clippy::large-enum-variant -A clippy::inherent-to-string -A clippy::inherent_to_string_shadow_display
cargo clippy --workspace --locked -- -D warnings -D clippy::unwrap_used -A clippy::too_many_arguments -A clippy::let-and-return -A clippy::module-inception -A clippy::new-ret-no-self -A clippy::wrong-self-convention -A clippy::large-enum-variant -A clippy::inherent-to-string -A clippy::inherent_to_string_shadow_display
3 changes: 3 additions & 0 deletions helix-db/src/helixc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//TODO: remove unwraps in helixc
#![allow(clippy::unwrap_used)]

pub mod analyzer;
pub mod generator;
pub mod parser;
20 changes: 1 addition & 19 deletions helix-db/src/helixc/parser/helix_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{
location::{HasLoc, Loc},
parser_methods::ParserError,
};
use crate::protocol::value::Value;
use crate::{helix_engine::types::GraphError, protocol::value::Value};
use chrono::{DateTime, NaiveDate, Utc};
use pest::{
Parser as PestParser,
Expand Down Expand Up @@ -2578,21 +2578,3 @@ impl HelixParser {
})
}
}

pub fn write_to_temp_file(content: Vec<&str>) -> Content {
let mut files = Vec::new();
for c in content {
let mut file = tempfile::NamedTempFile::new().unwrap();
file.write_all(c.as_bytes()).unwrap();
let path = file.path().to_string_lossy().into_owned();
files.push(HxFile {
name: path,
content: c.to_string(),
});
}
Content {
content: String::new(),
files,
source: Source::default(),
}
}
1 change: 0 additions & 1 deletion helix-db/src/helixc/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ pub mod parser_methods;

#[cfg(test)]
mod parser_tests;

26 changes: 25 additions & 1 deletion helix-db/src/helixc/parser/parser_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use super::helix_parser::{Content, FieldType, HelixParser, Source, write_to_temp_file};
#![allow(clippy::unwrap_used)]

use std::io::Write;

use crate::helixc::parser::helix_parser::HxFile;

use super::helix_parser::{Content, FieldType, HelixParser, Source};

#[test]
fn test_parse_node_schema() {
Expand Down Expand Up @@ -910,3 +916,21 @@ fn test_search_vector() {
let query = &result.queries[0];
assert_eq!(query.return_values.len(), 1);
}

pub fn write_to_temp_file(content: Vec<&str>) -> Content {
let mut files = Vec::new();
for c in content {
let mut file = tempfile::NamedTempFile::new().unwrap();
file.write_all(c.as_bytes()).unwrap();
let path = file.path().to_string_lossy().into_owned();
files.push(HxFile {
name: path,
content: c.to_string(),
});
}
Content {
content: String::new(),
files,
source: Source::default(),
}
}
4 changes: 3 additions & 1 deletion helix-db/src/protocol/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ impl Format {
/// is compatible with the chosen format to avoid panics.
pub fn serialize<T: Serialize>(self, val: &T) -> Cow<[u8]> {
match self {
Format::Json => sonic_rs::to_vec(val).unwrap().into(),
Format::Json => sonic_rs::to_vec(val)
.expect("All Helix types should infallibally convert to Json")
.into(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions helix-db/src/protocol/return_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ where
"label".to_string(),
ReturnValue::from(item.label().to_string()),
);
if item.properties_ref().is_some() {

if let Some(item_props) = item.properties() {
properties.extend(
item.properties()
.unwrap()
item_props
.into_iter()
.map(|(k, v)| (k, ReturnValue::from(v))),
);
Expand Down
13 changes: 6 additions & 7 deletions helix-db/src/protocol/value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::id::ID;
use crate::{helix_engine::types::GraphError, helixc::generator::utils::GenRef};
use chrono::Utc;
use serde::{
Expand All @@ -11,8 +12,6 @@ use std::{
collections::HashMap,
fmt::{self, Display},
};
use crate::utils::id::ID;


/// A flexible value type that can represent various property values in nodes and edges.
/// Handles both JSON and binary serialisation formats via custom implementaions of the Serialize and Deserialize traits.
Expand Down Expand Up @@ -910,12 +909,12 @@ impl From<JsonValue> for Value {
match v {
JsonValue::String(s) => Value::String(s),
JsonValue::Number(n) => {
if n.is_u64() {
Value::U64(n.as_u64().unwrap())
} else if n.is_i64() {
Value::I64(n.as_i64().unwrap())
if let Some(u) = n.as_u64() {
Value::U64(u)
} else if let Some(i) = n.as_i64() {
Value::I64(i)
} else {
Value::F64(n.as_f64().unwrap())
Value::F64(n.as_f64().expect("Number must be either a u64, i64 or f64, the first two have been excluded so it must be an f64"))
}
}
JsonValue::Bool(b) => Value::Boolean(b),
Expand Down
Loading