-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Summary
Issue Description:
The Ruff formatter incorrectly wraps lines containing Google Colab's @param form comments, which breaks their rendering and functionality in Jupyter Notebooks.
The problem
In Google Colab, you can create interactive forms with @param to parameterize your code using a special comment syntax, like this:
PROJECT_ID = "[your-project-id]" # @param {type: "string", placeholder: "[your-project-id]", isTemplate: true}When a line like this exceeds the configured line-length, ruff format will wrap it, like this:
PROJECT_ID = (
"[your-project-id]" # @param {type: "string", placeholder: "[your-project-id]", isTemplate: true}
)This wrapped code is valid Python, but it is no longer correctly interpreted by Colab, and the interactive form element will not render.
Proposed Solution
It would be beneficial to have an option to prevent the formatter from breaking these specific lines. A possible solution could be a new configuration option that would allow users to specify patterns for comments that should disable line-length formatting for that line. This would allow ruff to automatically ignore lines with @param comments without manual intervention.
Workaround
For users experiencing this issue, a temporary workaround is to use # fmt: off and # fmt: on to disable formatting for these specific lines:
# fmt: off
PROJECT_ID = "[your-project-id]" # @param {type: "string", placeholder: "[your-project-id]", isTemplate: true}
# fmt: onNote: Adding # fmt: skip to the individual lines also causes the formatting to be incorrect in Colab.
While this works, it requires manually adding these comments around every @param line that is too long, which can be cumbersome and adds visual noise.