ruff/crates/ruff_linter/src
Aleksei Latyshev dd0ba16a79
[refurb] Implement readlines_in_for lint (FURB129) (#9880)
## Summary
Implement [implicit readlines
(FURB129)](https://github.com/dosisod/refurb/blob/master/refurb/checks/iterable/implicit_readlines.py)
lint.

## Notes
I need a help/an opinion about suggested implementations.

This implementation differs from the original one from `refurb` in the
following way. This implementation checks syntactically the call of the
method with the name `readlines()` inside `for` {loop|generator
expression}. The implementation from refurb also
[checks](https://github.com/dosisod/refurb/blob/master/refurb/checks/iterable/implicit_readlines.py#L43)
that callee is a variable with a type `io.TextIOWrapper` or
`io.BufferedReader`.

- I do not see a simple way to implement the same logic.
- The best I can have is something like
```rust
checker.semantic().binding(checker.semantic().resolve_name(attr_expr.value.as_name_expr()?)?).statement(checker.semantic())
```
and analyze cases. But this will be not about types, but about guessing
the type by assignment (or with) expression.
- Also this logic has several false negatives, when the callee is not a
variable, but the result of function call (e.g. `open(...)`).
- On the other side, maybe it is good to lint this on other things,
where this suggestion is not safe, and push the developers to change
their interfaces to be less surprising, comparing with the standard
library.
- Anyway while the current implementation has false-positives (I
mentioned some of them in the test) I marked the fixes to be unsafe.
2024-02-12 22:28:35 -05:00
..
checkers [refurb] Implement readlines_in_for lint (FURB129) (#9880) 2024-02-12 22:28:35 -05:00
comments
cst Update string nodes for implicit concatenation (#7927) 2023-11-24 17:55:41 -06:00
docstrings [pydocstyle-D405] Allow using parameters as a sub-section header (#9894) 2024-02-08 21:54:32 -05:00
fix Skip LibCST parsing for standard dedent adjustments (#9769) 2024-02-02 18:13:46 +00:00
importer Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00
lex
message Feature: Add SARIF output support (#9078) 2023-12-13 00:33:19 -05:00
registry --show-settings displays active settings in a far more readable format (#9464) 2024-01-12 14:30:29 -05:00
rules [refurb] Implement readlines_in_for lint (FURB129) (#9880) 2024-02-12 22:28:35 -05:00
settings Allow arbitrary configuration options to be overridden via the CLI (#9599) 2024-02-09 21:56:37 +00:00
snapshots Detect automagic-like assignments in notebooks (#9653) 2024-01-29 12:55:44 +00:00
codes.rs [refurb] Implement readlines_in_for lint (FURB129) (#9880) 2024-02-12 22:28:35 -05:00
directives.rs Use comment_ranges for isort directive extraction (#9414) 2024-01-06 16:05:13 -05:00
doc_lines.rs Split Constant to individual literal nodes (#8064) 2023-10-30 12:13:23 +05:30
fs.rs
lib.rs
line_width.rs --show-settings displays active settings in a far more readable format (#9464) 2024-01-12 14:30:29 -05:00
linter.rs [pycodestyle] Add blank line(s) rules (E301, E302, E303, E304, E305, E306) (#9266) 2024-02-08 18:35:08 +00:00
logging.rs Deduplicate deprecation warnings for v0.2.0 release (#9764) 2024-02-01 17:10:24 -06:00
noqa.rs
packaging.rs
pyproject_toml.rs Update pyproject-toml to 0.8 (#8351) 2023-10-30 10:05:37 +00:00
registry.rs [pycodestyle] Add blank line(s) rules (E301, E302, E303, E304, E305, E306) (#9266) 2024-02-08 18:35:08 +00:00
renamer.rs Add a binding kind for comprehension targets (#9967) 2024-02-12 20:09:39 -05:00
rule_redirects.rs Bump version to 0.2.0 (#9762) 2024-02-01 17:10:33 -06:00
rule_selector.rs Fix clippy unused variable warning (#9902) 2024-02-08 22:13:31 +00:00
source_kind.rs Use SourceKind::diff for formatter (#8240) 2023-10-26 11:08:13 +05:30
test.rs Avoid rendering display-only rules as fixable (#9649) 2024-01-26 09:47:01 -05:00
upstream_categories.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00