ruff/scripts
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
..
benchmarks markdownlint: enforce 100 char max length (#4698) 2023-05-28 22:45:56 -04:00
_utils.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
add_plugin.py Fix diagnostics variable name in add_plugin.py script (#5317) 2023-06-22 20:06:47 +00:00
add_rule.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
check_docs_formatted.py [perflint] Add PERF401 and PERF402 rules (#5298) 2023-07-03 04:03:09 +00:00
check_ecosystem.py ecosystem: Run git command with no human interaction flag (#5435) 2023-06-29 09:19:11 +02:00
Dockerfile.ecosystem Remove outdated feature flag from Dockerfile.ecosystem (#4620) 2023-05-24 08:19:08 +00:00
ecosystem_all_check.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
ecosystem_all_check.sh Make ecosystem all check more generic (#4629) 2023-05-24 16:26:23 +02:00
ecosystem_all_check_entrypoint.sh Make ecosystem all check more generic (#4629) 2023-05-24 16:26:23 +02:00
generate_known_standard_library.py Remove HashMap and HashSet for known-standard-library detection (#5345) 2023-06-23 19:59:03 +00:00
generate_mkdocs.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
pyproject.toml [perflint] Implement try-except-in-loop (PERF203) (#5166) 2023-06-26 17:34:37 +00:00
transform_readme.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
update_ambiguous_characters.py [perflint] Add PERF401 and PERF402 rules (#5298) 2023-07-03 04:03:09 +00:00
update_schemastore.py Use SSH clones in update_schemastore.py (#5322) 2023-06-23 09:50:10 -04:00