astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.81k stars 1.1k forks source link

I want a universal configuration that most people are used to. #13433

Open lqllife opened 1 month ago

lqllife commented 1 month ago

I just started using ruff and never used black before, so I want to ask if there are any standard, commonly used and easy-to-use rules. I searched for a long time in the issue but couldn't find it, so I'm asking. Please give me some ready-made rules, preferably with some brief descriptions, thank you. Here are my pyproject.toml configuration.

[project]
name = "flask_test"
version = "0.1.0"
description = "falsk test"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "flask~=2.3.2",
    ...
]

# 开发环境依赖
[tool.uv]
dev-dependencies = [
    "pytest >=8.1.1,<9",
    "ruff>=0.6.6",
]

# ruff 自动化校验
[tool.ruff]
target-version = "py310"
exclude = [".venv", "*.pyi"]
src = ["app", "tests"]
line-length = 120
indent-width = 4

[tool.ruff.lint]
select = ["E", "F", "UP", "W"]

[tool.ruff.format]
quote-style = "single"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
augustelalande commented 1 month ago

ruff when unconfigured use this as the default configuration so I would say that is a good starting point.

lqllife commented 1 month ago

ruff when unconfigured use this as the default configuration so I would say that is a good starting point.

Thank you. I want to know, what is the more reasonable configuration in actual development?

augustelalande commented 1 month ago

That's a very loaded question, which people debate all the time. I would say the one specified by black, which I believe is also the ruff default is one of the most widely used.

lqllife commented 1 month ago

That's a very loaded question, which people debate all the time. I would say the one specified by black, which I believe is also the ruff default is one of the most widely used.

It's true, could you please share your configuration?

AndreuCodina commented 1 month ago

I always use this configuration: https://github.com/astral-sh/ruff/issues/11415

Avasam commented 1 month ago

With tools like these, I start with everything (select = ["ALL"]) then remove stuff as I find issues or disagree with their reasoning. I also get to learn a lot by reading their doc as they come up in my code. Then end up with a config looking something like this: https://github.com/BesLogic/shared-configs/blob/main/ruff.toml

https://github.com/astral-sh/ruff/issues/12352 / https://github.com/astral-sh/ruff/discussions/3363#discussioncomment-7266932 would be nice to make it easy to share a config once you settle on something you like.