-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: jq support #1801
feat: jq support #1801
Conversation
Warning Rate Limit Exceeded@ssddOnTop has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 18 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe updates primarily focus on integrating JAQ, a JSON transformation DSL, as an alternative to mustache templates across various modules. This involves adding new methods for evaluating JAQ filters, modifying mustache syntax, and updating related functionalities in structs and methods to support more complex JSON manipulations. Changes
Assessment against linked issues
The changes make significant strides towards integrating JAQ for JSON transformations, enhancing the flexibility and capabilities of the template system. However, some aspects like benchmarking and compile-time processing of JAQ templates need further clarification or implementation. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1801 +/- ##
==========================================
- Coverage 86.89% 86.60% -0.29%
==========================================
Files 156 156
Lines 15829 16078 +249
==========================================
+ Hits 13754 13924 +170
- Misses 2075 2154 +79 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Out of diff range and nitpick comments (1)
src/mustache.rs (1)
51-66
: Clarify the behavior when the rendered value is empty.Consider adding documentation or unit tests to explain that
evaluate
is used as a fallback when the rendered value is empty. This helps maintain clarity and ensures that future maintainers or users of this method understand its behavior.
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Out of diff range and nitpick comments (1)
src/mustache.rs (1)
Line range hint
44-53
: Theparse
method's fallback mechanism to treat the input as a literal if parsing fails is a good safeguard. However, consider logging the error for debugging purposes.+ Err(e) => { + log::error!("Failed to parse mustache template: {}", e); + Ok(Mustache::from(vec![Segment::Literal(str.to_string())])) + },
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> { | ||
let (input, _) = nom::character::complete::multispace0(input)?; | ||
let (input, _) = tag("{{")(input)?; | ||
let (input, _) = nom::character::complete::multispace0(input)?; | ||
let (input, _) = tag("jq:")(input)?; | ||
let (input, _) = nom::character::complete::multispace0(input)?; | ||
let (input, filter) = take_until("}}")(input)?; | ||
let filter = filter.trim(); | ||
let mut defs = jaq_interpret::ParseCtx::new(vec![]); | ||
defs.insert_natives(jaq_core::core()); | ||
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"); | ||
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, | ||
))); | ||
} | ||
let filter = defs.compile(filter.unwrap()); | ||
Ok((input, Some(filter))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parse_jq
function's error handling could be improved by including the actual error messages collected, which would aid in diagnosing parse failures.
+ "failed to parse jq", // TODO: fix ownership issue and return _err_str
+ _err_str,
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> { | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, _) = tag("{{")(input)?; | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, _) = tag("jq:")(input)?; | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, filter) = take_until("}}")(input)?; | |
let filter = filter.trim(); | |
let mut defs = jaq_interpret::ParseCtx::new(vec![]); | |
defs.insert_natives(jaq_core::core()); | |
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"); | |
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, | |
))); | |
} | |
let filter = defs.compile(filter.unwrap()); | |
Ok((input, Some(filter))) | |
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> { | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, _) = tag("{{")(input)?; | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, _) = tag("jq:")(input)?; | |
let (input, _) = nom::character::complete::multispace0(input)?; | |
let (input, filter) = take_until("}}")(input)?; | |
let filter = filter.trim(); | |
let mut defs = jaq_interpret::ParseCtx::new(vec![]); | |
defs.insert_natives(jaq_core::core()); | |
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"); | |
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 | |
_err_str, | |
nom::error::ErrorKind::Tag, | |
))); | |
} | |
let filter = defs.compile(filter.unwrap()); | |
Ok((input, Some(filter))) |
/tip 300$ |
🎉🎈 @ssddOnTop has been awarded $300! 🎈🎊 |
Issue Reference(s):
Fixes #1321
/claim #1321
Summary by CodeRabbit
New Features
Bug Fixes
Documentation