python的ruff简单使用

Ruff 是一个用 Rust 编写的高性能 Python 静态分析工具和代码格式化工具。它旨在提供快速的代码检查和格式化功能,同时支持丰富的配置选项和与现有工具的兼容性。ruff是用rust实现的python Linter&Formatter。

安装:

conda install -c conda-forge ruff     

# pip
pip install ruff

它可以作为代码检查工具和代码格式化工具使用

  • 运行代码检查

    ruff check .
    

    检查并修复:

    ruff check . --fix
    
  • 运行代码格式化

    ruff format .
    

Ruff 支持通过 pyproject.toml 文件进行配置。

创建pyproject.py文件,并写入:

[tool.ruff]
line-length = 120
[tool.ruff.lint]
select = ["E", "F", "W"]  # 启用特定的检查规则
ignore = ["W191"]

[tool.ruff.format]
quote-style = "single"
indent-style = "tab"
docstring-code-format = true

上面表示使用F,E,W规则,忽略w191规则。代码格式化采用单引号、缩进使用tab等。

在这里插入图片描述

代码规范与美观: Python Linter (Ruff) 和 Formatter (Black) - 知乎 (zhihu.com)

大一统的 Ruff: All-in-One Linter & Formatter for Python - 知乎 (zhihu.com)

The Ruff Formatter | Ruff (astral.sh)

astral-sh/ruff: An extremely fast Python linter and code formatter, written in Rust. (github.com)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

田乐蒙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值