Repository navigation
fix: keep blank lines empty when citry format re-indents a Python asset - #456
Merged
Merged
Conversation
When `citry format` or the editor writes a multiline template, `js`, or `css` string back into a Python triple-quoted literal, it indents each line to the literal's column. It indented blank lines too, so a blank line that the formatter keeps (for example next to a component tag) came back as trailing spaces, which Ruff flags as W293. A line of only spaces and tabs now stays empty. The loaded asset is unchanged, because `textwrap.dedent`, which loads inline assets, empties such a line anyway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What this fixes
citry formatand the editor's format command write a formattedtemplate,js, orcssstring back into its Python triple-quoted literal. To do that, they indent each line to the literal's column. Blank lines were indented too. So a blank line that the template formatter keeps, for example next to a component tag, came back as a line of trailing spaces, and Ruff reported it asW293:A dry run of
citry formatover citry_ui found 183 such lines in 78 files. This blocks the repository-wide reformat.What changes
PythonTemplateSourceMap._canonicalize_multiline_framinginpackages/py/citry/citry/analysis.pynow leaves a line of only spaces and tabs empty, instead of indenting it. Both template formatting and JS/CSS formatting call this function.The loaded asset does not change. Every reader of an inline asset goes through
normalize_inline_asset, which runstextwrap.dedent, anddedentalready empties a line of spaces and tabs. A line that holds a form feed keeps its indentation, becausededenton Python 3.11 to 3.13 keeps it.Tests and checks
test_blank_lines_in_a_multiline_template_stay_emptyandtest_blank_lines_in_a_formatted_js_string_stay_empty. Both fail onmainand pass here.test_format_python_templates.py,test_format_python_component_assets.py,test_format_command.pyandtest_analysis.pypass, and so do thecitry_lspformatting tests.cbutton/snippets/configuration.py, the file where the problem was first seen, now leaves no whitespace-only line.mainand this branch, under both the Python 3.11 and 3.15dedent. It used<pre>,<textarea>,<c-raw>and<script>content, and a tab-indented file. The loaded templates were identical in every case. The review's findings (the form-feed case, a test for the JS/CSS path, and the wording) are folded in.🤖 Generated with Claude Code