ruff/crates
Clément Schreiner b1072049bf
[pylint] Implement unnecessary-lambda (W0108) (#7953)
This is my first PR and I'm new at rust, so feel free to ask me to
rewrite everything if needed ;)

The rule must be called after deferred lambas have been visited because
of the last check (whether the lambda parameters are used in the body of
the function that's being called). I didn't know where to do it, so I
did what I could to be able to work on the rule itself:

 - added a `ruff_linter::checkers::ast::analyze::lambda` module
 - build a vec of visited lambdas in `visit_deferred_lambdas`
 - call `analyze::lambda` on the vec after they all have been visited
 
Building that vec of visited lambdas was necessary so that bindings
could be properly resolved in the case of nested lambdas.

Note that there is an open issue in pylint for some false positives, do
we need to fix that before merging the rule?
https://github.com/pylint-dev/pylint/issues/8192

Also, I did not provide any fixes (yet), maybe we want do avoid merging
new rules without fixes?

## Summary

Checks for lambdas whose body is a function call on the same arguments
as the lambda itself.

### Bad

```python
df.apply(lambda x: str(x))
```

### Good

```python
df.apply(str)
```

## Test Plan

Added unit test and snapshot.
Manually compared pylint and ruff output on pylint's test cases.

## References

- [pylint
documentation](https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/unnecessary-lambda.html)
- [pylint
implementation](https://github.com/pylint-dev/pylint/blob/main/pylint/checkers/base/basic_checker.py#L521-L587)
 - https://github.com/astral-sh/ruff/issues/970
2023-10-20 17:25:24 +00:00
..
flake8_to_ruff Release 0.1.1 (#8073) 2023-10-19 20:49:53 +00:00
ruff_benchmark Bump ureq from 2.7.1 to 2.8.0 (#7756) 2023-10-02 09:49:59 -04:00
ruff_cache Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00
ruff_cli Change line-ending default to auto (#8057) 2023-10-20 00:13:11 +01:00
ruff_dev Respect #(deprecated) attribute in configuration options (#8035) 2023-10-19 01:07:36 +00:00
ruff_diagnostics Add settings for promoting and demoting fixes (#7841) 2023-10-10 20:04:21 +00:00
ruff_formatter Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
ruff_index
ruff_linter [pylint] Implement unnecessary-lambda (W0108) (#7953) 2023-10-20 17:25:24 +00:00
ruff_macros Add #[automatically_derived] to derived impls (#8080) 2023-10-20 00:12:27 +00:00
ruff_notebook Add cell field to JSON output format (#7664) 2023-10-13 01:06:02 +00:00
ruff_python_ast Remove leftover constant tuple reference (#8062) 2023-10-19 17:50:45 +00:00
ruff_python_codegen Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
ruff_python_formatter Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
ruff_python_index Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
ruff_python_literal Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_python_parser Disallow f-strings in match pattern literal (#7857) 2023-10-09 10:11:08 +00:00
ruff_python_resolver
ruff_python_semantic Avoid if-else simplification for TYPE_CHECKING blocks (#8072) 2023-10-19 19:15:54 -04:00
ruff_python_stdlib Improvements to RUF015 (#7848) 2023-10-08 14:49:45 +00:00
ruff_python_trivia Extend pragma comment cases (#7687) 2023-09-28 18:55:19 +00:00
ruff_shrinking Release 0.1.1 (#8073) 2023-10-19 20:49:53 +00:00
ruff_source_file Add cell field to JSON output format (#7664) 2023-10-13 01:06:02 +00:00
ruff_text_size Unify line size settings between ruff and the formatter (#6873) 2023-08-28 06:44:56 +00:00
ruff_wasm Add [format|lint].exclude options (#8000) 2023-10-18 01:15:25 +00:00
ruff_workspace Fix Options JSON schema description (#8081) 2023-10-20 00:25:32 +00:00