mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Remove helpers.rs
dependency on Binding
(#3839)
This commit is contained in:
parent
b6276e2d95
commit
27e40e9b31
2 changed files with 22 additions and 19 deletions
|
@ -14,7 +14,7 @@ use rustpython_parser::ast::{
|
||||||
|
|
||||||
use ruff_diagnostics::Diagnostic;
|
use ruff_diagnostics::Diagnostic;
|
||||||
use ruff_python_ast::context::Context;
|
use ruff_python_ast::context::Context;
|
||||||
use ruff_python_ast::helpers::{binding_range, extract_handled_exceptions, to_module_path};
|
use ruff_python_ast::helpers::{extract_handled_exceptions, to_module_path};
|
||||||
use ruff_python_ast::operations::{extract_all_names, AllNamesFlags};
|
use ruff_python_ast::operations::{extract_all_names, AllNamesFlags};
|
||||||
use ruff_python_ast::scope::{
|
use ruff_python_ast::scope::{
|
||||||
Binding, BindingId, BindingKind, ClassDef, Exceptions, ExecutionContext, Export,
|
Binding, BindingId, BindingKind, ClassDef, Exceptions, ExecutionContext, Export,
|
||||||
|
@ -4058,7 +4058,16 @@ impl<'a> Checker<'a> {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
line: existing.range.location.row(),
|
line: existing.range.location.row(),
|
||||||
},
|
},
|
||||||
binding_range(&binding, self.locator),
|
matches!(
|
||||||
|
binding.kind,
|
||||||
|
BindingKind::ClassDefinition | BindingKind::FunctionDefinition
|
||||||
|
)
|
||||||
|
.then(|| {
|
||||||
|
binding.source.as_ref().map_or(binding.range, |source| {
|
||||||
|
helpers::identifier_range(source, self.locator)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or(binding.range),
|
||||||
);
|
);
|
||||||
if let Some(parent) = binding.source.as_ref() {
|
if let Some(parent) = binding.source.as_ref() {
|
||||||
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
||||||
|
@ -4904,7 +4913,17 @@ impl<'a> Checker<'a> {
|
||||||
name: (*name).to_string(),
|
name: (*name).to_string(),
|
||||||
line: binding.range.location.row(),
|
line: binding.range.location.row(),
|
||||||
},
|
},
|
||||||
binding_range(rebound, self.locator),
|
matches!(
|
||||||
|
rebound.kind,
|
||||||
|
BindingKind::ClassDefinition
|
||||||
|
| BindingKind::FunctionDefinition
|
||||||
|
)
|
||||||
|
.then(|| {
|
||||||
|
rebound.source.as_ref().map_or(rebound.range, |source| {
|
||||||
|
helpers::identifier_range(source, self.locator)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or(rebound.range),
|
||||||
);
|
);
|
||||||
if let Some(parent) = &rebound.source {
|
if let Some(parent) = &rebound.source {
|
||||||
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
||||||
|
|
|
@ -13,7 +13,6 @@ use rustpython_parser::{lexer, Mode, Tok};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::scope::{Binding, BindingKind};
|
|
||||||
use crate::source_code::{Generator, Indexer, Locator, Stylist};
|
use crate::source_code::{Generator, Indexer, Locator, Stylist};
|
||||||
use crate::types::{CallPath, Range};
|
use crate::types::{CallPath, Range};
|
||||||
use crate::visitor;
|
use crate::visitor;
|
||||||
|
@ -978,21 +977,6 @@ pub fn identifier_range(stmt: &Stmt, locator: &Locator) -> Range {
|
||||||
Range::from(stmt)
|
Range::from(stmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like `identifier_range`, but accepts a `Binding`.
|
|
||||||
pub fn binding_range(binding: &Binding, locator: &Locator) -> Range {
|
|
||||||
if matches!(
|
|
||||||
binding.kind,
|
|
||||||
BindingKind::ClassDefinition | BindingKind::FunctionDefinition
|
|
||||||
) {
|
|
||||||
binding
|
|
||||||
.source
|
|
||||||
.as_ref()
|
|
||||||
.map_or(binding.range, |source| identifier_range(source, locator))
|
|
||||||
} else {
|
|
||||||
binding.range
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the ranges of [`Tok::Name`] tokens within a specified node.
|
/// Return the ranges of [`Tok::Name`] tokens within a specified node.
|
||||||
pub fn find_names<'a, T>(
|
pub fn find_names<'a, T>(
|
||||||
located: &'a Located<T>,
|
located: &'a Located<T>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue