Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default linter rules #11415

Open
AndreuCodina opened this issue May 13, 2024 · 7 comments
Open

Add default linter rules #11415

AndreuCodina opened this issue May 13, 2024 · 7 comments
Labels
configuration Related to settings and configuration linter Related to the linter

Comments

@AndreuCodina
Copy link

AndreuCodina commented May 13, 2024

In my company we have lots of microservices and nanoservices, and a Python project prototype I maintain to guide how Python projects must be developed and updated.
It's a common complaint not to have default rules in our pyproject.toml files, and instead have "magic letters" just because "I chose them".
My job is to ensure data engineers develop software as we do in .NET, i.e. with types.

I want to propose a group of default linter rules, and choose them with groups (letters), instead of choosing a subset.

pyproject.toml

[tool.ruff.lint]
select = ["F", "E", "W", "N", "I", "ANN"]
ignore = ["E501", "ANN101", "ANN102", "ANN401"]

Reasoning of select:

  • F: Unused variables, comparison with ==, etc.
  • E, W, N: PEP 8.
  • I: Sort imports.
  • ANN: Mandatory return types.

Reasoning of ignore:

  • E501: Line too long hasn't an automatic fix.
  • ANN101, ANN102: Typing self and cls is strange in Python.
  • ANN401: The Python ecosystem is not prepared to not use Any.

Besides, I always use this configuration:

[tool.pyright]
typeCheckingMode = "strict"
@zanieb
Copy link
Member

zanieb commented May 13, 2024

Hi!

We're going to recategorize all of the rules (roughly discussed in #1774) and define new defaults eventually. We're actively working on this, but I'm not sure when we'll be done because it's a big project and we want to get it right.

@zanieb
Copy link
Member

zanieb commented May 13, 2024

Similarly, this request fits into #1773 which is a part of that effort.

@dhruvmanila
Copy link
Member

@zanieb Do you think this can be merged into either of the linked issue?

@zanieb
Copy link
Member

zanieb commented May 14, 2024

I'm okay with keeping it open for now unless there's a duplicate issue regarding defaults.

We should add a dedicated tracking issue for the full re-categorization work eventually.

@zanieb zanieb added configuration Related to settings and configuration linter Related to the linter labels May 14, 2024
@AndreuCodina
Copy link
Author

Should we include default rules for some project types? For instance, there're FastAPI rules (https://docs.astral.sh/ruff/rules/#fastapi-fast). It's a library very used, but I don't know if Ruff knows if a package (fastapi in this case) is installed and then it doesn't waste resources with those rules.

@AndreuCodina
Copy link
Author

AndreuCodina commented Oct 8, 2024

Idea: how about declaring the rule "strict" as an alias for the linter rules I posted?

[tool.ruff.lint]
select = ["strict"]

This aligns with Pyright:

[tool.pyright]
typeCheckingMode = "strict"

@Avasam
Copy link

Avasam commented Oct 11, 2024

I'll link to #12352 and #3363 (reply in thread) as well. With which you could make your own custom defaults for your needs and "levels of strictness"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration linter Related to the linter
Projects
None yet
Development

No branches or pull requests

4 participants