mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[pylint] Implement consider-using-ternary (R1706) (#7811)
This is my first PR. Please feel free to give me any feedback for even small drawbacks. ## Summary Checks if pre-python 2.5 ternary syntax is used. Before ```python x, y = 1, 2 maximum = x >= y and x or y # [consider-using-ternary] ``` After ```python x, y = 1, 2 maximum = x if x >= y else y ``` References: [pylint](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/consider-using-ternary.html) #970 [and_or_ternary distinction logic](https://github.com/pylint-dev/pylint/blob/main/pylint/checkers/refactoring/refactoring_checker.py#L1813) ## Test Plan Unit test, python file, snapshot added.
This commit is contained in:
parent
6f9c317aa5
commit
c03a693ebc
9 changed files with 445 additions and 1 deletions
|
@ -1076,6 +1076,8 @@ mod tests {
|
|||
];
|
||||
|
||||
const PREVIEW_RULES: &[Rule] = &[
|
||||
Rule::AndOrTernary,
|
||||
Rule::AssignmentInAssert,
|
||||
Rule::DirectLoggerInstantiation,
|
||||
Rule::InvalidGetLoggerArgument,
|
||||
Rule::ManualDictComprehension,
|
||||
|
@ -1085,7 +1087,6 @@ mod tests {
|
|||
Rule::TooManyPublicMethods,
|
||||
Rule::UndocumentedWarn,
|
||||
Rule::UnnecessaryEnumerate,
|
||||
Rule::AssignmentInAssert,
|
||||
];
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue