ruff/crates/ruff_linter/src
Dylan 0c2b88f224
[flake8-simplify] Further simplify to binary in preview for if-else-block-instead-of-if-exp (SIM108) (#12796)
In most cases we should suggest a ternary operator, but there are three
edge cases where a binary operator is more appropriate.

Given an if-else block of the form

```python
if test:
    target_var = body_value
else:
    target_var = else_value
```
This PR updates the check for SIM108 to the following:

- If `test == body_value` and preview enabled, suggest to replace with
`target_var = test or else_value`
- If `test == not body_value` and preview enabled, suggest to replace
with `target_var = body_value and else_value`
- If `not test == body_value` and preview enabled, suggest to replace
with `target_var = body_value and else_value`
- Otherwise, suggest to replace with `target_var = body_value if test
else else_value`

Closes #12189.
2024-08-10 16:49:25 +00:00
..
checkers [ruff] Implement incorrectly-parenthesized-tuple-in-subscript (RUF031) (#12480) 2024-08-07 13:11:29 +00:00
comments Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
cst Wrap expressions in parentheses when negating (#10346) 2024-03-11 18:20:55 -04:00
docstrings [pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502) (#11471) 2024-07-20 19:41:51 +00:00
fix [ruff_linter] - Use LibCST in adjust_indentation for mixed whitespace (#12740) 2024-08-08 10:49:58 +02:00
importer Move required import parsing out of lint rule (#12536) 2024-07-26 13:35:45 -04:00
message Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
registry Upgrade to Rust 1.79 (#11875) 2024-06-17 07:15:10 +01:00
rules [flake8-simplify] Further simplify to binary in preview for if-else-block-instead-of-if-exp (SIM108) (#12796) 2024-08-10 16:49:25 +00:00
settings [ruff] Implement incorrectly-parenthesized-tuple-in-subscript (RUF031) (#12480) 2024-08-07 13:11:29 +00:00
snapshots [ruff] Implement redirected-noqa (RUF101) (#11052) 2024-04-27 02:08:11 +00:00
codes.rs [ruff] Implement incorrectly-parenthesized-tuple-in-subscript (RUF031) (#12480) 2024-08-07 13:11:29 +00:00
directives.rs Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
doc_lines.rs Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
fs.rs Struct not tuple for compiled per-file ignores (#10864) 2024-04-11 13:47:57 -06:00
lib.rs Remove E999 as a rule, disallow any disablement methods for syntax error (#11901) 2024-06-27 13:44:11 +02:00
line_width.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
linter.rs Disable auto-fix when source has syntax errors (#12134) 2024-07-02 14:22:51 +05:30
logging.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
noqa.rs Remove E999 as a rule, disallow any disablement methods for syntax error (#11901) 2024-06-27 13:44:11 +02:00
packaging.rs Nested namespace packages support (#10541) 2024-03-24 22:53:32 -04:00
pyproject_toml.rs Update pyproject-toml to 0.8 (#8351) 2023-10-30 10:05:37 +00:00
registry.rs [flake8-builtins] Implement import, lambda, and module shadowing (#12546) 2024-07-29 01:42:42 +00:00
renamer.rs Remove BindingKind::ComprehensionVar (#12347) 2024-07-16 11:18:04 -04:00
rule_redirects.rs Re-code flake8-trio and flake8-async rules to match upstream (#10416) 2024-06-27 13:44:11 +02:00
rule_selector.rs Added ignoring deprecated rules for --select=ALL (#10497) 2024-06-27 13:44:11 +02:00
source_kind.rs Handle non-printable characters in diff view (#11687) 2024-06-08 06:22:03 +00:00
test.rs Disable auto-fix when source has syntax errors (#12134) 2024-07-02 14:22:51 +05:30
text_helpers.rs Handle non-printable characters in diff view (#11687) 2024-06-08 06:22:03 +00:00
upstream_categories.rs Fix pylint upstream categories not showing in docs (#10441) 2024-03-18 01:27:39 +00:00