Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed May 1, 2024
1 parent 036eab7 commit df061bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
51 changes: 30 additions & 21 deletions src/mustache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,17 @@ fn parse_mustache(input: &str) -> IResult<&str, Mustache> {
})(input);
let jq_result = parse_jq(input);
if jq_result.is_err() && result.is_err() {
return Err(
nom::Err::Error(nom::error::Error::new(
"failed to parse mustache",
nom::error::ErrorKind::Tag,
))
);
return Err(nom::Err::Error(nom::error::Error::new(
"failed to parse mustache",
nom::error::ErrorKind::Tag,
)));

Check warning on line 203 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L200-L203

Added lines #L200 - L203 were not covered by tests
}

let (res, jacques) = jq_result.unwrap_or((input, None));
if jacques.is_none() {
let (res, segments) = result.unwrap_or((input, vec![]));
Ok((res, Mustache { segments, jacques }))
}else {
} else {
Ok((res, Mustache { segments: vec![], jacques }))
}
}
Expand All @@ -227,15 +225,26 @@ fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> {
defs.insert_defs(jaq_std::std());

let (filter, errs) = jaq_parse::parse(filter, jaq_parse::main());
let _err_str = errs.iter().map(|v| v.to_string()).collect::<Vec<String>>().join("\n");
let _err_str = errs
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join("\n");
if !errs.is_empty() || filter.is_none() {
return Err(nom::Err::Error(nom::error::Error::new(
"failed to parse jq", // TODO: fix ownership issue and return _err_str
nom::error::ErrorKind::Tag,
)));

Check warning on line 237 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L234-L237

Added lines #L234 - L237 were not covered by tests
}
let filter = defs.compile(filter.unwrap());
Ok((input, if defs.errs.is_empty() { Some(filter) } else { None }))
Ok((
input,
if defs.errs.is_empty() {
Some(filter)
} else {
None

Check warning on line 245 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L245

Added line #L245 was not covered by tests
},
))
}

#[cfg(test)]
Expand Down Expand Up @@ -286,7 +295,7 @@ mod tests {
"hello".to_string(),
"world".to_string(),
])])
.segments
.segments
);
}

Expand All @@ -303,7 +312,7 @@ mod tests {
Segment::Expression(vec!["hello".to_string(), "world".to_string()]),
Segment::Literal("/end".to_string()),
])
.segments
.segments
);
}

Expand All @@ -317,7 +326,7 @@ mod tests {
"foo".to_string(),
"bar".to_string(),
])])
.segments
.segments
);
}

Expand Down Expand Up @@ -402,7 +411,7 @@ mod tests {
"env".to_string(),
"FOO".to_string(),
])])
.segments
.segments
);
}

Expand All @@ -415,7 +424,7 @@ mod tests {
"env".to_string(),
"FOO_BAR".to_string(),
])])
.segments
.segments
);
}

Expand All @@ -438,7 +447,7 @@ mod tests {
"foo".to_string(),
"bar".to_string(),
])])
.segments
.segments
);
}
}
Expand Down Expand Up @@ -467,8 +476,8 @@ mod tests {

impl Serialize for DummyPath {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
serializer.serialize_str("")
}

Check warning on line 483 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L479-L483

Added lines #L479 - L483 were not covered by tests
Expand Down Expand Up @@ -507,8 +516,8 @@ mod tests {

impl Serialize for DummyPath {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
serializer.serialize_str("")
}

Check warning on line 523 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L519-L523

Added lines #L519 - L523 were not covered by tests
Expand Down Expand Up @@ -551,8 +560,8 @@ mod tests {

impl Serialize for DummyPath {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
serializer.serialize_str("")
}

Check warning on line 567 in src/mustache.rs

View check run for this annotation

Codecov / codecov/patch

src/mustache.rs#L563-L567

Added lines #L563 - L567 were not covered by tests
Expand Down
3 changes: 1 addition & 2 deletions src/serde_value_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ mod tests {

#[test]
fn test_mustache_arr_obj_arr() {
let value =
json!([{"a": [{"aa": "{{jq: .foo.bar.baz}}"}]}, {"a": [{"aa": "{{jq: .foo.bar.qux}}"}]}]);
let value = json!([{"a": [{"aa": "{{jq: .foo.bar.baz}}"}]}, {"a": [{"aa": "{{jq: .foo.bar.qux}}"}]}]);
let value = DynamicValue::try_from(&value).unwrap();
let ctx = json!({"foo": {"bar": {"baz": 1, "qux": 2}}});
let result = value.render_value(&ctx);
Expand Down

1 comment on commit df061bb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.47ms 3.32ms 85.53ms 71.44%
Req/Sec 3.38k 179.80 3.68k 94.08%

404221 requests in 30.01s, 2.03GB read

Requests/sec: 13471.16

Transfer/sec: 69.14MB

Please sign in to comment.