Skip to content

fix: keep blank lines empty when citry format re-indents a Python asset - #456

Merged
JuroOravec merged 2 commits into
mainfrom
fix/format-blank-line-indent
Oct 28, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/format-blank-line-indent

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What this fixes

citry format and the editor's format command write a formatted template, js, or css string 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 as W293:

class Configuration(Component):
    template = """
      <c-CButton>...</c-CButton>
      ⎵⎵⎵⎵⎵⎵
      <p>...</p>
    """

A dry run of citry format over citry_ui found 183 such lines in 78 files. This blocks the repository-wide reformat.

What changes

PythonTemplateSourceMap._canonicalize_multiline_framing in packages/py/citry/citry/analysis.py now 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 runs textwrap.dedent, and dedent already empties a line of spaces and tabs. A line that holds a form feed keeps its indentation, because dedent on Python 3.11 to 3.13 keeps it.

Tests and checks

  • New tests: test_blank_lines_in_a_multiline_template_stay_empty and test_blank_lines_in_a_formatted_js_string_stay_empty. Both fail on main and pass here.
  • test_format_python_templates.py, test_format_python_component_assets.py, test_format_command.py and test_analysis.py pass, and so do the citry_lsp formatting tests.
  • Formatting cbutton/snippets/configuration.py, the file where the problem was first seen, now leaves no whitespace-only line.
  • An independent review compared the loaded templates from main and this branch, under both the Python 3.11 and 3.15 dedent. 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

JuroOravec and others added 2 commits October 27, 2026 17:49
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]>
@JuroOravec
JuroOravec merged commit 33c9531 into main Oct 28, 2026
25 of 31 checks passed
@JuroOravec
JuroOravec deleted the fix/format-blank-line-indent branch October 28, 2026 10:09
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