-
Notifications
You must be signed in to change notification settings - Fork 49
feat(kleros-sdk): predefined-lambdas-for-mustache #2024
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
base: dev
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for kleros-v2-testnet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for kleros-v2-neo ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
""" WalkthroughA new utility object named Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant populateTemplate
participant Mustache
participant lambdas
Caller->>populateTemplate: Call with (mustacheTemplate, data)
populateTemplate->>lambdas: Import lambdas
populateTemplate->>Mustache: Render template with { ...data, ...lambdas }
Mustache->>lambdas: Call hex lambda (if used in template)
Mustache->>populateTemplate: Return rendered string
populateTemplate->>Caller: Return parsed and validated result
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (13)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
❌ Deploy Preview for kleros-v2-university failed. Why did it fail? →
|
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: 2
🧹 Nitpick comments (2)
kleros-sdk/src/dataMappings/utils/lambdas.ts (2)
6-9
: Guard against negative / large numbers and drop redundant.toLowerCase()
parseInt
preserves the sign; for negative values you’ll end up with"-0x…"
.
Clarify whether that is intended or bail out for< 0
.
num.toString(16)
already yields lowercase, so the extra.toLowerCase()
is dead code.If negative numbers are not expected, short-circuit early:
- if (!isNaN(num)) { - return "0x" + num.toString(16).toLowerCase(); + if (!Number.isNaN(num) && num >= 0) { + return `0x${num.toString(16)}`; }
1-13
: Add unit tests for the new lambda
lambdas.hex
is a user-facing helper; edge-cases (non-numeric strings, negative numbers, 0, large ints) deserve automated tests to prevent regressions.
Consider placing them alongside existing template-population tests.🧰 Tools
🪛 Biome (1.9.4)
[error] 4-4: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
kleros-sdk/src/dataMappings/utils/lambdas.ts
(1 hunks)kleros-sdk/src/dataMappings/utils/populateTemplate.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: kleros-sdk/src/utils/getDispute.ts:43-43
Timestamp: 2024-10-14T15:29:32.954Z
Learning: In the Kleros SDK, when using the `populateTemplate` function in `kleros-sdk/src/utils/getDispute.ts`, missing variables in Mustache templates are acceptable. Mustache fills in blanks, and it's preferable to return the partially populated template without throwing errors, as it's still helpful for the consumer.
🧬 Code Graph Analysis (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)
kleros-sdk/src/dataMappings/utils/lambdas.ts (1)
lambdas
(1-13)
🪛 Biome (1.9.4)
kleros-sdk/src/dataMappings/utils/lambdas.ts
[error] 4-4: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
⏰ Context from checks skipped due to timeout of 90000ms (16)
- GitHub Check: Redirect rules - kleros-v2-university
- GitHub Check: Header rules - kleros-v2-university
- GitHub Check: Pages changed - kleros-v2-university
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-neo
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-neo
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-neo
- GitHub Check: Analyze (javascript)
- GitHub Check: SonarCloud
- GitHub Check: contracts-testing
- GitHub Check: Mend Security Check
🔇 Additional comments (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)
4-4
: Import looks goodStraightforward addition of the shared
lambdas
util.
✅ Deploy Preview for kleros-v2-testnet-devtools ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Climate has analyzed commit 33a47a9 and detected 3 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
|
PR-Codex overview
This PR introduces a new utility function for converting values to hex representation and integrates it into the
populateTemplate
function to enhance data rendering capabilities.Detailed summary
lambdas
object inlambdas.ts
with ahex
function.hex
function converts a string value to its hexadecimal representation.populateTemplate
function to includelambdas
in the rendering process.Summary by CodeRabbit