[pylint] Implement too-many-positional (PLR0917) (#8995)

## Summary

Adds a rule that bans too many positional (i.e. not keyword-only)
parameters in function definitions.

Fixes https://github.com/astral-sh/ruff/issues/8946

Rule ID code taken from https://github.com/pylint-dev/pylint/pull/9278

## Test Plan
1. fixtures file checking multiple OKs/fails
2. parametrized test file
This commit is contained in:
Philipp A 2023-12-04 19:03:09 +01:00 committed by GitHub
parent 060a25df09
commit b90027d037
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 209 additions and 0 deletions

View file

@ -2635,6 +2635,11 @@ pub struct PylintOptions {
#[option(default = r"5", value_type = "int", example = r"max-args = 5")]
pub max_args: Option<usize>,
/// Maximum number of positional arguments allowed for a function or method definition
/// (see: `PLR0917`).
#[option(default = r"3", value_type = "int", example = r"max-pos-args = 3")]
pub max_positional_args: Option<usize>,
/// Maximum number of statements allowed for a function or method body (see:
/// `PLR0915`).
#[option(default = r"50", value_type = "int", example = r"max-statements = 50")]
@ -2663,6 +2668,9 @@ impl PylintOptions {
.unwrap_or(defaults.allow_magic_value_types),
allow_dunder_method_names: self.allow_dunder_method_names.unwrap_or_default(),
max_args: self.max_args.unwrap_or(defaults.max_args),
max_positional_args: self
.max_positional_args
.unwrap_or(defaults.max_positional_args),
max_bool_expr: self.max_bool_expr.unwrap_or(defaults.max_bool_expr),
max_returns: self.max_returns.unwrap_or(defaults.max_returns),
max_branches: self.max_branches.unwrap_or(defaults.max_branches),