Skip to content

improved dummy macros handling of spaces in parameters strings values#239

Open
Frix-x wants to merge 1 commit intomainfrom
space-strings
Open

improved dummy macros handling of spaces in parameters strings values#239
Frix-x wants to merge 1 commit intomainfrom
space-strings

Conversation

@Frix-x
Copy link
Owner

@Frix-x Frix-x commented Sep 25, 2025

Improve dummy macros parameter handling by removing empty-string fallbacks and applying xmlattr filtering to properly quote and escape values with spaces.

Enhancements:

  • Remove empty-string fallback logic for None macro parameters across dummy macros
  • Apply xmlattr filter to macro parameter outputs for proper quoting and escaping of values containing spaces

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 25, 2025

Reviewer's Guide

This 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

Change Details Files
Removed redundant conditional defaults in parameter dictionaries
  • Eliminated "if ... is not none else ''" wrappers for all optional params
  • Simplified assignments for ACCEL_PER_HZ, Z_HEIGHT, ACCEL_CHIP, FREQ_START, FREQ_END, MAX_SCALE, SCV, MAX_SMOOTHING
  • Unified behavior so undefined or None params simply remain None
  • Reduced boilerplate across all dummy macros
shaketune/dummy_macros.cfg
Applied xmlattr filter in Jinja loops for safe value quoting
  • Replaced {key}={value} with `{key}={{ value
xmlattr }}` in macro expansions
  • Ensured parameters with spaces are escaped and quoted properly
  • Updated loops in _EXCITATE_AXIS_AT_FREQ, _COMPARE_BELTS_RESPONSES, _AXES_SHAPER_CALIBRATION

  • Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

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

    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>

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    cursor[bot]

    This comment was marked as duplicate.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant