Skip to content

Commit

Permalink
fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Dec 19, 2024
1 parent 2d5be4b commit a9fafa7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/datamodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl DataModel {
/// ```
/// # Returns
/// A data model
#[allow(clippy::result_large_err)]
pub fn from_markdown(path: &Path) -> Result<Self, Validator> {
let content = fs::read_to_string(path).expect("Could not read file");
parse_markdown(&content)
Expand All @@ -326,6 +327,7 @@ impl DataModel {
/// ```
/// # Returns
/// A data model
#[allow(clippy::result_large_err)]
pub fn from_markdown_string(content: &str) -> Result<Self, Validator> {
parse_markdown(content)
}
Expand Down
5 changes: 5 additions & 0 deletions src/markdown/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ use crate::validation::Validator;

use super::frontmatter::parse_frontmatter;

#[cfg(feature = "python")]
use pyo3::pyclass;

lazy_static! {
static ref MD_MODEL_TYPES: BTreeMap<&'static str, &'static str> = {
let mut m = BTreeMap::new();
Expand Down Expand Up @@ -85,6 +88,7 @@ enum ParserState {

// Add this struct to track positions
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "python", pyclass(get_all))]
pub struct Position {
pub line: usize,
pub range: (usize, usize),
Expand All @@ -99,6 +103,7 @@ pub struct Position {
/// # Returns
///
/// A `Result` containing a `DataModel` on success or an error on failure.
#[allow(clippy::result_large_err)]
pub fn parse_markdown(content: &str) -> Result<DataModel, Validator> {
// Remove HTML and links
let content = clean_content(content);
Expand Down
21 changes: 9 additions & 12 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Display for ValidationError {
.collect();
let mut line = lines.join(", ");

if lines.len() > 0 {
if !lines.is_empty() {
line = format!("[line: {}]", line);
} else {
line = "".to_string();
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Validator {

// Validate the attributes of the object
object.attributes.iter().for_each(|attribute| {
self.validate_attribute(attribute, types, &object);
self.validate_attribute(attribute, types, object);
});
}

Expand Down Expand Up @@ -393,7 +393,7 @@ impl Validator {
}

for dtype in &attribute.dtypes {
self.check_attr_dtype(attribute, types, object, &dtype);
self.check_attr_dtype(attribute, types, object, dtype);
}
}

Expand Down Expand Up @@ -600,9 +600,9 @@ fn extract_object_positions(model: &DataModel) -> HashMap<String, Vec<Position>>
}

if let Some(pos) = positions.get_mut(&object.name) {
pos.push(object.position.clone().unwrap());
pos.push(object.position.unwrap());
} else {
positions.insert(object.name.clone(), vec![object.position.clone().unwrap()]);
positions.insert(object.name.clone(), vec![object.position.unwrap()]);
}
}
positions
Expand All @@ -625,9 +625,9 @@ fn extract_enum_positions(model: &DataModel) -> HashMap<String, Vec<Position>> {
}

if let Some(pos) = positions.get_mut(&enum_.name) {
pos.push(enum_.position.clone().unwrap());
pos.push(enum_.position.unwrap());
} else {
positions.insert(enum_.name.clone(), vec![enum_.position.clone().unwrap()]);
positions.insert(enum_.name.clone(), vec![enum_.position.unwrap()]);
}
}
positions
Expand All @@ -650,12 +650,9 @@ fn extract_attribute_positions(object: &Object) -> HashMap<String, Vec<Position>
}

if let Some(pos) = positions.get_mut(&attribute.name) {
pos.push(attribute.position.clone().unwrap());
pos.push(attribute.position.unwrap());
} else {
positions.insert(
attribute.name.clone(),
vec![attribute.position.clone().unwrap()],
);
positions.insert(attribute.name.clone(), vec![attribute.position.unwrap()]);
}
}
positions
Expand Down

0 comments on commit a9fafa7

Please sign in to comment.