ruff/crates
qdegraaf 93b2bd7184
[perflint] Add PERF401 and PERF402 rules (#5298)
## Summary

Adds `PERF401` and `PERF402` mirroring `W8401` and `W8402` from
https://github.com/tonybaloney/perflint

Implementation is not super smart but should be at parity with upstream
implementation judging by:
c07391c176/perflint/comprehension_checker.py (L42-L73)

It essentially checks:

- If the body of a for-loop is just one statement
- If that statement is an `if` and the if-statement contains a call to
`append()` we flag `PERF401` and suggest a list comprehension
- If that statement is a plain call to `append()` or `insert()` we flag
`PERF402` and suggest `list()` or `list.copy()`

I've set the violation to only flag the first append call in a long
`if-else` statement for `PERF401`. Happy to change this to some other
location or make it multiple violations if that makes more sense.

## Test Plan

Fixtures were added with the relevant scenarios for both rules

## Issue Links

Refers: https://github.com/astral-sh/ruff/issues/4789
2023-07-03 04:03:09 +00:00
..
flake8_to_ruff Bump version to 0.0.275 (#5276) 2023-06-21 21:53:37 -04:00
ruff [perflint] Add PERF401 and PERF402 rules (#5298) 2023-07-03 04:03:09 +00:00
ruff_benchmark Create PyFormatOptions 2023-06-26 14:02:17 +02:00
ruff_cache Only use a single cache file per Python package (#5117) 2023-06-19 17:46:13 +02:00
ruff_cli Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_dev Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_diagnostics Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_formatter Show BestFitting mode if it isn't FirstLine (#5452) 2023-06-30 09:49:00 +00:00
ruff_index Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
ruff_macros Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_python_ast Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_python_formatter Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_python_resolver Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_python_semantic Format let-else with rustfmt nightly (#5461) 2023-07-03 02:13:35 +00:00
ruff_python_stdlib Rewrite a variety of .contains() calls as matches! statements (#5432) 2023-06-28 22:42:27 -04:00
ruff_python_whitespace Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_rustpython Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_textwrap Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_wasm [pyupgrade] Restore the keep-runtime-typing setting (#5470) 2023-07-03 02:11:31 +00:00