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

Expose max number of arguments / max number of lines per method / etc as a specific setting #12389

Open
knyazer opened this issue Jul 18, 2024 · 3 comments
Labels
configuration Related to settings and configuration

Comments

@knyazer
Copy link

knyazer commented Jul 18, 2024

This is a feature proposal

There are several checks that constrain some numerically-computed properties of the code: the ones from the top of my head are a limit for McCabe complexity (from C901), number of arguments of a function limit (PLR0903), and a number of lines in a single method (PLR0905).

While these constraints are pretty neat, and useful, I would prefer to have more control over them: for example, in machine learning research, it is common to have a lot of parameters in a function, so the 6 arguments constraint is quite annoying, while putting it to e.g. 10 seems to be a good idea.

Besides, I can imagine that when adopting ruff on a new, un-ruffed, codebase one would want to be able to set particular limits for these rules: like, if it is common in the codebase to have insanely long methods, one could just bump up the length to a required value.

I would love the configuration of these rules to be exposed similarly to how line length is exposed, just with a field in a configuration file. Then, I could put something like:

[tool.ruff]
max_function_arguments = 5
max_file_length = 500

into a pyproject.toml and be happy about myself.

P.S. I'm used to Java checkstyle configuration, which allows to specify an enormous number of different constraints, so I am certainly biased about the necessity of such a feature.

@charliermarsh charliermarsh added the configuration Related to settings and configuration label Jul 18, 2024
@charliermarsh
Copy link
Member

Some of these actually do exist as Pylint rules and settings: https://docs.astral.sh/ruff/settings/#lint_pylint_max-args

@knyazer
Copy link
Author

knyazer commented Jul 19, 2024

Hmm, true, I didn't notice that!

Still, I think, my point stands: exposing these arguments more ergonomically and on the top-level of the configuration would be great.

Maybe ruff needs a list of "prioritized rules", configurations of which are exposed through the top level config, with generic names that bear no relation to the original pylint-or-whatever rule ids? A human-readable alias of sorts.

While ruff does mostly position itself as simply a reimplementation of tons of linters, it seems interesting to have a nicer interface to configure/add rules, since all the people I know just use ruff as a generic linter, without targeting any particular underlying rule group.

@MichaReiser
Copy link
Member

I don't think these settings should be exposed globally. They only apply to the linter and, therefore, should be under [ruff.lint]. However, for the setting to be under ruff lint, they would have to apply to multiple lint-groups which I don't think they currently do.

I do agree that having them in linter specific sections doesn't help with discoverability. This is something we have to solve as part of #1774

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
Projects
None yet
Development

No branches or pull requests

3 participants