You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Ruff统计行长度时忽略注释,避免代码被强制换行?

让Ruff统计行长度时忽略注释内容

要实现统计行长度时仅计算代码字符、忽略注释内容,只需修改Ruff的配置文件(如pyproject.toml或ruff.toml),添加如下配置项:

[tool.ruff.format]
line-length = 79
ignore-comments = true

配置说明:

  • line-length:设置你需要的行长度阈值(示例中为你配置的79)
  • ignore-comments = true:开启后,Ruff计算行长度时会跳过行尾注释,仅统计代码部分的字符长度

配置生效后,你的示例代码:

demo_code = print("foo bar")  # some comments and this line length exceed 79 that i config.

将不会因为注释部分导致行长度超标而被强制换行格式化。

内容的提问来源于stack exchange,提问作者Rubem Pacelli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 00:43:10