[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:
Jake Park 2023-10-13 10:29:19 +09:00 committed by GitHub
parent 6f9c317aa5
commit c03a693ebc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 445 additions and 1 deletions

View file

@ -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)]