[refurb] Implement repeated-append rule (FURB113) (#6702)

## Summary

As an initial effort with replicating `refurb` rules (#1348 ), this PR
adds support for
[FURB113](https://github.com/dosisod/refurb/blob/master/refurb/checks/builtin/list_extend.py)
and adds a new category of checks.

## Test Plan

I included a new test + checked that all other tests pass.
This commit is contained in:
Valeriy Savchenko 2023-08-28 23:51:59 +01:00 committed by GitHub
parent 1439bb592e
commit 26d53c56a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 1003 additions and 11 deletions

View file

@ -5,6 +5,7 @@ use bitflags::bitflags;
use ruff_index::{newtype_index, IndexSlice, IndexVec};
use ruff_python_ast::call_path::format_call_path;
use ruff_python_ast::Stmt;
use ruff_source_file::Locator;
use ruff_text_size::{Ranged, TextRange};
@ -181,17 +182,21 @@ impl<'a> Binding<'a> {
locator.slice(self.range)
}
/// Returns the statement in which the binding was defined.
pub fn statement<'b>(&self, semantic: &'b SemanticModel) -> Option<&'b Stmt> {
self.source
.map(|statement_id| semantic.statement(statement_id))
}
/// Returns the range of the binding's parent.
pub fn parent_range(&self, semantic: &SemanticModel) -> Option<TextRange> {
self.source
.map(|id| semantic.statement(id))
.and_then(|parent| {
if parent.is_import_from_stmt() {
Some(parent.range())
} else {
None
}
})
self.statement(semantic).and_then(|parent| {
if parent.is_import_from_stmt() {
Some(parent.range())
} else {
None
}
})
}
pub fn as_any_import(&'a self) -> Option<AnyImport<'a>> {

View file

@ -117,7 +117,7 @@ impl Ranged for Member<'_> {
}
/// A definition within a Python program.
#[derive(Debug)]
#[derive(Debug, is_macro::Is)]
pub enum Definition<'a> {
Module(Module<'a>),
Member(Member<'a>),