improved dummy macros handling of spaces in parameters strings values#239
Open
improved dummy macros handling of spaces in parameters strings values#239
Conversation
Contributor
Reviewer's GuideThis PR simplifies the dummy macro parameter mappings by removing explicit empty‐string fallbacks and applies the Jinja xmlattr filter to properly quote values containing spaces in the rendered G-code commands. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `shaketune/dummy_macros.cfg:32` </location>
<code_context>
+ "ACCEL_CHIP": accel_chip
} %}
- _EXCITATE_AXIS_AT_FREQ {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}{key}={value} {% endfor %}
+ _EXCITATE_AXIS_AT_FREQ {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}{key}={{ value|xmlattr }} {% endfor %}
</code_context>
<issue_to_address>
**suggestion:** Use of xmlattr filter may alter output formatting for non-string values.
Check that xmlattr produces the correct output for all parameter types, especially if consumers rely on specific formats for numeric or boolean values.
Suggested implementation:
```
_EXCITATE_AXIS_AT_FREQ {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}
{%- if value is number -%}
{{ key }}={{ value|float|xmlattr }}
{%- elif value is boolean -%}
{{ key }}={{ value|int|xmlattr }}
{%- else -%}
{{ key }}={{ value|xmlattr }}
{%- endif -%}
{% endfor %}
```
If your Jinja environment does not support `is number` or `is boolean` tests, you may need to implement custom filters or use type checks available in your templating engine. Also, ensure that the consumers of this macro expect floats for numbers and 0/1 for booleans.
</issue_to_address>
### Comment 2
<location> `shaketune/dummy_macros.cfg:66` </location>
<code_context>
+ "ACCEL_CHIP": accel_chip
} %}
- _COMPARE_BELTS_RESPONSES {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}{key}={value} {% endfor %}
+ _COMPARE_BELTS_RESPONSES {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}{key}={{ value|xmlattr }} {% endfor %}
</code_context>
<issue_to_address>
**suggestion:** Consistent use of xmlattr filter may require review for all parameter types.
Verify that xmlattr handles all parameter types correctly, especially for complex objects or those with special characters. Use a more specific filter if needed.
Suggested implementation:
```
_COMPARE_BELTS_RESPONSES {% for key, value in params_filtered.items() if value is defined and value is not none and value != '' %}
{%- if value is string or value is number -%}
{{ key }}={{ value|xmlattr }}
{%- else -%}
{{ key }}={{ value|tojson }}
{%- endif -%}
{% endfor %}
```
- If you have custom types or need to handle special serialization, consider implementing a custom Jinja filter for those cases.
- Ensure that the macro consumer can handle JSON-encoded values if any parameters are complex objects.
- If you use other macros or templates with similar parameter serialization, apply the same logic for consistency.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
01229ad to
8a935d8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve dummy macros parameter handling by removing empty-string fallbacks and applying xmlattr filtering to properly quote and escape values with spaces.
Enhancements: