Skip to content

Commit

Permalink
refactor: Move scope and binding types to scope.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Mar 17, 2023
1 parent e5f64ce commit e5fa25c
Show file tree
Hide file tree
Showing 34 changed files with 450 additions and 430 deletions.
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/deferred.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_python_ast::context::ScopeStack;
use ruff_python_ast::scope::ScopeStack;
use rustpython_parser::ast::{Expr, Stmt};

use ruff_python_ast::types::Range;
Expand Down
11 changes: 6 additions & 5 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ use rustpython_parser::ast::{
};

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::context::{Context, ScopeStack};
use ruff_python_ast::context::Context;
use ruff_python_ast::helpers::{
binding_range, extract_handled_exceptions, to_module_path, Exceptions,
};
use ruff_python_ast::operations::{extract_all_names, AllNamesFlags};
use ruff_python_ast::relocate::relocate_expr;
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
use ruff_python_ast::types::{
Binding, BindingId, BindingKind, ClassDef, ExecutionContext, FunctionDef, Lambda, Node, Range,
RefEquality, Scope, ScopeId, ScopeKind,
use ruff_python_ast::scope::{
Binding, BindingId, BindingKind, ClassDef, ExecutionContext, FunctionDef, Lambda, Scope,
ScopeId, ScopeKind, ScopeStack,
};
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
use ruff_python_ast::types::{Node, Range, RefEquality};
use ruff_python_ast::typing::{match_annotated_subscript, Callable, SubscriptKind};
use ruff_python_ast::visitor::{walk_excepthandler, walk_pattern, Visitor};
use ruff_python_ast::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::{Expr, ExprKind};

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Expr, ExprKind};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::collect_call_path;
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Cmpop, Expr, ExprKind, Stmt, StmtKind, Unaryop};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::{create_expr, unparse_expr};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::AsRule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/flake8_type_checking/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustpython_parser::ast::{Constant, Expr, ExprKind};

use ruff_python_ast::context::Context;
use ruff_python_ast::helpers::{map_callable, to_call_path};
use ruff_python_ast::types::{Binding, BindingKind, ExecutionContext, ScopeKind};
use ruff_python_ast::scope::{Binding, BindingKind, ExecutionContext, ScopeKind};

/// Return `true` if [`Expr`] is a guard for a type-checking block.
pub fn is_type_checking_block(context: &Context, test: &Expr) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Binding, BindingKind, ExecutionContext};
use ruff_python_ast::scope::{Binding, BindingKind, ExecutionContext};

#[violation]
pub struct RuntimeImportInTypeCheckingBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Binding, BindingKind, ExecutionContext};
use ruff_python_ast::scope::{Binding, BindingKind, ExecutionContext};

use crate::rules::isort::{categorize, ImportType};
use crate::settings::Settings;
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/flake8_unused_arguments/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use rustpython_parser::ast::{Arg, Arguments};

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::context::Bindings;
use ruff_python_ast::function_type;
use ruff_python_ast::function_type::FunctionType;
use ruff_python_ast::types::{BindingId, FunctionDef, Lambda, Scope, ScopeKind};
use ruff_python_ast::scope::{BindingId, Bindings, FunctionDef, Lambda, Scope, ScopeKind};
use ruff_python_ast::visibility;

use crate::checkers::ast::Checker;
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pandas_vet/rules/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Expr, ExprKind};
use ruff_diagnostics::Violation;
use ruff_diagnostics::{Diagnostic, DiagnosticKind};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{BindingKind, Range};
use ruff_python_ast::scope::BindingKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pandas_vet/rules/check_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Expr, ExprKind};
use ruff_diagnostics::Violation;
use ruff_diagnostics::{Diagnostic, DiagnosticKind};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{BindingKind, Range};
use ruff_python_ast::scope::BindingKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use rustpython_parser::ast::Stmt;
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::identifier_range;
use ruff_python_ast::scope::{Scope, ScopeKind};
use ruff_python_ast::source_code::Locator;
use ruff_python_ast::types::{Scope, ScopeKind};

/// ## What it does
/// Checks for functions with "dunder" names (that is, names with two
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Arguments, Expr};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::function_type;
use ruff_python_ast::types::{Range, Scope};
use ruff_python_ast::scope::Scope;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustpython_parser::ast::{Arguments, Expr};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::function_type;
use ruff_python_ast::types::{Range, Scope};
use ruff_python_ast::scope::Scope;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use ruff_diagnostics::{AutofixKind, Availability, Diagnostic, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::{match_leading_content, match_trailing_content, unparse_stmt};
use ruff_python_ast::newlines::StrExt;
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::source_code::Stylist;
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::types::Range;
use ruff_python_ast::whitespace::leading_space;

use crate::checkers::ast::Checker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::Stmt;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pyflakes/rules/undefined_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::path::Path;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, Scope};
use ruff_python_ast::scope::Scope;
use ruff_python_ast::types::Range;

#[violation]
pub struct UndefinedExport {
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/pyflakes/rules/undefined_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::string::ToString;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::context::Bindings;
use ruff_python_ast::types::{Scope, ScopeKind};
use ruff_python_ast::scope::{Bindings, Scope, ScopeKind};

#[violation]
pub struct UndefinedLocal {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pyflakes/rules/unused_annotation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::ScopeId;
use ruff_python_ast::scope::ScopeId;

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pyflakes/rules/unused_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use rustpython_parser::{lexer, Mode, Tok};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::contains_effect;
use ruff_python_ast::scope::{ScopeId, ScopeKind};
use ruff_python_ast::source_code::Locator;
use ruff_python_ast::types::{Range, RefEquality, ScopeId, ScopeKind};
use ruff_python_ast::types::{Range, RefEquality};

use crate::autofix::helpers::delete_stmt;
use crate::checkers::ast::Checker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use rustpython_parser::ast::{Expr, ExprKind};

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pylint/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_python_ast::function_type;
use ruff_python_ast::function_type::FunctionType;
use ruff_python_ast::types::{FunctionDef, ScopeKind};
use ruff_python_ast::scope::{FunctionDef, ScopeKind};

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pylint/rules/await_outside_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::Expr;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{FunctionDef, Range, ScopeKind};
use ruff_python_ast::scope::{FunctionDef, ScopeKind};
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::{Expr, ExprKind};

use ruff_diagnostics::{AutofixKind, Availability, Diagnostic, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{BindingKind, Range};
use ruff_python_ast::scope::BindingKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::AsRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::Expr;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rustpython_parser::ast::{ArgData, Expr, ExprKind, Stmt, StmtKind};

use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::{Range, ScopeKind};
use ruff_python_ast::scope::ScopeKind;
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::AsRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use rustpython_parser::ast::{Expr, ExprKind, Keyword, Stmt};

use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::context::Bindings;
use ruff_python_ast::types::{Binding, BindingKind, Range, Scope};
use ruff_python_ast::scope::{Binding, BindingKind, Bindings, Scope};
use ruff_python_ast::types::Range;

use crate::checkers::ast::Checker;
use crate::registry::AsRule;
Expand Down

0 comments on commit e5fa25c

Please sign in to comment.