diff --git a/Cargo.lock b/Cargo.lock index 8afabb6e94..08cdd31917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1905,13 +1905,16 @@ dependencies = [ "ruff_index", "ruff_macros", "ruff_python_ast", + "ruff_python_codegen", + "ruff_python_index", + "ruff_python_parser", "ruff_python_semantic", "ruff_python_stdlib", "ruff_python_trivia", - "ruff_rustpython", + "ruff_source_file", "ruff_text_size", - "ruff_textwrap", "rustc-hash", + "rustpython-ast", "rustpython-format", "rustpython-parser", "schemars", @@ -1944,6 +1947,7 @@ dependencies = [ "ruff", "ruff_python_ast", "ruff_python_formatter", + "rustpython-ast", "rustpython-parser", "serde", "serde_json", @@ -1999,8 +2003,9 @@ dependencies = [ "ruff_python_ast", "ruff_python_formatter", "ruff_python_stdlib", + "ruff_python_trivia", + "ruff_source_file", "ruff_text_size", - "ruff_textwrap", "rustc-hash", "serde", "serde_json", @@ -2034,9 +2039,11 @@ dependencies = [ "ruff_cli", "ruff_diagnostics", "ruff_formatter", + "ruff_python_codegen", "ruff_python_formatter", "ruff_python_stdlib", - "ruff_textwrap", + "ruff_python_trivia", + "rustpython-ast", "rustpython-format", "rustpython-parser", "schemars", @@ -2089,7 +2096,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "ruff_textwrap", + "ruff_python_trivia", "syn 2.0.23", ] @@ -2097,25 +2104,35 @@ dependencies = [ name = "ruff_python_ast" version = "0.0.0" dependencies = [ - "anyhow", "bitflags 2.3.3", "insta", "is-macro", - "itertools", "memchr", "num-bigint", "num-traits", "once_cell", "ruff_python_trivia", + "ruff_source_file", "ruff_text_size", "rustc-hash", "rustpython-ast", - "rustpython-literal", "rustpython-parser", "serde", "smallvec", ] +[[package]] +name = "ruff_python_codegen" +version = "0.0.0" +dependencies = [ + "once_cell", + "ruff_python_ast", + "ruff_source_file", + "rustpython-ast", + "rustpython-literal", + "rustpython-parser", +] + [[package]] name = "ruff_python_formatter" version = "0.0.0" @@ -2130,9 +2147,12 @@ dependencies = [ "once_cell", "ruff_formatter", "ruff_python_ast", + "ruff_python_index", "ruff_python_trivia", + "ruff_source_file", "ruff_text_size", "rustc-hash", + "rustpython-ast", "rustpython-parser", "serde", "serde_json", @@ -2141,6 +2161,30 @@ dependencies = [ "thiserror", ] +[[package]] +name = "ruff_python_index" +version = "0.0.0" +dependencies = [ + "itertools", + "ruff_python_trivia", + "ruff_source_file", + "ruff_text_size", + "rustpython-ast", + "rustpython-parser", +] + +[[package]] +name = "ruff_python_parser" +version = "0.0.0" +dependencies = [ + "anyhow", + "is-macro", + "ruff_python_ast", + "ruff_text_size", + "rustpython-ast", + "rustpython-parser", +] + [[package]] name = "ruff_python_resolver" version = "0.0.0" @@ -2161,8 +2205,10 @@ dependencies = [ "ruff_index", "ruff_python_ast", "ruff_python_stdlib", + "ruff_source_file", "ruff_text_size", "rustc-hash", + "rustpython-ast", "rustpython-parser", "smallvec", ] @@ -2177,19 +2223,14 @@ version = "0.0.0" dependencies = [ "insta", "memchr", + "ruff_source_file", "ruff_text_size", + "rustpython-ast", + "rustpython-parser", "smallvec", "unic-ucd-ident", ] -[[package]] -name = "ruff_rustpython" -version = "0.0.0" -dependencies = [ - "anyhow", - "rustpython-parser", -] - [[package]] name = "ruff_shrinking" version = "0.1.0" @@ -2199,13 +2240,24 @@ dependencies = [ "fs-err", "regex", "ruff_python_ast", - "ruff_rustpython", + "ruff_python_parser", "rustpython-ast", "shlex", "tracing", "tracing-subscriber", ] +[[package]] +name = "ruff_source_file" +version = "0.0.0" +dependencies = [ + "insta", + "memchr", + "once_cell", + "ruff_text_size", + "serde", +] + [[package]] name = "ruff_text_size" version = "0.0.0" @@ -2215,14 +2267,6 @@ dependencies = [ "serde", ] -[[package]] -name = "ruff_textwrap" -version = "0.0.0" -dependencies = [ - "ruff_python_trivia", - "ruff_text_size", -] - [[package]] name = "ruff_wasm" version = "0.0.0" @@ -2234,8 +2278,11 @@ dependencies = [ "ruff", "ruff_diagnostics", "ruff_python_ast", + "ruff_python_codegen", "ruff_python_formatter", - "ruff_rustpython", + "ruff_python_index", + "ruff_python_parser", + "ruff_source_file", "rustpython-parser", "serde", "serde-wasm-bindgen", diff --git a/crates/ruff/Cargo.toml b/crates/ruff/Cargo.toml index e3b52e0e76..a9f679f640 100644 --- a/crates/ruff/Cargo.toml +++ b/crates/ruff/Cargo.toml @@ -19,13 +19,15 @@ ruff_cache = { path = "../ruff_cache" } ruff_diagnostics = { path = "../ruff_diagnostics", features = ["serde"] } ruff_index = { path = "../ruff_index" } ruff_macros = { path = "../ruff_macros" } -ruff_python_trivia = { path = "../ruff_python_trivia" } ruff_python_ast = { path = "../ruff_python_ast", features = ["serde"] } +ruff_python_codegen = { path = "../ruff_python_codegen" } +ruff_python_index = { path = "../ruff_python_index" } ruff_python_semantic = { path = "../ruff_python_semantic" } ruff_python_stdlib = { path = "../ruff_python_stdlib" } -ruff_rustpython = { path = "../ruff_rustpython" } +ruff_python_trivia = { path = "../ruff_python_trivia" } +ruff_python_parser = { path = "../ruff_python_parser" } +ruff_source_file = { path = "../ruff_source_file" } ruff_text_size = { workspace = true } -ruff_textwrap = { path = "../ruff_textwrap" } annotate-snippets = { version = "0.9.1", features = ["color"] } anyhow = { workspace = true } @@ -61,6 +63,7 @@ result-like = { version = "0.4.6" } rustc-hash = { workspace = true } rustpython-format = { workspace = true } rustpython-parser = { workspace = true } +rustpython-ast = { workspace = true } schemars = { workspace = true, optional = true } semver = { version = "1.0.16" } serde = { workspace = true } diff --git a/crates/ruff/src/autofix/codemods.rs b/crates/ruff/src/autofix/codemods.rs index b73b2d5041..19d962293e 100644 --- a/crates/ruff/src/autofix/codemods.rs +++ b/crates/ruff/src/autofix/codemods.rs @@ -4,9 +4,10 @@ use anyhow::{bail, Result}; use libcst_native::{ Codegen, CodegenState, ImportNames, ParenthesizableWhitespace, SmallStatement, Statement, }; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::cst::helpers::compose_module_path; use crate::cst::matchers::match_statement; diff --git a/crates/ruff/src/autofix/edits.rs b/crates/ruff/src/autofix/edits.rs index 694a14e614..4f98234614 100644 --- a/crates/ruff/src/autofix/edits.rs +++ b/crates/ruff/src/autofix/edits.rs @@ -1,13 +1,14 @@ //! Interface for generating autofix edits from higher-level actions (e.g., "remove an argument"). use anyhow::{bail, Result}; use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_parser::ast::{self, ExceptHandler, Expr, Keyword, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Keyword, Ranged, Stmt}; use rustpython_parser::{lexer, Mode}; use ruff_diagnostics::Edit; -use ruff_python_ast::helpers; -use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; -use ruff_python_trivia::{is_python_whitespace, NewlineWithTrailingNewline, PythonWhitespace}; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; +use ruff_python_trivia::{has_leading_content, is_python_whitespace, PythonWhitespace}; +use ruff_source_file::{Locator, NewlineWithTrailingNewline}; use crate::autofix::codemods; @@ -41,11 +42,9 @@ pub(crate) fn delete_stmt( if let Some(semicolon) = trailing_semicolon(stmt.end(), locator) { let next = next_stmt_break(semicolon, locator); Edit::deletion(stmt.start(), next) - } else if helpers::has_leading_content(stmt.start(), locator) { + } else if has_leading_content(stmt.start(), locator) { Edit::range_deletion(stmt.range()) - } else if let Some(start) = - helpers::preceded_by_continuations(stmt.start(), locator, indexer) - { + } else if let Some(start) = indexer.preceded_by_continuations(stmt.start(), locator) { Edit::range_deletion(TextRange::new(start, stmt.end())) } else { let range = locator.full_lines_range(stmt.range()); @@ -296,10 +295,10 @@ fn next_stmt_break(semicolon: TextSize, locator: &Locator) -> TextSize { mod tests { use anyhow::Result; use ruff_text_size::TextSize; - use rustpython_parser::ast::{Ranged, Suite}; + use rustpython_ast::{Ranged, Suite}; use rustpython_parser::Parse; - use ruff_python_ast::source_code::Locator; + use ruff_source_file::Locator; use crate::autofix::edits::{next_stmt_break, trailing_semicolon}; diff --git a/crates/ruff/src/autofix/mod.rs b/crates/ruff/src/autofix/mod.rs index 3aba3eb424..777f225a7a 100644 --- a/crates/ruff/src/autofix/mod.rs +++ b/crates/ruff/src/autofix/mod.rs @@ -5,7 +5,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use rustc_hash::{FxHashMap, FxHashSet}; use ruff_diagnostics::{Diagnostic, Edit, Fix, IsolationLevel}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::autofix::source_map::SourceMap; use crate::linter::FixTable; @@ -146,7 +146,7 @@ mod tests { use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; - use ruff_python_ast::source_code::Locator; + use ruff_source_file::Locator; use crate::autofix::source_map::SourceMarker; use crate::autofix::{apply_fixes, FixResult}; diff --git a/crates/ruff/src/checkers/ast/analyze/argument.rs b/crates/ruff/src/checkers/ast/analyze/argument.rs index 98c7dcb05b..cf2c2628be 100644 --- a/crates/ruff/src/checkers/ast/analyze/argument.rs +++ b/crates/ruff/src/checkers/ast/analyze/argument.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arg, Ranged}; +use rustpython_ast::{Arg, Ranged}; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/arguments.rs b/crates/ruff/src/checkers/ast/analyze/arguments.rs index 87e6203a68..84b88069f6 100644 --- a/crates/ruff/src/checkers/ast/analyze/arguments.rs +++ b/crates/ruff/src/checkers/ast/analyze/arguments.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Arguments; +use rustpython_ast::Arguments; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/comprehension.rs b/crates/ruff/src/checkers/ast/analyze/comprehension.rs index 893e030765..92ec113bbd 100644 --- a/crates/ruff/src/checkers/ast/analyze/comprehension.rs +++ b/crates/ruff/src/checkers/ast/analyze/comprehension.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Comprehension; +use rustpython_ast::Comprehension; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/deferred_for_loops.rs b/crates/ruff/src/checkers/ast/analyze/deferred_for_loops.rs index 0cbc5ba3cd..3453db08ec 100644 --- a/crates/ruff/src/checkers/ast/analyze/deferred_for_loops.rs +++ b/crates/ruff/src/checkers/ast/analyze/deferred_for_loops.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Stmt}; +use rustpython_ast::{self as ast, Stmt}; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/definitions.rs b/crates/ruff/src/checkers/ast/analyze/definitions.rs index fe32800278..809ec2c325 100644 --- a/crates/ruff/src/checkers/ast/analyze/definitions.rs +++ b/crates/ruff/src/checkers/ast/analyze/definitions.rs @@ -1,6 +1,6 @@ use ruff_python_ast::str::raw_contents_range; use ruff_text_size::TextRange; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_python_semantic::{BindingKind, ContextualizedDefinition, Export}; diff --git a/crates/ruff/src/checkers/ast/analyze/except_handler.rs b/crates/ruff/src/checkers/ast/analyze/except_handler.rs index 5dad39a60c..c2bdaf4845 100644 --- a/crates/ruff/src/checkers/ast/analyze/except_handler.rs +++ b/crates/ruff/src/checkers/ast/analyze/except_handler.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Ranged}; use crate::checkers::ast::Checker; use crate::registry::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/expression.rs b/crates/ruff/src/checkers/ast/analyze/expression.rs index b485527b5b..54f9e3770f 100644 --- a/crates/ruff/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff/src/checkers/ast/analyze/expression.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Operator, Ranged}; use rustpython_format::cformat::{CFormatError, CFormatErrorType}; -use rustpython_parser::ast::{self, Constant, Expr, ExprContext, Operator, Ranged}; use ruff_diagnostics::Diagnostic; diff --git a/crates/ruff/src/checkers/ast/analyze/module.rs b/crates/ruff/src/checkers/ast/analyze/module.rs index 6d678961d7..9c19ddc21a 100644 --- a/crates/ruff/src/checkers/ast/analyze/module.rs +++ b/crates/ruff/src/checkers/ast/analyze/module.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Suite; +use rustpython_ast::Suite; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/analyze/statement.rs b/crates/ruff/src/checkers/ast/analyze/statement.rs index 958a9dcd1d..762201e4d7 100644 --- a/crates/ruff/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff/src/checkers/ast/analyze/statement.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::Diagnostic; use ruff_python_ast::helpers; diff --git a/crates/ruff/src/checkers/ast/analyze/suite.rs b/crates/ruff/src/checkers/ast/analyze/suite.rs index f24b4525eb..4266abd529 100644 --- a/crates/ruff/src/checkers/ast/analyze/suite.rs +++ b/crates/ruff/src/checkers/ast/analyze/suite.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use crate::checkers::ast::Checker; use crate::codes::Rule; diff --git a/crates/ruff/src/checkers/ast/deferred.rs b/crates/ruff/src/checkers/ast/deferred.rs index d380da3041..1d9e6f6490 100644 --- a/crates/ruff/src/checkers/ast/deferred.rs +++ b/crates/ruff/src/checkers/ast/deferred.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_python_semantic::{ScopeId, Snapshot}; diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index e02b026833..97ff354925 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -31,20 +31,21 @@ use std::path::Path; use itertools::Itertools; use log::error; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{ - self, Arg, ArgWithDefault, Arguments, Comprehension, Constant, ElifElseClause, ExceptHandler, - Expr, ExprContext, Keyword, Pattern, Ranged, Stmt, Suite, UnaryOp, +use rustpython_ast::{ + self as ast, Arg, ArgWithDefault, Arguments, Comprehension, Constant, ElifElseClause, + ExceptHandler, Expr, ExprContext, Keyword, Pattern, Ranged, Stmt, Suite, UnaryOp, }; use ruff_diagnostics::{Diagnostic, IsolationLevel}; use ruff_python_ast::all::{extract_all_names, DunderAllFlags}; use ruff_python_ast::helpers::{extract_handled_exceptions, to_module_path}; use ruff_python_ast::identifier::Identifier; -use ruff_python_ast::source_code::{Generator, Indexer, Locator, Quote, Stylist}; use ruff_python_ast::str::trailing_quote; -use ruff_python_ast::typing::{parse_type_annotation, AnnotationKind}; use ruff_python_ast::visitor::{walk_except_handler, walk_pattern, Visitor}; use ruff_python_ast::{helpers, str, visitor}; +use ruff_python_codegen::{Generator, Quote, Stylist}; +use ruff_python_index::Indexer; +use ruff_python_parser::typing::{parse_type_annotation, AnnotationKind}; use ruff_python_semantic::analyze::{typing, visibility}; use ruff_python_semantic::{ BindingFlags, BindingId, BindingKind, Exceptions, Export, FromImport, Globals, Import, Module, @@ -52,6 +53,7 @@ use ruff_python_semantic::{ }; use ruff_python_stdlib::builtins::{BUILTINS, MAGIC_GLOBALS}; use ruff_python_stdlib::path::is_python_stub_file; +use ruff_source_file::Locator; use crate::checkers::ast::deferred::Deferred; use crate::docstrings::extraction::ExtractionTarget; @@ -1690,7 +1692,9 @@ impl<'a> Checker<'a> { while !self.deferred.string_type_definitions.is_empty() { let type_definitions = std::mem::take(&mut self.deferred.string_type_definitions); for (range, value, snapshot) in type_definitions { - if let Ok((expr, kind)) = parse_type_annotation(value, range, self.locator) { + if let Ok((expr, kind)) = + parse_type_annotation(value, range, self.locator.contents()) + { let expr = allocator.alloc(expr); self.semantic.restore(snapshot); diff --git a/crates/ruff/src/checkers/imports.rs b/crates/ruff/src/checkers/imports.rs index 0ee66eddaf..6d71be0ac8 100644 --- a/crates/ruff/src/checkers/imports.rs +++ b/crates/ruff/src/checkers/imports.rs @@ -2,14 +2,16 @@ use std::borrow::Cow; use std::path::Path; -use rustpython_parser::ast::{self, Ranged, Stmt, Suite}; +use rustpython_ast::{self as ast, Ranged, Stmt, Suite}; use ruff_diagnostics::Diagnostic; use ruff_python_ast::helpers::to_module_path; use ruff_python_ast::imports::{ImportMap, ModuleImport}; -use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; use ruff_python_ast::statement_visitor::StatementVisitor; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; use ruff_python_stdlib::path::is_python_stub_file; +use ruff_source_file::Locator; use crate::directives::IsortDirectives; use crate::registry::Rule; diff --git a/crates/ruff/src/checkers/logical_lines.rs b/crates/ruff/src/checkers/logical_lines.rs index cbf9263c70..5f1f563fb1 100644 --- a/crates/ruff/src/checkers/logical_lines.rs +++ b/crates/ruff/src/checkers/logical_lines.rs @@ -2,8 +2,9 @@ use ruff_text_size::TextRange; use rustpython_parser::lexer::LexResult; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; -use ruff_python_ast::source_code::{Locator, Stylist}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_codegen::Stylist; +use ruff_python_parser::token_kind::TokenKind; +use ruff_source_file::Locator; use crate::registry::{AsRule, Rule}; use crate::rules::pycodestyle::rules::logical_lines::{ diff --git a/crates/ruff/src/checkers/noqa.rs b/crates/ruff/src/checkers/noqa.rs index 56dac2c8f1..b90e07942d 100644 --- a/crates/ruff/src/checkers/noqa.rs +++ b/crates/ruff/src/checkers/noqa.rs @@ -4,10 +4,10 @@ use std::path::Path; use itertools::Itertools; use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::noqa; use crate::noqa::{Directive, FileExemption, NoqaDirectives, NoqaMapping}; diff --git a/crates/ruff/src/checkers/physical_lines.rs b/crates/ruff/src/checkers/physical_lines.rs index bef019d8b5..5b3b6f5ca6 100644 --- a/crates/ruff/src/checkers/physical_lines.rs +++ b/crates/ruff/src/checkers/physical_lines.rs @@ -2,8 +2,9 @@ use ruff_text_size::TextSize; use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; -use ruff_python_trivia::UniversalNewlines; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; +use ruff_source_file::{Locator, UniversalNewlines}; use crate::registry::Rule; use crate::rules::flake8_copyright::rules::missing_copyright_notice; @@ -121,7 +122,9 @@ mod tests { use rustpython_parser::lexer::lex; use rustpython_parser::Mode; - use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; + use ruff_python_codegen::Stylist; + use ruff_python_index::Indexer; + use ruff_source_file::Locator; use crate::line_width::LineLength; use crate::registry::Rule; diff --git a/crates/ruff/src/checkers/tokens.rs b/crates/ruff/src/checkers/tokens.rs index 06cfafd4a7..04dc6c599f 100644 --- a/crates/ruff/src/checkers/tokens.rs +++ b/crates/ruff/src/checkers/tokens.rs @@ -6,7 +6,8 @@ use rustpython_parser::lexer::LexResult; use rustpython_parser::Tok; use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use crate::directives::TodoComment; use crate::lex::docstring_detection::StateMachine; diff --git a/crates/ruff/src/directives.rs b/crates/ruff/src/directives.rs index 06e8c09272..a4b7fbb5d3 100644 --- a/crates/ruff/src/directives.rs +++ b/crates/ruff/src/directives.rs @@ -7,7 +7,8 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use rustpython_parser::lexer::LexResult; use rustpython_parser::Tok; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use crate::noqa::NoqaMapping; use crate::settings::Settings; @@ -352,7 +353,8 @@ mod tests { use rustpython_parser::lexer::LexResult; use rustpython_parser::{lexer, Mode}; - use ruff_python_ast::source_code::{Indexer, Locator}; + use ruff_python_index::Indexer; + use ruff_source_file::Locator; use crate::directives::{ extract_isort_directives, extract_noqa_line_for, TodoDirective, TodoDirectiveKind, diff --git a/crates/ruff/src/doc_lines.rs b/crates/ruff/src/doc_lines.rs index 32dea215bd..bd41a41da1 100644 --- a/crates/ruff/src/doc_lines.rs +++ b/crates/ruff/src/doc_lines.rs @@ -4,13 +4,12 @@ use std::iter::FusedIterator; use ruff_text_size::TextSize; -use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt, Suite}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite}; use rustpython_parser::lexer::LexResult; use rustpython_parser::Tok; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; -use ruff_python_trivia::UniversalNewlineIterator; +use ruff_source_file::{Locator, UniversalNewlineIterator}; /// Extract doc lines (standalone comments) from a token sequence. pub(crate) fn doc_lines_from_tokens(lxr: &[LexResult]) -> DocLines { diff --git a/crates/ruff/src/docstrings/extraction.rs b/crates/ruff/src/docstrings/extraction.rs index d4ae103b2f..1de50930a0 100644 --- a/crates/ruff/src/docstrings/extraction.rs +++ b/crates/ruff/src/docstrings/extraction.rs @@ -1,6 +1,6 @@ //! Extract docstrings from an AST. -use rustpython_parser::ast::{self, Constant, Expr, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Stmt}; use ruff_python_semantic::{Definition, DefinitionId, Definitions, Member, MemberKind}; diff --git a/crates/ruff/src/docstrings/mod.rs b/crates/ruff/src/docstrings/mod.rs index 97b44784b5..3f5c64addb 100644 --- a/crates/ruff/src/docstrings/mod.rs +++ b/crates/ruff/src/docstrings/mod.rs @@ -2,7 +2,7 @@ use std::fmt::{Debug, Formatter}; use std::ops::Deref; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_python_semantic::Definition; diff --git a/crates/ruff/src/docstrings/sections.rs b/crates/ruff/src/docstrings/sections.rs index 03ad9510df..d8f6aa2a55 100644 --- a/crates/ruff/src/docstrings/sections.rs +++ b/crates/ruff/src/docstrings/sections.rs @@ -5,7 +5,7 @@ use ruff_python_ast::docstrings::{leading_space, leading_words}; use ruff_text_size::{TextLen, TextRange, TextSize}; use strum_macros::EnumIter; -use ruff_python_trivia::{Line, UniversalNewlineIterator, UniversalNewlines}; +use ruff_source_file::{Line, UniversalNewlineIterator, UniversalNewlines}; use crate::docstrings::styles::SectionStyle; use crate::docstrings::{Docstring, DocstringBody}; diff --git a/crates/ruff/src/importer/insertion.rs b/crates/ruff/src/importer/insertion.rs index 31658caa8e..12eb54d9b4 100644 --- a/crates/ruff/src/importer/insertion.rs +++ b/crates/ruff/src/importer/insertion.rs @@ -2,14 +2,14 @@ use std::ops::Add; use ruff_text_size::TextSize; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::Edit; use ruff_python_ast::helpers::is_docstring_stmt; -use ruff_python_ast::source_code::{Locator, Stylist}; -use ruff_python_trivia::{PythonWhitespace, UniversalNewlineIterator}; -use ruff_textwrap::indent; +use ruff_python_codegen::Stylist; +use ruff_python_trivia::{textwrap::indent, PythonWhitespace}; +use ruff_source_file::{Locator, UniversalNewlineIterator}; #[derive(Debug, Clone, PartialEq, Eq)] pub(super) enum Placement<'a> { @@ -300,12 +300,12 @@ fn match_leading_semicolon(s: &str) -> Option { mod tests { use anyhow::Result; use ruff_text_size::TextSize; - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::lexer::LexResult; use rustpython_parser::Parse; - use ruff_python_ast::source_code::{Locator, Stylist}; - use ruff_python_trivia::LineEnding; + use ruff_python_codegen::Stylist; + use ruff_source_file::{LineEnding, Locator}; use super::Insertion; @@ -313,7 +313,7 @@ mod tests { fn start_of_file() -> Result<()> { fn insert(contents: &str) -> Result { let program = Suite::parse(contents, "")?; - let tokens: Vec = ruff_rustpython::tokenize(contents); + let tokens: Vec = ruff_python_parser::tokenize(contents); let locator = Locator::new(contents); let stylist = Stylist::from_tokens(&tokens, &locator); Ok(Insertion::start_of_file(&program, &locator, &stylist)) @@ -424,7 +424,7 @@ x = 1 #[test] fn start_of_block() { fn insert(contents: &str, offset: TextSize) -> Insertion { - let tokens: Vec = ruff_rustpython::tokenize(contents); + let tokens: Vec = ruff_python_parser::tokenize(contents); let locator = Locator::new(contents); let stylist = Stylist::from_tokens(&tokens, &locator); Insertion::start_of_block(offset, &locator, &stylist) diff --git a/crates/ruff/src/importer/mod.rs b/crates/ruff/src/importer/mod.rs index 6acab6e471..a4147e2e7f 100644 --- a/crates/ruff/src/importer/mod.rs +++ b/crates/ruff/src/importer/mod.rs @@ -8,13 +8,14 @@ use std::error::Error; use anyhow::Result; use libcst_native::{ImportAlias, Name, NameOrAttribute}; use ruff_text_size::TextSize; -use rustpython_parser::ast::{self, Ranged, Stmt, Suite}; +use rustpython_ast::{self as ast, Ranged, Stmt, Suite}; use ruff_diagnostics::Edit; use ruff_python_ast::imports::{AnyImport, Import, ImportFrom}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; use ruff_python_semantic::SemanticModel; -use ruff_textwrap::indent; +use ruff_python_trivia::textwrap::indent; +use ruff_source_file::Locator; use crate::autofix; use crate::autofix::codemods::CodegenStylist; diff --git a/crates/ruff/src/jupyter/notebook.rs b/crates/ruff/src/jupyter/notebook.rs index 8e5e2a6b39..50cd682822 100644 --- a/crates/ruff/src/jupyter/notebook.rs +++ b/crates/ruff/src/jupyter/notebook.rs @@ -10,7 +10,7 @@ use serde::Serialize; use serde_json::error::Category; use ruff_diagnostics::Diagnostic; -use ruff_python_trivia::{NewlineWithTrailingNewline, UniversalNewlineIterator}; +use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlineIterator}; use ruff_text_size::{TextRange, TextSize}; use rustpython_parser::lexer::lex; use rustpython_parser::Mode; diff --git a/crates/ruff/src/lib.rs b/crates/ruff/src/lib.rs index 0f65d8ffbf..c10ba7e96c 100644 --- a/crates/ruff/src/lib.rs +++ b/crates/ruff/src/lib.rs @@ -5,7 +5,6 @@ //! //! [Ruff]: https://github.com/astral-sh/ruff -pub use ruff_python_ast::source_code::round_trip; pub use rule_selector::RuleSelector; pub use rules::pycodestyle::rules::IOError; diff --git a/crates/ruff/src/linter.rs b/crates/ruff/src/linter.rs index 768fb36faa..92589dc427 100644 --- a/crates/ruff/src/linter.rs +++ b/crates/ruff/src/linter.rs @@ -12,8 +12,10 @@ use rustpython_parser::ParseError; use ruff_diagnostics::Diagnostic; use ruff_python_ast::imports::ImportMap; -use ruff_python_ast::source_code::{Indexer, Locator, SourceFileBuilder, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; use ruff_python_stdlib::path::is_python_stub_file; +use ruff_source_file::{Locator, SourceFileBuilder}; use crate::autofix::{fix_file, FixResult}; use crate::checkers::ast::check_ast; @@ -136,7 +138,7 @@ pub fn check_path( .iter_enabled() .any(|rule_code| rule_code.lint_source().is_imports()); if use_ast || use_imports || use_doc_lines { - match ruff_rustpython::parse_program_tokens(tokens, &path.to_string_lossy()) { + match ruff_python_parser::parse_program_tokens(tokens, &path.to_string_lossy()) { Ok(python_ast) => { if use_ast { diagnostics.extend(check_ast( @@ -258,7 +260,7 @@ pub fn add_noqa_to_path(path: &Path, package: Option<&Path>, settings: &Settings let contents = std::fs::read_to_string(path)?; // Tokenize once. - let tokens: Vec = ruff_rustpython::tokenize(&contents); + let tokens: Vec = ruff_python_parser::tokenize(&contents); // Map row and column locations to byte slices (lazily). let locator = Locator::new(&contents); @@ -326,7 +328,7 @@ pub fn lint_only( source_kind: Option<&SourceKind>, ) -> LinterResult<(Vec, Option)> { // Tokenize once. - let tokens: Vec = ruff_rustpython::tokenize(contents); + let tokens: Vec = ruff_python_parser::tokenize(contents); // Map row and column locations to byte slices (lazily). let locator = Locator::new(contents); @@ -418,7 +420,7 @@ pub fn lint_fix<'a>( // Continuously autofix until the source code stabilizes. loop { // Tokenize once. - let tokens: Vec = ruff_rustpython::tokenize(&transformed); + let tokens: Vec = ruff_python_parser::tokenize(&transformed); // Map row and column locations to byte slices (lazily). let locator = Locator::new(&transformed); diff --git a/crates/ruff/src/logging.rs b/crates/ruff/src/logging.rs index df950899eb..e224f84e30 100644 --- a/crates/ruff/src/logging.rs +++ b/crates/ruff/src/logging.rs @@ -9,7 +9,7 @@ use log::Level; use once_cell::sync::Lazy; use rustpython_parser::{ParseError, ParseErrorType}; -use ruff_python_ast::source_code::{OneIndexed, SourceCode, SourceLocation}; +use ruff_source_file::{OneIndexed, SourceCode, SourceLocation}; use crate::fs; use crate::jupyter::Notebook; diff --git a/crates/ruff/src/message/azure.rs b/crates/ruff/src/message/azure.rs index f775fe27ab..a95a7ea217 100644 --- a/crates/ruff/src/message/azure.rs +++ b/crates/ruff/src/message/azure.rs @@ -1,6 +1,6 @@ use std::io::Write; -use ruff_python_ast::source_code::SourceLocation; +use ruff_source_file::SourceLocation; use crate::message::{Emitter, EmitterContext, Message}; use crate::registry::AsRule; diff --git a/crates/ruff/src/message/diff.rs b/crates/ruff/src/message/diff.rs index c665578c2a..a3a03db244 100644 --- a/crates/ruff/src/message/diff.rs +++ b/crates/ruff/src/message/diff.rs @@ -7,7 +7,7 @@ use ruff_text_size::{TextRange, TextSize}; use similar::{ChangeTag, TextDiff}; use ruff_diagnostics::{Applicability, Fix}; -use ruff_python_ast::source_code::{OneIndexed, SourceFile}; +use ruff_source_file::{OneIndexed, SourceFile}; use crate::message::Message; diff --git a/crates/ruff/src/message/github.rs b/crates/ruff/src/message/github.rs index 97a28a4e97..86e8c23fea 100644 --- a/crates/ruff/src/message/github.rs +++ b/crates/ruff/src/message/github.rs @@ -1,6 +1,6 @@ use std::io::Write; -use ruff_python_ast::source_code::SourceLocation; +use ruff_source_file::SourceLocation; use crate::fs::relativize_path; use crate::message::{Emitter, EmitterContext, Message}; diff --git a/crates/ruff/src/message/gitlab.rs b/crates/ruff/src/message/gitlab.rs index 8538245b39..00720fbc54 100644 --- a/crates/ruff/src/message/gitlab.rs +++ b/crates/ruff/src/message/gitlab.rs @@ -6,7 +6,7 @@ use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; use serde_json::json; -use ruff_python_ast::source_code::SourceLocation; +use ruff_source_file::SourceLocation; use crate::fs::{relativize_path, relativize_path_to}; use crate::message::{Emitter, EmitterContext, Message}; diff --git a/crates/ruff/src/message/grouped.rs b/crates/ruff/src/message/grouped.rs index f6f2cd335c..417a39e33c 100644 --- a/crates/ruff/src/message/grouped.rs +++ b/crates/ruff/src/message/grouped.rs @@ -4,7 +4,7 @@ use std::num::NonZeroUsize; use colored::Colorize; -use ruff_python_ast::source_code::OneIndexed; +use ruff_source_file::OneIndexed; use crate::fs::relativize_path; use crate::jupyter::{JupyterIndex, Notebook}; diff --git a/crates/ruff/src/message/json.rs b/crates/ruff/src/message/json.rs index 8a80635be9..6d17df0fcc 100644 --- a/crates/ruff/src/message/json.rs +++ b/crates/ruff/src/message/json.rs @@ -5,7 +5,7 @@ use serde::{Serialize, Serializer}; use serde_json::{json, Value}; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::SourceCode; +use ruff_source_file::SourceCode; use crate::message::{Emitter, EmitterContext, Message}; use crate::registry::AsRule; diff --git a/crates/ruff/src/message/junit.rs b/crates/ruff/src/message/junit.rs index 26d7161f2e..3a8fdd5a4d 100644 --- a/crates/ruff/src/message/junit.rs +++ b/crates/ruff/src/message/junit.rs @@ -3,7 +3,7 @@ use std::path::Path; use quick_junit::{NonSuccessKind, Report, TestCase, TestCaseStatus, TestSuite}; -use ruff_python_ast::source_code::SourceLocation; +use ruff_source_file::SourceLocation; use crate::message::{ group_messages_by_filename, Emitter, EmitterContext, Message, MessageWithLocation, diff --git a/crates/ruff/src/message/mod.rs b/crates/ruff/src/message/mod.rs index f86e408ecd..33f0eb98a3 100644 --- a/crates/ruff/src/message/mod.rs +++ b/crates/ruff/src/message/mod.rs @@ -16,7 +16,7 @@ pub use json_lines::JsonLinesEmitter; pub use junit::JunitEmitter; pub use pylint::PylintEmitter; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix}; -use ruff_python_ast::source_code::{SourceFile, SourceLocation}; +use ruff_source_file::{SourceFile, SourceLocation}; pub use text::TextEmitter; mod azure; @@ -155,7 +155,7 @@ mod tests { use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Edit, Fix}; - use ruff_python_ast::source_code::SourceFileBuilder; + use ruff_source_file::SourceFileBuilder; use crate::message::{Emitter, EmitterContext, Message}; diff --git a/crates/ruff/src/message/pylint.rs b/crates/ruff/src/message/pylint.rs index 7453495bb9..1deee6d2f9 100644 --- a/crates/ruff/src/message/pylint.rs +++ b/crates/ruff/src/message/pylint.rs @@ -1,6 +1,6 @@ use std::io::Write; -use ruff_python_ast::source_code::OneIndexed; +use ruff_source_file::OneIndexed; use crate::fs::relativize_path; use crate::message::{Emitter, EmitterContext, Message}; diff --git a/crates/ruff/src/message/text.rs b/crates/ruff/src/message/text.rs index ee27ae28fe..3aa5ebc545 100644 --- a/crates/ruff/src/message/text.rs +++ b/crates/ruff/src/message/text.rs @@ -8,7 +8,7 @@ use bitflags::bitflags; use colored::Colorize; use ruff_text_size::{TextRange, TextSize}; -use ruff_python_ast::source_code::{OneIndexed, SourceLocation}; +use ruff_source_file::{OneIndexed, SourceLocation}; use crate::fs::relativize_path; use crate::jupyter::{JupyterIndex, Notebook}; diff --git a/crates/ruff/src/noqa.rs b/crates/ruff/src/noqa.rs index b895a061ea..48aa350736 100644 --- a/crates/ruff/src/noqa.rs +++ b/crates/ruff/src/noqa.rs @@ -9,11 +9,10 @@ use anyhow::Result; use itertools::Itertools; use log::warn; use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::Locator; -use ruff_python_trivia::LineEnding; +use ruff_source_file::{LineEnding, Locator}; use crate::codes::NoqaCode; use crate::fs::relativize_path; @@ -782,8 +781,7 @@ mod tests { use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::Diagnostic; - use ruff_python_ast::source_code::Locator; - use ruff_python_trivia::LineEnding; + use ruff_source_file::{LineEnding, Locator}; use crate::noqa::{add_noqa_inner, Directive, NoqaMapping, ParsedFileExemption}; use crate::rules::pycodestyle::rules::AmbiguousVariableName; diff --git a/crates/ruff/src/pyproject_toml.rs b/crates/ruff/src/pyproject_toml.rs index d320f091a7..c06fafb140 100644 --- a/crates/ruff/src/pyproject_toml.rs +++ b/crates/ruff/src/pyproject_toml.rs @@ -5,7 +5,7 @@ use ruff_text_size::{TextRange, TextSize}; use serde::{Deserialize, Serialize}; use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::SourceFile; +use ruff_source_file::SourceFile; use crate::message::Message; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/airflow/rules/task_variable_name.rs b/crates/ruff/src/rules/airflow/rules/task_variable_name.rs index 9decaf65f7..383f249284 100644 --- a/crates/ruff/src/rules/airflow/rules/task_variable_name.rs +++ b/crates/ruff/src/rules/airflow/rules/task_variable_name.rs @@ -1,10 +1,10 @@ +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::find_keyword; -use rustpython_parser::ast::Constant; +use rustpython_ast::Constant; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/eradicate/detection.rs b/crates/ruff/src/rules/eradicate/detection.rs index 4f3a77f15a..c857883958 100644 --- a/crates/ruff/src/rules/eradicate/detection.rs +++ b/crates/ruff/src/rules/eradicate/detection.rs @@ -1,7 +1,7 @@ /// See: [eradicate.py](https://github.com/myint/eradicate/blob/98f199940979c94447a461d50d27862b118b282d/eradicate.py) use once_cell::sync::Lazy; use regex::Regex; -use rustpython_parser::ast::Suite; +use rustpython_ast::Suite; use rustpython_parser::Parse; static ALLOWLIST_REGEX: Lazy = Lazy::new(|| { diff --git a/crates/ruff/src/rules/eradicate/rules/commented_out_code.rs b/crates/ruff/src/rules/eradicate/rules/commented_out_code.rs index 15e23ab6f1..69e451fa55 100644 --- a/crates/ruff/src/rules/eradicate/rules/commented_out_code.rs +++ b/crates/ruff/src/rules/eradicate/rules/commented_out_code.rs @@ -1,6 +1,7 @@ use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use crate::registry::Rule; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/flake8_2020/helpers.rs b/crates/ruff/src/rules/flake8_2020/helpers.rs index 3f86f9bfd9..b58edccbbc 100644 --- a/crates/ruff/src/rules/flake8_2020/helpers.rs +++ b/crates/ruff/src/rules/flake8_2020/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_python_semantic::SemanticModel; diff --git a/crates/ruff/src/rules/flake8_2020/rules/compare.rs b/crates/ruff/src/rules/flake8_2020/rules/compare.rs index 55197df851..313d257677 100644 --- a/crates/ruff/src/rules/flake8_2020/rules/compare.rs +++ b/crates/ruff/src/rules/flake8_2020/rules/compare.rs @@ -1,5 +1,5 @@ use num_bigint::BigInt; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs b/crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs index 47bdd31421..d37df2341c 100644 --- a/crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs +++ b/crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_2020/rules/subscript.rs b/crates/ruff/src/rules/flake8_2020/rules/subscript.rs index 0f18cfae68..d78a80ca51 100644 --- a/crates/ruff/src/rules/flake8_2020/rules/subscript.rs +++ b/crates/ruff/src/rules/flake8_2020/rules/subscript.rs @@ -1,5 +1,5 @@ use num_bigint::BigInt; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_annotations/fixes.rs b/crates/ruff/src/rules/flake8_annotations/fixes.rs index 26ae559005..1b7c176a4a 100644 --- a/crates/ruff/src/rules/flake8_annotations/fixes.rs +++ b/crates/ruff/src/rules/flake8_annotations/fixes.rs @@ -1,9 +1,9 @@ use anyhow::{bail, Result}; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; /// ANN204 pub(crate) fn add_return_annotation( diff --git a/crates/ruff/src/rules/flake8_annotations/helpers.rs b/crates/ruff/src/rules/flake8_annotations/helpers.rs index d73825fe07..60a6e7a9c4 100644 --- a/crates/ruff/src/rules/flake8_annotations/helpers.rs +++ b/crates/ruff/src/rules/flake8_annotations/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Arguments, Expr, Stmt}; +use rustpython_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_python_ast::cast; use ruff_python_semantic::analyze::visibility; diff --git a/crates/ruff/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff/src/rules/flake8_annotations/rules/definition.rs index aa5ef05607..a9929d1200 100644 --- a/crates/ruff/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff/src/rules/flake8_annotations/rules/definition.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ArgWithDefault, Constant, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, ArgWithDefault, Constant, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -6,7 +6,7 @@ use ruff_python_ast::cast; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::statement_visitor::StatementVisitor; -use ruff_python_ast::typing::parse_type_annotation; +use ruff_python_parser::typing::parse_type_annotation; use ruff_python_semantic::analyze::visibility; use ruff_python_semantic::{Definition, Member, MemberKind}; use ruff_python_stdlib::typing::simple_magic_return_type; @@ -462,7 +462,8 @@ fn check_dynamically_typed( }) = annotation { // Quoted annotations - if let Ok((parsed_annotation, _)) = parse_type_annotation(string, *range, checker.locator()) + if let Ok((parsed_annotation, _)) = + parse_type_annotation(string, *range, checker.locator().contents()) { if type_hint_resolves_to_any( &parsed_annotation, diff --git a/crates/ruff/src/rules/flake8_async/rules/blocking_http_call.rs b/crates/ruff/src/rules/flake8_async/rules/blocking_http_call.rs index 2ab4e94f4d..13451f7e76 100644 --- a/crates/ruff/src/rules/flake8_async/rules/blocking_http_call.rs +++ b/crates/ruff/src/rules/flake8_async/rules/blocking_http_call.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_async/rules/blocking_os_call.rs b/crates/ruff/src/rules/flake8_async/rules/blocking_os_call.rs index c08dece6f4..bc3aabaee4 100644 --- a/crates/ruff/src/rules/flake8_async/rules/blocking_os_call.rs +++ b/crates/ruff/src/rules/flake8_async/rules/blocking_os_call.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_async/rules/open_sleep_or_subprocess_call.rs b/crates/ruff/src/rules/flake8_async/rules/open_sleep_or_subprocess_call.rs index 0d1f813ec6..8fa2c81464 100644 --- a/crates/ruff/src/rules/flake8_async/rules/open_sleep_or_subprocess_call.rs +++ b/crates/ruff/src/rules/flake8_async/rules/open_sleep_or_subprocess_call.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/helpers.rs b/crates/ruff/src/rules/flake8_bandit/helpers.rs index b480934b8b..b83a3f4d10 100644 --- a/crates/ruff/src/rules/flake8_bandit/helpers.rs +++ b/crates/ruff/src/rules/flake8_bandit/helpers.rs @@ -1,6 +1,6 @@ use once_cell::sync::Lazy; use regex::Regex; -use rustpython_parser::ast::{self, Constant, Expr}; +use rustpython_ast::{self as ast, Constant, Expr}; use ruff_python_semantic::SemanticModel; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs b/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs index 28fba960c0..f05c01fe3b 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/bad_file_permissions.rs b/crates/ruff/src/rules/flake8_bandit/rules/bad_file_permissions.rs index 1d6d66423a..530b7d0361 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/bad_file_permissions.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/bad_file_permissions.rs @@ -1,5 +1,5 @@ use num_traits::ToPrimitive; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/exec_used.rs b/crates/ruff/src/rules/flake8_bandit/rules/exec_used.rs index af0caabc1d..51bd2834e4 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/exec_used.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/exec_used.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_default.rs b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_default.rs index 7883d346ac..57116c9317 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_default.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arg, ArgWithDefault, Arguments, Expr, Ranged}; +use rustpython_ast::{Arg, ArgWithDefault, Arguments, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs index 5449b51171..9969b09634 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Keyword, Ranged}; +use rustpython_ast::{Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_string.rs b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_string.rs index c48036517f..ea347d2ced 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_string.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_password_string.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs index 25d3fd43ca..8c1d521113 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs @@ -1,6 +1,6 @@ use once_cell::sync::Lazy; use regex::Regex; -use rustpython_parser::ast::{self, Expr, Operator, Ranged}; +use rustpython_ast::{self as ast, Expr, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs index 2fae004907..efe937da6a 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs b/crates/ruff/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs index f46bac5329..81577a894b 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs b/crates/ruff/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs index d4f96727b8..ad9f704ebd 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs @@ -1,5 +1,5 @@ use ruff_python_ast::helpers::find_keyword; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs b/crates/ruff/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs index b3f25bd2ba..46c5c50b1e 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/paramiko_calls.rs b/crates/ruff/src/rules/flake8_bandit/rules/paramiko_calls.rs index e0e50828d1..f57fa30d9f 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/paramiko_calls.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/paramiko_calls.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs b/crates/ruff/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs index 546c2b963d..d1eac48e4f 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/request_without_timeout.rs b/crates/ruff/src/rules/flake8_bandit/rules/request_without_timeout.rs index fdb46fc620..c37794ae70 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/request_without_timeout.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/request_without_timeout.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs b/crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs index d8e83953ae..306230d70e 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs @@ -1,6 +1,6 @@ //! Checks relating to shell injection. -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/snmp_insecure_version.rs b/crates/ruff/src/rules/flake8_bandit/rules/snmp_insecure_version.rs index 08a97668b4..3fc247ff11 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/snmp_insecure_version.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/snmp_insecure_version.rs @@ -1,5 +1,5 @@ use num_traits::{One, Zero}; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs b/crates/ruff/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs index 26d5bae978..7c8f9ba26c 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/suspicious_function_call.rs b/crates/ruff/src/rules/flake8_bandit/rules/suspicious_function_call.rs index 79687fe458..fb5694d6a9 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/suspicious_function_call.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/suspicious_function_call.rs @@ -1,7 +1,7 @@ //! Check for calls to suspicious functions, or calls into suspicious modules. //! //! See: -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/try_except_continue.rs b/crates/ruff/src/rules/flake8_bandit/rules/try_except_continue.rs index a153c99845..43a4c7a86b 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/try_except_continue.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/try_except_continue.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ExceptHandler, Expr, Ranged, Stmt}; +use rustpython_ast::{ExceptHandler, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/try_except_pass.rs b/crates/ruff/src/rules/flake8_bandit/rules/try_except_pass.rs index 2febb18936..7d4593ce42 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/try_except_pass.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/try_except_pass.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ExceptHandler, Expr, Ranged, Stmt}; +use rustpython_ast::{ExceptHandler, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs b/crates/ruff/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs index 9cf1d37ba9..76aee42ac5 100644 --- a/crates/ruff/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs +++ b/crates/ruff/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_blind_except/rules/blind_except.rs b/crates/ruff/src/rules/flake8_blind_except/rules/blind_except.rs index d80f2216ae..bc3aae4647 100644 --- a/crates/ruff/src/rules/flake8_blind_except/rules/blind_except.rs +++ b/crates/ruff/src/rules/flake8_blind_except/rules/blind_except.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs index 01cc630de6..2572b02619 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_default_value_in_function_definition.rs b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_default_value_in_function_definition.rs index 1e853abb87..cce7960f1d 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_default_value_in_function_definition.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_default_value_in_function_definition.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ArgWithDefault, Arguments, Decorator}; +use rustpython_ast::{ArgWithDefault, Arguments, Decorator}; use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_positional_value_in_function_call.rs b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_positional_value_in_function_call.rs index 95b84c8b9c..876a05cee0 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_positional_value_in_function_call.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_boolean_positional_value_in_function_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_positional_boolean_in_def.rs b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_positional_boolean_in_def.rs index 68dc43238f..888ddf66a6 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/rules/check_positional_boolean_in_def.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/rules/check_positional_boolean_in_def.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Constant, Decorator, Expr, Ranged}; +use rustpython_ast::{self as ast, ArgWithDefault, Arguments, Constant, Decorator, Expr, Ranged}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs b/crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs index 4c16954baa..f8a4d24912 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs index 56b43f77df..80e990f04a 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, ExprContext, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, ExprContext, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/assert_raises_exception.rs b/crates/ruff/src/rules/flake8_bugbear/rules/assert_raises_exception.rs index d459718b37..7aabb5f6c8 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/assert_raises_exception.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/assert_raises_exception.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged, WithItem}; +use rustpython_ast::{self as ast, Expr, Ranged, WithItem}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs b/crates/ruff/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs index 0921bf04e5..74aa6fc948 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/cached_instance_method.rs b/crates/ruff/src/rules/flake8_bugbear/rules/cached_instance_method.rs index b12482599d..de1ee325d3 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/cached_instance_method.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/cached_instance_method.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Decorator, Expr, Ranged}; +use rustpython_ast::{self as ast, Decorator, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index 388d4a0128..89d6848c17 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_text_size::TextRange; use rustc_hash::{FxHashMap, FxHashSet}; -use rustpython_parser::ast::{self, ExceptHandler, Expr, ExprContext, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, ExprContext, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_value.rs b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_value.rs index e66da4623c..66b6c3b407 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_value.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_value.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs b/crates/ruff/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs index 1ee0f711ee..f75fe3dae2 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs @@ -1,5 +1,5 @@ -use rustpython_parser::ast::{self, Ranged}; -use rustpython_parser::ast::{ExceptHandler, Expr}; +use rustpython_ast::{self as ast, Ranged}; +use rustpython_ast::{ExceptHandler, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs b/crates/ruff/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs index cd195a8635..f028937b15 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs @@ -1,6 +1,6 @@ use std::collections::VecDeque; -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/f_string_docstring.rs b/crates/ruff/src/rules/flake8_bugbear/rules/f_string_docstring.rs index 1a5bd2e011..962cebb4af 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/f_string_docstring.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/f_string_docstring.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Stmt}; +use rustpython_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs index 7306024965..241e242eaf 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Expr, Ranged}; +use rustpython_ast::{self as ast, ArgWithDefault, Arguments, Expr, Ranged}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs b/crates/ruff/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs index 5900cab1e0..0c60522638 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Comprehension, Expr, ExprContext, Ranged, Stmt}; +use rustpython_ast::{self as ast, Comprehension, Expr, ExprContext, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index ffd202c01d..311d9e8224 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs b/crates/ruff/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs index 15b8aca374..b3c3c4a4e1 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs b/crates/ruff/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs index 8b7efb83ec..213a5736a5 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, ArgWithDefault, Expr, Ranged}; +use rustpython_ast::{self as ast, ArgWithDefault, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index 4af5133187..35a850edd0 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ArgWithDefault, Arguments, Ranged}; +use rustpython_ast::{ArgWithDefault, Arguments, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs b/crates/ruff/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs index af04d6d632..371cf0b995 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/raise_literal.rs b/crates/ruff/src/rules/flake8_bugbear/rules/raise_literal.rs index 8adc4f0150..3c1036086d 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/raise_literal.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/raise_literal.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs b/crates/ruff/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs index e619ecc2b8..3006bcd65a 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs @@ -1,5 +1,5 @@ +use rustpython_ast::Stmt; use rustpython_parser::ast; -use rustpython_parser::ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs b/crates/ruff/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs index c70791d136..271a9cbae9 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Ranged}; +use rustpython_ast::{self as ast, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs b/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs index 865456d3f2..0bc11225d1 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs b/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs index 736470b3b9..cb1575bb4a 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Comprehension, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Comprehension, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index fe107f5fc0..33974d6a86 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -1,9 +1,9 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, ExprContext, Identifier, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Identifier, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Generator; +use ruff_python_codegen::Generator; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs b/crates/ruff/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs index dae1e2168e..aef48b8cb1 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs b/crates/ruff/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs index 7f4e0f963a..7412466034 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs b/crates/ruff/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs index b562491334..0dd9a35ba7 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, Expr, Ranged, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs b/crates/ruff/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs index 0c5cad9903..94b0fbcc93 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index 8b67970643..7af165e271 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs b/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs index 24cd5b9f35..71982ac702 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/useless_comparison.rs b/crates/ruff/src/rules/flake8_bugbear/rules/useless_comparison.rs index 1654ef13ce..8f415f6be3 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/useless_comparison.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/useless_comparison.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs b/crates/ruff/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs index 8e734d70cb..56ea81dce4 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/useless_expression.rs b/crates/ruff/src/rules/flake8_bugbear/rules/useless_expression.rs index 24361c1895..132b4464e3 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/useless_expression.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/useless_expression.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index 7629b37f3e..beadd8dbcc 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs b/crates/ruff/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs index f2e95545e5..cbb62c03a3 100644 --- a/crates/ruff/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs +++ b/crates/ruff/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arg, Ranged}; +use rustpython_ast::{Arg, Ranged}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs b/crates/ruff/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs index 353e92f506..fdcca49e16 100644 --- a/crates/ruff/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs +++ b/crates/ruff/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs @@ -1,6 +1,6 @@ use ruff_text_size::TextRange; +use rustpython_ast::Decorator; use rustpython_parser::ast; -use rustpython_parser::ast::Decorator; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_commas/rules/trailing_commas.rs b/crates/ruff/src/rules/flake8_commas/rules/trailing_commas.rs index 1335ff3bb4..f00a454297 100644 --- a/crates/ruff/src/rules/flake8_commas/rules/trailing_commas.rs +++ b/crates/ruff/src/rules/flake8_commas/rules/trailing_commas.rs @@ -6,7 +6,7 @@ use rustpython_parser::Tok; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::registry::Rule; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/flake8_comprehensions/fixes.rs b/crates/ruff/src/rules/flake8_comprehensions/fixes.rs index f8018568f9..4014adf105 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/fixes.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/fixes.rs @@ -8,10 +8,11 @@ use libcst_native::{ TrailingWhitespace, Tuple, }; use ruff_text_size::TextRange; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{Edit, Fix}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::rules::flake8_comprehensions::rules::ObjectType; @@ -27,7 +28,7 @@ use crate::{ pub(crate) fn fix_unnecessary_generator_list( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { // Expr(Call(GeneratorExp)))) -> Expr(ListComp))) let module_text = locator.slice(expr.range()); @@ -59,7 +60,7 @@ pub(crate) fn fix_unnecessary_generator_list( /// (C401) Convert `set(x for x in y)` to `{x for x in y}`. pub(crate) fn fix_unnecessary_generator_set( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -97,7 +98,7 @@ pub(crate) fn fix_unnecessary_generator_set( /// range(3)}`. pub(crate) fn fix_unnecessary_generator_dict( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -140,7 +141,7 @@ pub(crate) fn fix_unnecessary_generator_dict( /// (C403) Convert `set([x for x in y])` to `{x for x in y}`. pub(crate) fn fix_unnecessary_list_comprehension_set( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -176,7 +177,7 @@ pub(crate) fn fix_unnecessary_list_comprehension_set( /// range(3)}`. pub(crate) fn fix_unnecessary_list_comprehension_dict( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -263,7 +264,7 @@ fn drop_trailing_comma<'a>( /// (C405) Convert `set((1, 2))` to `{1, 2}`. pub(crate) fn fix_unnecessary_literal_set( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -307,7 +308,7 @@ pub(crate) fn fix_unnecessary_literal_set( /// (C406) Convert `dict([(1, 2)])` to `{1: 2}`. pub(crate) fn fix_unnecessary_literal_dict( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let locator = checker.locator(); let stylist = checker.stylist(); @@ -373,7 +374,7 @@ pub(crate) fn fix_unnecessary_literal_dict( /// (C408) pub(crate) fn fix_unnecessary_collection_call( checker: &Checker, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { enum Collection { Tuple, @@ -534,7 +535,7 @@ fn pad_expression(content: String, range: TextRange, checker: &Checker) -> Strin pub(crate) fn fix_unnecessary_literal_within_tuple_call( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -584,7 +585,7 @@ pub(crate) fn fix_unnecessary_literal_within_tuple_call( pub(crate) fn fix_unnecessary_literal_within_list_call( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -636,7 +637,7 @@ pub(crate) fn fix_unnecessary_literal_within_list_call( pub(crate) fn fix_unnecessary_list_call( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { // Expr(Call(List|Tuple)))) -> Expr(List|Tuple))) let module_text = locator.slice(expr.range()); @@ -658,7 +659,7 @@ pub(crate) fn fix_unnecessary_list_call( pub(crate) fn fix_unnecessary_call_around_sorted( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -770,7 +771,7 @@ pub(crate) fn fix_unnecessary_call_around_sorted( pub(crate) fn fix_unnecessary_double_cast_or_process( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -800,7 +801,7 @@ pub(crate) fn fix_unnecessary_double_cast_or_process( pub(crate) fn fix_unnecessary_comprehension( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -887,8 +888,8 @@ pub(crate) fn fix_unnecessary_comprehension( pub(crate) fn fix_unnecessary_map( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, - parent: Option<&rustpython_parser::ast::Expr>, + expr: &rustpython_ast::Expr, + parent: Option<&rustpython_ast::Expr>, object_type: ObjectType, ) -> Result { let module_text = locator.slice(expr.range()); @@ -1017,7 +1018,7 @@ pub(crate) fn fix_unnecessary_map( // If the expression is embedded in an f-string, surround it with spaces to avoid // syntax errors. if matches!(object_type, ObjectType::Set | ObjectType::Dict) { - if parent.map_or(false, rustpython_parser::ast::Expr::is_formatted_value_expr) { + if parent.map_or(false, rustpython_ast::Expr::is_formatted_value_expr) { content = format!(" {content} "); } } @@ -1032,7 +1033,7 @@ pub(crate) fn fix_unnecessary_map( pub(crate) fn fix_unnecessary_literal_within_dict_call( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { let module_text = locator.slice(expr.range()); let mut tree = match_expression(module_text)?; @@ -1051,7 +1052,7 @@ pub(crate) fn fix_unnecessary_literal_within_dict_call( pub(crate) fn fix_unnecessary_comprehension_any_all( locator: &Locator, stylist: &Stylist, - expr: &rustpython_parser::ast::Expr, + expr: &rustpython_ast::Expr, ) -> Result { // Expr(ListComp) -> Expr(GeneratorExp) let module_text = locator.slice(expr.range()); diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs index 19af6be297..8b72c642ec 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword}; +use rustpython_ast::{self as ast, Expr, Keyword}; pub(super) fn expr_name(func: &Expr) -> Option<&str> { if let Expr::Name(ast::ExprName { id, .. }) = func { diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index d4da905087..c16dfad104 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index 6a51574d45..6b1bf1dbae 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index ce96d0048b..568097b227 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Comprehension, Expr, Ranged}; +use rustpython_ast::{self as ast, Comprehension, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs index a3b7a1f985..f34e601239 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::Violation; use ruff_diagnostics::{AutofixKind, Diagnostic}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index c9df27bf22..30f63dd04d 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index fe8c8afb0e..f81a28c194 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index d6cfc5a654..5fc61a659f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index 44fa61ced3..90e247f74f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 3070171d6b..3487406f46 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index d425003f04..da21ddd459 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 9bf415f8f8..1de2900e03 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index 8c981d062a..9fa4875be8 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 43f4372404..3fcefb9bc7 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index 37f6790103..1215b5d3e2 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index 6ee6d854d4..9d6d4c138b 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index 4226aa695b..d1afdb9af2 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 6867aa2373..41a1a7af20 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Arguments, Expr, ExprContext, Ranged, Stmt}; +use rustpython_ast::{self as ast, Arguments, Expr, ExprContext, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Fix}; diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index 896b9128a5..9e3c7badf5 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -1,5 +1,5 @@ use num_bigint::BigInt; -use rustpython_parser::ast::{self, Constant, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_copyright/rules/missing_copyright_notice.rs b/crates/ruff/src/rules/flake8_copyright/rules/missing_copyright_notice.rs index ce3cca98c7..3c99bb487f 100644 --- a/crates/ruff/src/rules/flake8_copyright/rules/missing_copyright_notice.rs +++ b/crates/ruff/src/rules/flake8_copyright/rules/missing_copyright_notice.rs @@ -2,7 +2,7 @@ use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs index 1c41e6c702..9082b721f3 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_date_today.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_date_today.rs index 282dff64fe..2010d0a15e 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_date_today.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_date_today.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs index 5ce71fa558..7023501d28 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Keyword}; +use rustpython_ast::{Expr, Keyword}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs index 478fc06c10..5a06e977f8 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Keyword}; +use rustpython_ast::{Expr, Keyword}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs index f690027e80..216adc3b72 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr}; +use rustpython_ast::{self as ast, Constant, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_today.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_today.rs index 0738b1ae70..ea6a5cade4 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_today.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_today.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs index c63c79483f..1384ac3eae 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs index 1c92b1ea66..c011d643c6 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs index cf153a5c7d..8f46629e29 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Keyword}; +use rustpython_ast::{Expr, Keyword}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/helpers.rs b/crates/ruff/src/rules/flake8_datetimez/rules/helpers.rs index bd237f9da1..30e13958c4 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, ExprAttribute}; +use rustpython_ast::{Expr, ExprAttribute}; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_debugger/rules/debugger.rs b/crates/ruff/src/rules/flake8_debugger/rules/debugger.rs index 08a022e62a..51a7dc6435 100644 --- a/crates/ruff/src/rules/flake8_debugger/rules/debugger.rs +++ b/crates/ruff/src/rules/flake8_debugger/rules/debugger.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged, Stmt}; +use rustpython_ast::{Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/all_with_model_form.rs b/crates/ruff/src/rules/flake8_django/rules/all_with_model_form.rs index 63dc9551d6..1140c908da 100644 --- a/crates/ruff/src/rules/flake8_django/rules/all_with_model_form.rs +++ b/crates/ruff/src/rules/flake8_django/rules/all_with_model_form.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/exclude_with_model_form.rs b/crates/ruff/src/rules/flake8_django/rules/exclude_with_model_form.rs index 8079eb3099..fecc81a71e 100644 --- a/crates/ruff/src/rules/flake8_django/rules/exclude_with_model_form.rs +++ b/crates/ruff/src/rules/flake8_django/rules/exclude_with_model_form.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/helpers.rs b/crates/ruff/src/rules/flake8_django/rules/helpers.rs index 5c208cc235..2052445b33 100644 --- a/crates/ruff/src/rules/flake8_django/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_django/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_python_semantic::SemanticModel; diff --git a/crates/ruff/src/rules/flake8_django/rules/locals_in_render_function.rs b/crates/ruff/src/rules/flake8_django/rules/locals_in_render_function.rs index bcff921caa..b3cf6cb9f5 100644 --- a/crates/ruff/src/rules/flake8_django/rules/locals_in_render_function.rs +++ b/crates/ruff/src/rules/flake8_django/rules/locals_in_render_function.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/model_without_dunder_str.rs b/crates/ruff/src/rules/flake8_django/rules/model_without_dunder_str.rs index 6c0718f95a..020799b27b 100644 --- a/crates/ruff/src/rules/flake8_django/rules/model_without_dunder_str.rs +++ b/crates/ruff/src/rules/flake8_django/rules/model_without_dunder_str.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs b/crates/ruff/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs index 9e823858c0..7dce1671c0 100644 --- a/crates/ruff/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs +++ b/crates/ruff/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Decorator, Ranged}; +use rustpython_ast::{Decorator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/nullable_model_string_field.rs b/crates/ruff/src/rules/flake8_django/rules/nullable_model_string_field.rs index 2fc19f4f28..6621f55e2b 100644 --- a/crates/ruff/src/rules/flake8_django/rules/nullable_model_string_field.rs +++ b/crates/ruff/src/rules/flake8_django/rules/nullable_model_string_field.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs b/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs index b46d825ca2..a5cbde47dc 100644 --- a/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs +++ b/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_errmsg/rules/string_in_exception.rs b/crates/ruff/src/rules/flake8_errmsg/rules/string_in_exception.rs index 00a7b8facb..099f18107b 100644 --- a/crates/ruff/src/rules/flake8_errmsg/rules/string_in_exception.rs +++ b/crates/ruff/src/rules/flake8_errmsg/rules/string_in_exception.rs @@ -1,10 +1,10 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, ExprContext, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Generator, Stylist}; use ruff_python_ast::whitespace; +use ruff_python_codegen::{Generator, Stylist}; use crate::checkers::ast::Checker; use crate::registry::{AsRule, Rule}; diff --git a/crates/ruff/src/rules/flake8_executable/rules/mod.rs b/crates/ruff/src/rules/flake8_executable/rules/mod.rs index f854387424..de62b83b21 100644 --- a/crates/ruff/src/rules/flake8_executable/rules/mod.rs +++ b/crates/ruff/src/rules/flake8_executable/rules/mod.rs @@ -4,7 +4,7 @@ use rustpython_parser::lexer::LexResult; use rustpython_parser::Tok; use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; pub(crate) use shebang_leading_whitespace::*; pub(crate) use shebang_missing_executable_file::*; pub(crate) use shebang_missing_python::*; diff --git a/crates/ruff/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs b/crates/ruff/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs index dae3757d67..265b5b3db3 100644 --- a/crates/ruff/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs +++ b/crates/ruff/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs @@ -2,8 +2,8 @@ use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_trivia::is_python_whitespace; +use ruff_source_file::Locator; use crate::registry::AsRule; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/flake8_executable/rules/shebang_not_first_line.rs b/crates/ruff/src/rules/flake8_executable/rules/shebang_not_first_line.rs index 2d8ee35863..9f199d9038 100644 --- a/crates/ruff/src/rules/flake8_executable/rules/shebang_not_first_line.rs +++ b/crates/ruff/src/rules/flake8_executable/rules/shebang_not_first_line.rs @@ -2,8 +2,8 @@ use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_trivia::is_python_whitespace; +use ruff_source_file::Locator; /// ## What it does /// Checks for a shebang directive that is not at the beginning of the file. diff --git a/crates/ruff/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs b/crates/ruff/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs index b82e8d5cb8..e988590dfc 100644 --- a/crates/ruff/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs +++ b/crates/ruff/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; diff --git a/crates/ruff/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs b/crates/ruff/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs index 33e604c821..127652a3c5 100644 --- a/crates/ruff/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs +++ b/crates/ruff/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_gettext/mod.rs b/crates/ruff/src/rules/flake8_gettext/mod.rs index d9d681a85b..d5dd64e753 100644 --- a/crates/ruff/src/rules/flake8_gettext/mod.rs +++ b/crates/ruff/src/rules/flake8_gettext/mod.rs @@ -1,5 +1,5 @@ //! Rules from [flake8-gettext](https://pypi.org/project/flake8-gettext/). -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; pub(crate) mod rules; pub mod settings; diff --git a/crates/ruff/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs b/crates/ruff/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs index 0818ac0d7a..d911d38007 100644 --- a/crates/ruff/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs +++ b/crates/ruff/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs b/crates/ruff/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs index 813d392821..36433620b2 100644 --- a/crates/ruff/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs +++ b/crates/ruff/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs b/crates/ruff/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs index 082ff1ae6c..91afdcfe10 100644 --- a/crates/ruff/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs +++ b/crates/ruff/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Operator, Ranged}; use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/rules/explicit.rs b/crates/ruff/src/rules/flake8_implicit_str_concat/rules/explicit.rs index 0d93bae425..64e140b8c5 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/rules/explicit.rs +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/rules/explicit.rs @@ -1,8 +1,8 @@ -use rustpython_parser::ast::{self, Constant, Expr, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; /// ## What it does /// Checks for string literals that are explicitly concatenated (using the diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/rules/implicit.rs b/crates/ruff/src/rules/flake8_implicit_str_concat/rules/implicit.rs index 3d10ae85b0..072eb7a7dd 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/rules/implicit.rs +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/rules/implicit.rs @@ -4,8 +4,8 @@ use rustpython_parser::lexer::LexResult; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::str::{leading_quote, trailing_quote}; +use ruff_source_file::Locator; use crate::rules::flake8_implicit_str_concat::settings::Settings; diff --git a/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_alias.rs b/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_alias.rs index c22b9db2ec..6a1cae7ea4 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_alias.rs +++ b/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_alias.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashMap; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_from.rs b/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_from.rs index f410f3b029..7e858443eb 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_from.rs +++ b/crates/ruff/src/rules/flake8_import_conventions/rules/banned_import_from.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff/src/rules/flake8_logging_format/rules/logging_call.rs index 5b75402168..5cbf54644a 100644 --- a/crates/ruff/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff/src/rules/flake8_logging_format/rules/logging_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_python_ast::helpers::{find_keyword, CallArguments}; diff --git a/crates/ruff/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs b/crates/ruff/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs index 2c2e6745ba..fabfe5bf9a 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::{AlwaysAutofixableViolation, Fix}; diff --git a/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 05893da8e5..597877cadc 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -5,7 +5,7 @@ use itertools::Either::{Left, Right}; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, BoolOp, Expr, ExprContext, Identifier, Ranged}; +use rustpython_ast::{self as ast, BoolOp, Expr, ExprContext, Identifier, Ranged}; use ruff_diagnostics::AlwaysAutofixableViolation; use ruff_diagnostics::{Diagnostic, Edit, Fix}; diff --git a/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs b/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs index 34bba46d1f..6257f98772 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs @@ -1,9 +1,10 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::AlwaysAutofixableViolation; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::{is_docstring_stmt, trailing_comment_start_offset}; +use ruff_python_ast::helpers::is_docstring_stmt; +use ruff_python_ast::whitespace::trailing_comment_start_offset; use crate::autofix; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_pie/rules/non_unique_enums.rs b/crates/ruff/src/rules/flake8_pie/rules/non_unique_enums.rs index 6dbe88153a..7fa7a13038 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/non_unique_enums.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/non_unique_enums.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs b/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs index e2b68792eb..f68840791f 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, ExprLambda, Ranged}; +use rustpython_ast::{self as ast, Expr, ExprLambda, Ranged}; use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; diff --git a/crates/ruff/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs b/crates/ruff/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs index 5fedf58108..667dd7034a 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_pie/rules/unnecessary_spread.rs b/crates/ruff/src/rules/flake8_pie/rules/unnecessary_spread.rs index 278d23d07c..3b3d12a34d 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/unnecessary_spread.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/unnecessary_spread.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/flake8_print/rules/print_call.rs b/crates/ruff/src/rules/flake8_print/rules/print_call.rs index 146bfdc534..ee3dd247fc 100644 --- a/crates/ruff/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff/src/rules/flake8_print/rules/print_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/helpers.rs b/crates/ruff/src/rules/flake8_pyi/helpers.rs index 0f37e94470..2db721cd45 100644 --- a/crates/ruff/src/rules/flake8_pyi/helpers.rs +++ b/crates/ruff/src/rules/flake8_pyi/helpers.rs @@ -1,5 +1,5 @@ use ruff_python_semantic::SemanticModel; -use rustpython_parser::ast::{self, Expr, Operator}; +use rustpython_ast::{self as ast, Expr, Operator}; /// Traverse a "union" type annotation, applying `func` to each union member. /// Supports traversal of `Union` and `|` union expressions. diff --git a/crates/ruff/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs b/crates/ruff/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs index 43a47e5c24..c7d1c910c0 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arguments, Ranged}; +use rustpython_ast::{Arguments, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs b/crates/ruff/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs index 332ddfc5f7..f635b84989 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, CmpOp, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/collections_named_tuple.rs b/crates/ruff/src/rules/flake8_pyi/rules/collections_named_tuple.rs index d9d32e81f2..02dfc81853 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/collections_named_tuple.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/collections_named_tuple.rs @@ -1,8 +1,8 @@ -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs index 6b12b60411..38b29c3497 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, StmtAssign}; +use rustpython_ast::{Expr, StmtAssign}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs index 2c7b1a5cfb..858bd6b477 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/docstring_in_stubs.rs b/crates/ruff/src/rules/flake8_pyi/rules/docstring_in_stubs.rs index 924baa9c2b..bcc811bae7 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/docstring_in_stubs.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/docstring_in_stubs.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs index d47ff65aa7..a058c16dd3 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use std::collections::HashSet; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs b/crates/ruff/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs index cb21f08f4b..7876d8a182 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, ExprConstant, Ranged, Stmt, StmtExpr}; +use rustpython_ast::{Expr, ExprConstant, Ranged, Stmt, StmtExpr}; use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs b/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs index 6093da5b7a..f1cd93f4b1 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs @@ -1,6 +1,6 @@ use std::fmt::{Display, Formatter}; -use rustpython_parser::ast::{ +use rustpython_ast::{ ArgWithDefault, Arguments, Expr, ExprBinOp, ExprSubscript, ExprTuple, Identifier, Operator, Ranged, }; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs index 2968980034..5378a8d59d 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::StmtImportFrom; +use rustpython_ast::StmtImportFrom; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs b/crates/ruff/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs index e4971016b1..9da3e110c6 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs @@ -1,10 +1,10 @@ +use rustpython_ast::{Ranged, Stmt}; use rustpython_parser::ast; -use rustpython_parser::ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{Definition, Member, MemberKind}; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs b/crates/ruff/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs index 669e3ba046..2bd4c95377 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs @@ -1,10 +1,10 @@ use std::fmt; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use rustpython_parser::ast::Arguments; +use rustpython_ast::Arguments; use crate::checkers::ast::Checker; use crate::settings::types::PythonVersion::Py311; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs b/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs index 0b4642b28c..d668953d50 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff/src/rules/flake8_pyi/rules/non_self_return_type.rs index 56f4cd9da0..f97b740c45 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Arguments, Decorator, Expr, Stmt}; +use rustpython_ast::{self as ast, Arguments, Decorator, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs b/crates/ruff/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs index 28a49c0547..d4443ece65 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextSize; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/pass_in_class_body.rs b/crates/ruff/src/rules/flake8_pyi/rules/pass_in_class_body.rs index 6e05b0318e..28d66b3149 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/pass_in_class_body.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/pass_in_class_body.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs b/crates/ruff/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs index 54f747985b..0ea07b3392 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/prefix_type_params.rs b/crates/ruff/src/rules/flake8_pyi/rules/prefix_type_params.rs index cbbe1256b8..27d93a3fb3 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/prefix_type_params.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/prefix_type_params.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/redundant_numeric_union.rs b/crates/ruff/src/rules/flake8_pyi/rules/redundant_numeric_union.rs index 740c9e342a..4ff354176e 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/redundant_numeric_union.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/redundant_numeric_union.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arguments, Expr, Ranged}; +use rustpython_ast::{Arguments, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs index 01021b2051..7df270efbf 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -1,12 +1,12 @@ -use rustpython_parser::ast::{ - self, ArgWithDefault, Arguments, Constant, Expr, Operator, Ranged, Stmt, UnaryOp, +use rustpython_ast::{ + self as ast, ArgWithDefault, Arguments, Constant, Expr, Operator, Ranged, Stmt, UnaryOp, }; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::CallPath; -use ruff_python_ast::source_code::Locator; use ruff_python_semantic::{ScopeKind, SemanticModel}; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::importer::ImportRequest; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs index e9a1d6384b..790186642c 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs @@ -1,5 +1,5 @@ +use rustpython_ast::Stmt; use rustpython_parser::ast; -use rustpython_parser::ast::Stmt; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index ff5ab572e8..6872699ad3 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs b/crates/ruff/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs index 62872ecc9a..b8c840ec80 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/type_alias_naming.rs b/crates/ruff/src/rules/flake8_pyi/rules/type_alias_naming.rs index 3bd57edfc4..803f6a15c5 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/type_alias_naming.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/type_alias_naming.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/type_comment_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/type_comment_in_stub.rs index d7f8fda8ce..c52d353180 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/type_comment_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/type_comment_in_stub.rs @@ -1,6 +1,7 @@ use once_cell::sync::Lazy; use regex::Regex; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs b/crates/ruff/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs index 7082765444..144c64da88 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_platform.rs b/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_platform.rs index 418c0c55bf..f8b671c0d0 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_platform.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_platform.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_version_info.rs b/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_version_info.rs index dfb288154c..5af1a76fe9 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_version_info.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/unrecognized_version_info.rs @@ -1,6 +1,6 @@ use num_bigint::BigInt; use num_traits::{One, Zero}; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs b/crates/ruff/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs index f4ee1cf30c..ff35c48653 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs index 6c9c74864f..ad5c083efd 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -7,14 +7,15 @@ use libcst_native::{ ParenthesizedNode, SimpleStatementLine, SimpleWhitespace, SmallStatement, Statement, TrailingWhitespace, UnaryOperation, }; -use rustpython_parser::ast::{self, BoolOp, ExceptHandler, Expr, Keyword, Ranged, Stmt, UnaryOp}; +use rustpython_ast::{self as ast, BoolOp, ExceptHandler, Expr, Keyword, Ranged, Stmt, UnaryOp}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::Truthiness; -use ruff_python_ast::source_code::{Locator, Stylist}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{visitor, whitespace}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/fail.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/fail.rs index c6fddc84ad..dfd7bbb506 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/fail.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/fail.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs index 819b2f42e2..dd78de2573 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs @@ -1,8 +1,8 @@ use std::fmt; use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::Decorator; -use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Expr, Ranged, Stmt}; +use rustpython_ast::Decorator; +use rustpython_ast::{self as ast, ArgWithDefault, Arguments, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/helpers.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/helpers.rs index eac402d889..9353edf3aa 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Decorator, Expr, Keyword}; +use rustpython_ast::{self as ast, Constant, Decorator, Expr, Keyword}; use ruff_python_ast::call_path::{collect_call_path, CallPath}; use ruff_python_ast::helpers::map_callable; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs index e710b9a15c..5c863a2310 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/imports.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs index f13040575f..7d09e3782f 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Decorator, Expr, Ranged}; +use rustpython_ast::{self as ast, Decorator, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs index 69d6b85c5e..1ea6663ffd 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -1,10 +1,11 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Decorator, Expr, ExprContext, Ranged}; +use rustpython_ast::{self as ast, Constant, Decorator, Expr, ExprContext, Ranged}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Generator, Locator}; +use ruff_python_codegen::Generator; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::{AsRule, Rule}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/patch.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/patch.rs index 465ab7a161..87d1b54e05 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/patch.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/patch.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Arguments, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Arguments, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs index 8b476d4764..fcc98c49eb 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs @@ -1,5 +1,5 @@ use ruff_python_ast::helpers::{find_keyword, is_compound_statement}; -use rustpython_parser::ast::{self, Expr, Keyword, Ranged, Stmt, WithItem}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged, Stmt, WithItem}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/unittest_assert.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/unittest_assert.rs index 106bf9ec51..f4e8dbdc61 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/unittest_assert.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/unittest_assert.rs @@ -3,8 +3,8 @@ use std::hash::BuildHasherDefault; use anyhow::{anyhow, bail, Result}; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{ - self, CmpOp, Constant, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp, +use rustpython_ast::{ + self as ast, CmpOp, Constant, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp, }; /// An enum to represent the different types of assertions present in the diff --git a/crates/ruff/src/rules/flake8_quotes/rules/from_tokens.rs b/crates/ruff/src/rules/flake8_quotes/rules/from_tokens.rs index fa77834113..f02017ed31 100644 --- a/crates/ruff/src/rules/flake8_quotes/rules/from_tokens.rs +++ b/crates/ruff/src/rules/flake8_quotes/rules/from_tokens.rs @@ -4,7 +4,7 @@ use rustpython_parser::Tok; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::lex::docstring_detection::StateMachine; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs b/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs index 14967c342b..58559ae347 100644 --- a/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs +++ b/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs @@ -1,9 +1,10 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use ruff_text_size::{TextRange, TextSize}; +use rustpython_ast::{self as ast, Expr, Ranged}; +use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; - -use ruff_python_ast::helpers::match_parens; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::AsRule; @@ -75,3 +76,36 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: } } } + +/// Return the range of the first parenthesis pair after a given [`TextSize`]. +fn match_parens(start: TextSize, locator: &Locator) -> Option { + let contents = &locator.contents()[usize::from(start)..]; + + let mut fix_start = None; + let mut fix_end = None; + let mut count = 0u32; + + for (tok, range) in lexer::lex_starts_at(contents, Mode::Module, start).flatten() { + match tok { + Tok::Lpar => { + if count == 0 { + fix_start = Some(range.start()); + } + count = count.saturating_add(1); + } + Tok::Rpar => { + count = count.saturating_sub(1); + if count == 0 { + fix_end = Some(range.end()); + break; + } + } + _ => {} + } + } + + match (fix_start, fix_end) { + (Some(start), Some(end)) => Some(TextRange::new(start, end)), + _ => None, + } +} diff --git a/crates/ruff/src/rules/flake8_return/helpers.rs b/crates/ruff/src/rules/flake8_return/helpers.rs index ff61c0a10e..00ad3d8594 100644 --- a/crates/ruff/src/rules/flake8_return/helpers.rs +++ b/crates/ruff/src/rules/flake8_return/helpers.rs @@ -1,9 +1,8 @@ use ruff_text_size::TextSize; +use rustpython_ast::{Expr, Ranged, Stmt}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Ranged, Stmt}; -use ruff_python_ast::source_code::Locator; -use ruff_python_trivia::UniversalNewlines; +use ruff_source_file::{Locator, UniversalNewlines}; /// Return `true` if a function's return statement include at least one /// non-`None` value. diff --git a/crates/ruff/src/rules/flake8_return/rules/function.rs b/crates/ruff/src/rules/flake8_return/rules/function.rs index 47a27159e8..bfc01fbcd6 100644 --- a/crates/ruff/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff/src/rules/flake8_return/rules/function.rs @@ -1,7 +1,7 @@ use std::ops::Add; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, ElifElseClause, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, ElifElseClause, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; @@ -591,7 +591,8 @@ fn superfluous_else_node( if child.is_return_stmt() { let diagnostic = Diagnostic::new( SuperfluousElseReturn { branch }, - elif_else_range(elif_else, checker.locator()).unwrap_or_else(|| elif_else.range()), + elif_else_range(elif_else, checker.locator().contents()) + .unwrap_or_else(|| elif_else.range()), ); if checker.enabled(diagnostic.kind.rule()) { checker.diagnostics.push(diagnostic); @@ -600,7 +601,8 @@ fn superfluous_else_node( } else if child.is_break_stmt() { let diagnostic = Diagnostic::new( SuperfluousElseBreak { branch }, - elif_else_range(elif_else, checker.locator()).unwrap_or_else(|| elif_else.range()), + elif_else_range(elif_else, checker.locator().contents()) + .unwrap_or_else(|| elif_else.range()), ); if checker.enabled(diagnostic.kind.rule()) { checker.diagnostics.push(diagnostic); @@ -609,7 +611,8 @@ fn superfluous_else_node( } else if child.is_raise_stmt() { let diagnostic = Diagnostic::new( SuperfluousElseRaise { branch }, - elif_else_range(elif_else, checker.locator()).unwrap_or_else(|| elif_else.range()), + elif_else_range(elif_else, checker.locator().contents()) + .unwrap_or_else(|| elif_else.range()), ); if checker.enabled(diagnostic.kind.rule()) { checker.diagnostics.push(diagnostic); @@ -618,7 +621,8 @@ fn superfluous_else_node( } else if child.is_continue_stmt() { let diagnostic = Diagnostic::new( SuperfluousElseContinue { branch }, - elif_else_range(elif_else, checker.locator()).unwrap_or_else(|| elif_else.range()), + elif_else_range(elif_else, checker.locator().contents()) + .unwrap_or_else(|| elif_else.range()), ); if checker.enabled(diagnostic.kind.rule()) { checker.diagnostics.push(diagnostic); diff --git a/crates/ruff/src/rules/flake8_return/visitor.rs b/crates/ruff/src/rules/flake8_return/visitor.rs index 9d157f0e6e..52af68bf8b 100644 --- a/crates/ruff/src/rules/flake8_return/visitor.rs +++ b/crates/ruff/src/rules/flake8_return/visitor.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, ElifElseClause, Expr, Identifier, Stmt}; +use rustpython_ast::{self as ast, ElifElseClause, Expr, Identifier, Stmt}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; diff --git a/crates/ruff/src/rules/flake8_self/rules/private_member_access.rs b/crates/ruff/src/rules/flake8_self/rules/private_member_access.rs index c20d3f77dd..d484cdcd08 100644 --- a/crates/ruff/src/rules/flake8_self/rules/private_member_access.rs +++ b/crates/ruff/src/rules/flake8_self/rules/private_member_access.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs index b19c9f1669..2e0a503070 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -5,12 +5,12 @@ use itertools::Either::{Left, Right}; use itertools::Itertools; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, BoolOp, CmpOp, Expr, ExprContext, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, BoolOp, CmpOp, Expr, ExprContext, Ranged, UnaryOp}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; -use ruff_python_ast::helpers::{contains_effect, has_comments, Truthiness}; +use ruff_python_ast::helpers::{contains_effect, Truthiness}; use crate::checkers::ast::Checker; use crate::registry::AsRule; @@ -505,7 +505,7 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { } // Avoid removing comments. - if has_comments(expr, checker.locator(), checker.indexer()) { + if checker.indexer().has_comments(expr, checker.locator()) { continue; } diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs index a10feab33f..f6cc6e58f1 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs index 518f0139bd..d896c07a7e 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs @@ -1,18 +1,19 @@ use log::error; use ruff_text_size::TextRange; use rustc_hash::FxHashSet; -use rustpython_parser::ast::{ - self, CmpOp, Constant, ElifElseClause, Expr, ExprContext, Identifier, Ranged, Stmt, StmtIf, +use rustpython_ast::{ + self as ast, CmpOp, Constant, ElifElseClause, Expr, ExprContext, Identifier, Ranged, Stmt, + StmtIf, }; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::{ComparableConstant, ComparableExpr, ComparableStmt}; -use ruff_python_ast::helpers::{any_over_expr, contains_effect, first_colon_range, has_comments}; -use ruff_python_ast::source_code::Locator; +use ruff_python_ast::helpers::{any_over_expr, contains_effect}; use ruff_python_ast::stmt_if::{if_elif_branches, IfElifBranch}; +use ruff_python_parser::first_colon_range; use ruff_python_semantic::SemanticModel; -use ruff_python_trivia::UniversalNewlines; +use ruff_source_file::{Locator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::line_width::LineWidth; @@ -372,7 +373,7 @@ pub(crate) fn nested_if_statements(checker: &mut Checker, stmt_if: &StmtIf, pare let colon = first_colon_range( TextRange::new(test.end(), first_stmt.start()), - checker.locator(), + checker.locator().contents(), ); // Check if the parent is already emitting a larger diagnostic including this if statement @@ -514,7 +515,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) { if checker.patch(diagnostic.kind.rule()) { if matches!(if_return, Bool::True) && matches!(else_return, Bool::False) - && !has_comments(&range, checker.locator(), checker.indexer()) + && !checker.indexer().has_comments(&range, checker.locator()) && (if_test.is_compare_expr() || checker.semantic().is_builtin("bool")) { if if_test.is_compare_expr() { @@ -672,7 +673,7 @@ pub(crate) fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt) { stmt.range(), ); if checker.patch(diagnostic.kind.rule()) { - if !has_comments(stmt, checker.locator(), checker.indexer()) { + if !checker.indexer().has_comments(stmt, checker.locator()) { diagnostic.set_fix(Fix::suggested(Edit::range_replacement( contents, stmt.range(), @@ -978,7 +979,7 @@ pub(crate) fn use_dict_get_with_default(checker: &mut Checker, stmt_if: &StmtIf) stmt_if.range(), ); if checker.patch(diagnostic.kind.rule()) { - if !has_comments(stmt_if, checker.locator(), checker.indexer()) { + if !checker.indexer().has_comments(stmt_if, checker.locator()) { diagnostic.set_fix(Fix::suggested(Edit::range_replacement( contents, stmt_if.range(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs index f08a0e2306..493ab8bc56 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, ExprContext, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, Expr, ExprContext, Ranged, UnaryOp}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs index 887a0aca74..680cda5b18 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, CmpOp, Expr, ExprContext, Ranged, Stmt, UnaryOp}; +use rustpython_ast::{self as ast, CmpOp, Expr, ExprContext, Ranged, Stmt, UnaryOp}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs index a874bbdbaa..04a842f120 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs @@ -1,12 +1,12 @@ use log::error; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Ranged, Stmt, WithItem}; +use rustpython_ast::{self as ast, Ranged, Stmt, WithItem}; use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::first_colon_range; -use ruff_python_trivia::UniversalNewlines; +use ruff_python_parser::first_colon_range; +use ruff_source_file::UniversalNewlines; use crate::checkers::ast::Checker; use crate::line_width::LineWidth; @@ -118,7 +118,7 @@ pub(crate) fn multiple_with_statements( .map_or(last_item.context_expr.end(), |v| v.end()), body.first().expect("Expected body to be non-empty").start(), ), - checker.locator(), + checker.locator().contents(), ); let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff/src/rules/flake8_simplify/rules/fix_if.rs b/crates/ruff/src/rules/flake8_simplify/rules/fix_if.rs index ad575808f4..f2f69690bb 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/fix_if.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/fix_if.rs @@ -8,8 +8,9 @@ use libcst_native::{ use ruff_text_size::TextRange; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::{Locator, Stylist}; use ruff_python_ast::whitespace; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::cst::matchers::{match_function_def, match_if, match_indented_block, match_statement}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/fix_with.rs b/crates/ruff/src/rules/flake8_simplify/rules/fix_with.rs index 649496bb8b..c8e63210aa 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/fix_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/fix_with.rs @@ -1,11 +1,12 @@ use anyhow::{bail, Result}; use libcst_native::{CompoundStatement, Statement, Suite, With}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use crate::autofix::codemods::CodegenStylist; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::{Locator, Stylist}; use ruff_python_ast::whitespace; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::cst::matchers::{match_function_def, match_indented_block, match_statement, match_with}; @@ -13,7 +14,7 @@ use crate::cst::matchers::{match_function_def, match_indented_block, match_state pub(crate) fn fix_multiple_with_statements( locator: &Locator, stylist: &Stylist, - stmt: &rustpython_parser::ast::Stmt, + stmt: &rustpython_ast::Stmt, ) -> Result { // Infer the indentation of the outer block. let Some(outer_indent) = whitespace::indentation(locator, stmt) else { diff --git a/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs index 32e044feb1..5f2bec88a4 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -1,11 +1,12 @@ use anyhow::Result; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, CmpOp, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Expr, Ranged}; use ruff_diagnostics::Edit; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs b/crates/ruff/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs index 41da294234..7feb860dc1 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 3288d9f46b..fbb9e25ee0 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -1,13 +1,13 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{ - self, CmpOp, Comprehension, Constant, Expr, ExprContext, Ranged, Stmt, UnaryOp, +use rustpython_ast::{ + self as ast, CmpOp, Comprehension, Constant, Expr, ExprContext, Ranged, Stmt, UnaryOp, }; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::any_over_expr; -use ruff_python_ast::source_code::Generator; use ruff_python_ast::traversal; +use ruff_python_codegen::Generator; use crate::checkers::ast::Checker; use crate::line_width::LineWidth; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs b/crates/ruff/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs index ce6872778f..d8a07783ab 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs index 3858d0a591..b3bf99abfa 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -1,11 +1,10 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{self, Constant, ExceptHandler, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, ExceptHandler, Expr, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::compose_call_path; use ruff_python_ast::helpers; -use ruff_python_ast::helpers::has_comments; use crate::checkers::ast::Checker; use crate::importer::ImportRequest; @@ -134,7 +133,7 @@ pub(crate) fn suppressible_exception( stmt.range(), ); if checker.patch(diagnostic.kind.rule()) { - if !has_comments(stmt, checker.locator(), checker.indexer()) { + if !checker.indexer().has_comments(stmt, checker.locator()) { diagnostic.try_set_fix(|| { let (import_edit, binding) = checker.importer().get_or_import_symbol( &ImportRequest::import("contextlib", "suppress"), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs index 21fe4a10f4..472a17303b 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -1,12 +1,13 @@ use anyhow::Result; use libcst_native::CompOp; -use rustpython_parser::ast::{self, CmpOp, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, CmpOp, Expr, Ranged, UnaryOp}; use crate::autofix::codemods::CodegenStylist; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; use ruff_python_stdlib::str::{self}; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::cst::matchers::{match_comparison, match_expression}; diff --git a/crates/ruff/src/rules/flake8_slots/rules/helpers.rs b/crates/ruff/src/rules/flake8_slots/rules/helpers.rs index 7d0035d15f..99200ca510 100644 --- a/crates/ruff/src/rules/flake8_slots/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_slots/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Stmt}; +use rustpython_ast::{self as ast, Expr, Stmt}; /// Return `true` if the given body contains a `__slots__` assignment. pub(super) fn has_slots(body: &[Stmt]) -> bool { diff --git a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs index de20c1e926..626ade812d 100644 --- a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs +++ b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs @@ -1,10 +1,10 @@ +use rustpython_ast::{Expr, StmtClassDef}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::identifier::Identifier; -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use crate::checkers::ast::Checker; use crate::rules::flake8_slots::rules::helpers::has_slots; diff --git a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs index 8a486b70e5..d336c7562f 100644 --- a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs +++ b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Stmt, StmtClassDef}; +use rustpython_ast::{Expr, Stmt, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs index 98ce10bb56..9e0fdeea90 100644 --- a/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs +++ b/crates/ruff/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Stmt, StmtClassDef}; +use rustpython_ast::{Stmt, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_tidy_imports/rules/banned_api.rs b/crates/ruff/src/rules/flake8_tidy_imports/rules/banned_api.rs index 6730ce8700..249f8b62c9 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/rules/banned_api.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/rules/banned_api.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_tidy_imports/rules/relative_imports.rs b/crates/ruff/src/rules/flake8_tidy_imports/rules/relative_imports.rs index 5012d69950..347bd38117 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/rules/relative_imports.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/rules/relative_imports.rs @@ -1,10 +1,10 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Identifier, Int, Ranged, Stmt}; +use rustpython_ast::{self as ast, Identifier, Int, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::resolve_imported_module_path; -use ruff_python_ast::source_code::Generator; +use ruff_python_codegen::Generator; use ruff_python_stdlib::identifiers::is_identifier; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_todos/rules/todos.rs b/crates/ruff/src/rules/flake8_todos/rules/todos.rs index 7bd52d9ba1..23021d9caa 100644 --- a/crates/ruff/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff/src/rules/flake8_todos/rules/todos.rs @@ -1,6 +1,7 @@ use once_cell::sync::Lazy; use regex::RegexSet; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; diff --git a/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs b/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs index 0e1241b2d1..0cf98a50e9 100644 --- a/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs +++ b/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs @@ -1,5 +1,5 @@ +use rustpython_ast::Ranged; use rustpython_parser::ast; -use rustpython_parser::ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_unused_arguments/helpers.rs b/crates/ruff/src/rules/flake8_unused_arguments/helpers.rs index 0669964015..3fa7c841b0 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/helpers.rs +++ b/crates/ruff/src/rules/flake8_unused_arguments/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Stmt}; use ruff_python_ast::helpers::is_docstring_stmt; diff --git a/crates/ruff/src/rules/flake8_unused_arguments/rules/unused_arguments.rs b/crates/ruff/src/rules/flake8_unused_arguments/rules/unused_arguments.rs index 7df519c887..0a581b90d8 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/rules/unused_arguments.rs +++ b/crates/ruff/src/rules/flake8_unused_arguments/rules/unused_arguments.rs @@ -1,8 +1,8 @@ use std::iter; use regex::Regex; +use rustpython_ast::{Arg, Arguments}; use rustpython_parser::ast; -use rustpython_parser::ast::{Arg, Arguments}; use ruff_diagnostics::DiagnosticKind; use ruff_diagnostics::{Diagnostic, Violation}; diff --git a/crates/ruff/src/rules/flake8_use_pathlib/rules/os_sep_split.rs b/crates/ruff/src/rules/flake8_use_pathlib/rules/os_sep_split.rs index dfff78b9ee..ffd61fe932 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/rules/os_sep_split.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/rules/os_sep_split.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::find_keyword; -use rustpython_parser::ast::{Expr, ExprAttribute, Keyword, Ranged}; +use rustpython_ast::{Expr, ExprAttribute, Keyword, Ranged}; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index 0dee506ef3..952d6e101e 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Constant, Expr, ExprCall, ExprConstant}; +use rustpython_ast::{Constant, Expr, ExprCall, ExprConstant}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index c884d3a3e6..056971398a 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/flynt/helpers.rs b/crates/ruff/src/rules/flynt/helpers.rs index f331471499..850180d2c3 100644 --- a/crates/ruff/src/rules/flynt/helpers.rs +++ b/crates/ruff/src/rules/flynt/helpers.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, ConversionFlag, Expr}; +use rustpython_ast::{self as ast, Constant, ConversionFlag, Expr}; /// Wrap an expression in a `FormattedValue` with no special formatting. fn to_formatted_value_expr(inner: &Expr) -> Expr { diff --git a/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs index cd2750006b..18cf54c152 100644 --- a/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/isort/annotate.rs b/crates/ruff/src/rules/isort/annotate.rs index 71168e5121..4cad6f7888 100644 --- a/crates/ruff/src/rules/isort/annotate.rs +++ b/crates/ruff/src/rules/isort/annotate.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use super::comments::Comment; use super::helpers::trailing_comma; diff --git a/crates/ruff/src/rules/isort/block.rs b/crates/ruff/src/rules/isort/block.rs index 647b39501f..17b5049e46 100644 --- a/crates/ruff/src/rules/isort/block.rs +++ b/crates/ruff/src/rules/isort/block.rs @@ -1,10 +1,10 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, ElifElseClause, ExceptHandler, MatchCase, Ranged, Stmt}; +use rustpython_ast::{self as ast, ElifElseClause, ExceptHandler, MatchCase, Ranged, Stmt}; use std::iter::Peekable; use std::slice; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::statement_visitor::StatementVisitor; +use ruff_source_file::Locator; use crate::directives::IsortDirectives; use crate::jupyter::Notebook; diff --git a/crates/ruff/src/rules/isort/comments.rs b/crates/ruff/src/rules/isort/comments.rs index ee1c4d9f7f..32138ca384 100644 --- a/crates/ruff/src/rules/isort/comments.rs +++ b/crates/ruff/src/rules/isort/comments.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use ruff_text_size::{TextRange, TextSize}; use rustpython_parser::{lexer, Mode, Tok}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; #[derive(Debug)] pub(crate) struct Comment<'a> { diff --git a/crates/ruff/src/rules/isort/format.rs b/crates/ruff/src/rules/isort/format.rs index ece938b2ac..cfabdb5364 100644 --- a/crates/ruff/src/rules/isort/format.rs +++ b/crates/ruff/src/rules/isort/format.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::source_code::Stylist; +use ruff_python_codegen::Stylist; use crate::line_width::{LineLength, LineWidth}; diff --git a/crates/ruff/src/rules/isort/helpers.rs b/crates/ruff/src/rules/isort/helpers.rs index d98a157e45..54ceb3a8ff 100644 --- a/crates/ruff/src/rules/isort/helpers.rs +++ b/crates/ruff/src/rules/isort/helpers.rs @@ -1,8 +1,8 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use rustpython_parser::{lexer, Mode, Tok}; -use ruff_python_ast::source_code::Locator; -use ruff_python_trivia::{PythonWhitespace, UniversalNewlines}; +use ruff_python_trivia::PythonWhitespace; +use ruff_source_file::{Locator, UniversalNewlines}; use crate::rules::isort::types::TrailingComma; diff --git a/crates/ruff/src/rules/isort/mod.rs b/crates/ruff/src/rules/isort/mod.rs index 565f031775..55412202d8 100644 --- a/crates/ruff/src/rules/isort/mod.rs +++ b/crates/ruff/src/rules/isort/mod.rs @@ -11,7 +11,8 @@ pub use categorize::{ImportSection, ImportType}; use comments::Comment; use normalize::normalize_imports; use order::order_imports; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use settings::RelativeImportsOrder; use sorting::cmp_either_import; use types::EitherImport::{Import, ImportFrom}; diff --git a/crates/ruff/src/rules/isort/rules/add_required_imports.rs b/crates/ruff/src/rules/isort/rules/add_required_imports.rs index 9abcb3971c..938efe96c6 100644 --- a/crates/ruff/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff/src/rules/isort/rules/add_required_imports.rs @@ -1,13 +1,14 @@ use log::error; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, Stmt, Suite}; +use rustpython_ast::{self as ast, Stmt, Suite}; use rustpython_parser::Parse; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::imports::{Alias, AnyImport, FutureImport, Import, ImportFrom}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::importer::Importer; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/isort/rules/organize_imports.rs b/crates/ruff/src/rules/isort/rules/organize_imports.rs index 21dfead825..fa19caa195 100644 --- a/crates/ruff/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff/src/rules/isort/rules/organize_imports.rs @@ -2,16 +2,15 @@ use std::path::Path; use itertools::{EitherOrBoth, Itertools}; use ruff_text_size::TextRange; -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::{ - followed_by_multi_statement_line, preceded_by_multi_statement_line, trailing_lines_end, -}; -use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; -use ruff_python_trivia::{leading_indentation, PythonWhitespace, UniversalNewlines}; -use ruff_textwrap::indent; +use ruff_python_ast::whitespace::{followed_by_multi_statement_line, trailing_lines_end}; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; +use ruff_python_trivia::{leading_indentation, textwrap::indent, PythonWhitespace}; +use ruff_source_file::{Locator, UniversalNewlines}; use crate::line_width::LineWidth; use crate::registry::AsRule; @@ -96,7 +95,7 @@ pub(crate) fn organize_imports( // Special-cases: there's leading or trailing content in the import block. These // are too hard to get right, and relatively rare, so flag but don't fix. - if preceded_by_multi_statement_line(block.imports.first().unwrap(), locator, indexer) + if indexer.preceded_by_multi_statement_line(block.imports.first().unwrap(), locator) || followed_by_multi_statement_line(block.imports.last().unwrap(), locator) { return Some(Diagnostic::new(UnsortedImports, range)); diff --git a/crates/ruff/src/rules/mccabe/rules/function_is_too_complex.rs b/crates/ruff/src/rules/mccabe/rules/function_is_too_complex.rs index e5242e69e6..f52765b31b 100644 --- a/crates/ruff/src/rules/mccabe/rules/function_is_too_complex.rs +++ b/crates/ruff/src/rules/mccabe/rules/function_is_too_complex.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -169,7 +169,7 @@ pub(crate) fn function_is_too_complex( #[cfg(test)] mod tests { use anyhow::Result; - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::Parse; use super::get_complexity_number; diff --git a/crates/ruff/src/rules/numpy/rules/deprecated_function.rs b/crates/ruff/src/rules/numpy/rules/deprecated_function.rs index 3fb2774cfb..3da00a8135 100644 --- a/crates/ruff/src/rules/numpy/rules/deprecated_function.rs +++ b/crates/ruff/src/rules/numpy/rules/deprecated_function.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs b/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs index 853cf8039d..de20927883 100644 --- a/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/numpy/rules/legacy_random.rs b/crates/ruff/src/rules/numpy/rules/legacy_random.rs index cdcd68f149..c1c3f9bfac 100644 --- a/crates/ruff/src/rules/numpy/rules/legacy_random.rs +++ b/crates/ruff/src/rules/numpy/rules/legacy_random.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pandas_vet/helpers.rs b/crates/ruff/src/rules/pandas_vet/helpers.rs index b849af1f80..a9f43d4871 100644 --- a/crates/ruff/src/rules/pandas_vet/helpers.rs +++ b/crates/ruff/src/rules/pandas_vet/helpers.rs @@ -1,5 +1,5 @@ +use rustpython_ast::Expr; use rustpython_parser::ast; -use rustpython_parser::ast::Expr; use ruff_python_semantic::{BindingKind, Import, SemanticModel}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/assignment_to_df.rs b/crates/ruff/src/rules/pandas_vet/rules/assignment_to_df.rs index bcc923718f..970d523b4d 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/assignment_to_df.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/assignment_to_df.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/attr.rs b/crates/ruff/src/rules/pandas_vet/rules/attr.rs index cb2ec2398d..59a3062623 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/attr.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/attr.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/call.rs b/crates/ruff/src/rules/pandas_vet/rules/call.rs index 20f1ae873d..03f35f6caa 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/call.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs index dbb62c891a..af621cd3e1 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs @@ -1,11 +1,11 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_true; -use ruff_python_ast::source_code::Locator; use ruff_python_semantic::{BindingKind, Import}; +use ruff_source_file::Locator; use crate::autofix::edits::remove_argument; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pandas_vet/rules/nunique_constant_series_check.rs b/crates/ruff/src/rules/pandas_vet/rules/nunique_constant_series_check.rs index 9edffcf25e..3d70fbc777 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/nunique_constant_series_check.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/nunique_constant_series_check.rs @@ -1,5 +1,5 @@ use num_traits::One; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; diff --git a/crates/ruff/src/rules/pandas_vet/rules/pd_merge.rs b/crates/ruff/src/rules/pandas_vet/rules/pd_merge.rs index a515cd3639..ee8b7646ae 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/pd_merge.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/pd_merge.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/read_table.rs b/crates/ruff/src/rules/pandas_vet/rules/read_table.rs index 15450ced9c..bba50dedd8 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/read_table.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/read_table.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{Constant, Expr, Keyword, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pandas_vet/rules/subscript.rs b/crates/ruff/src/rules/pandas_vet/rules/subscript.rs index 8916c7d29a..03b867ba6a 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/subscript.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/subscript.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; diff --git a/crates/ruff/src/rules/pep8_naming/helpers.rs b/crates/ruff/src/rules/pep8_naming/helpers.rs index 24017389ff..f017fc34b0 100644 --- a/crates/ruff/src/rules/pep8_naming/helpers.rs +++ b/crates/ruff/src/rules/pep8_naming/helpers.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{self, Expr, Stmt}; +use rustpython_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::str::{is_cased_lowercase, is_cased_uppercase}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs index b81b30abb2..026cbebf97 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs index b43f54b977..dedd8fffbe 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs index b5f051de6a..338048223f 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs b/crates/ruff/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs index 3ce0ab006f..b1d744d17c 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/dunder_function_name.rs b/crates/ruff/src/rules/pep8_naming/rules/dunder_function_name.rs index 2e0b708469..fa2c5ce6e0 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/dunder_function_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/dunder_function_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs b/crates/ruff/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs index 82edff98eb..9a1eda54b5 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Stmt}; +use rustpython_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_argument_name.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_argument_name.rs index be9e86723f..35f5a20aed 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_argument_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_argument_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arg, Ranged}; +use rustpython_ast::{Arg, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_class_name.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_class_name.rs index e1bd799d9f..e13da1ebaa 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_class_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_class_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_class_method.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_class_method.rs index cc17ffe817..921803062b 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_class_method.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_class_method.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ArgWithDefault, Arguments, Decorator, Ranged}; +use rustpython_ast::{ArgWithDefault, Arguments, Decorator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_method.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_method.rs index 55dd34d104..c50db8ca63 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_method.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_first_argument_name_for_method.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arguments, Decorator, Ranged}; +use rustpython_ast::{Arguments, Decorator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs index 71ca191d40..3b28d3f03c 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Decorator, Stmt}; +use rustpython_ast::{Decorator, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs b/crates/ruff/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs index 63dd420c00..8df0318458 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs b/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs index 895ff1f8e3..2310ec6137 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs b/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs index f644f52f4e..5c9b081050 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs b/crates/ruff/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs index 34003c1778..8d557f48f7 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/perflint/rules/incorrect_dict_iterator.rs b/crates/ruff/src/rules/perflint/rules/incorrect_dict_iterator.rs index 8de9bc5a73..4cfd91c2bd 100644 --- a/crates/ruff/src/rules/perflint/rules/incorrect_dict_iterator.rs +++ b/crates/ruff/src/rules/perflint/rules/incorrect_dict_iterator.rs @@ -1,8 +1,8 @@ use std::fmt; +use rustpython_ast::Expr; +use rustpython_ast::Ranged; use rustpython_parser::ast; -use rustpython_parser::ast::Expr; -use rustpython_parser::ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/perflint/rules/manual_list_comprehension.rs b/crates/ruff/src/rules/perflint/rules/manual_list_comprehension.rs index 73b6ee60be..8f02551af5 100644 --- a/crates/ruff/src/rules/perflint/rules/manual_list_comprehension.rs +++ b/crates/ruff/src/rules/perflint/rules/manual_list_comprehension.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Stmt}; +use rustpython_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/perflint/rules/manual_list_copy.rs b/crates/ruff/src/rules/perflint/rules/manual_list_copy.rs index 3752c4eb1c..6494ac50ae 100644 --- a/crates/ruff/src/rules/perflint/rules/manual_list_copy.rs +++ b/crates/ruff/src/rules/perflint/rules/manual_list_copy.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Stmt}; +use rustpython_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/perflint/rules/try_except_in_loop.rs b/crates/ruff/src/rules/perflint/rules/try_except_in_loop.rs index eeeed136ed..4248c185cd 100644 --- a/crates/ruff/src/rules/perflint/rules/try_except_in_loop.rs +++ b/crates/ruff/src/rules/perflint/rules/try_except_in_loop.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff/src/rules/perflint/rules/unnecessary_list_cast.rs index 670256d10a..f4febc792e 100644 --- a/crates/ruff/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -1,9 +1,9 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use crate::checkers::ast::Checker; use crate::registry::AsRule; diff --git a/crates/ruff/src/rules/pycodestyle/helpers.rs b/crates/ruff/src/rules/pycodestyle/helpers.rs index b8f5c81d07..4850ac16bb 100644 --- a/crates/ruff/src/rules/pycodestyle/helpers.rs +++ b/crates/ruff/src/rules/pycodestyle/helpers.rs @@ -1,9 +1,8 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{CmpOp, Expr, Ranged}; +use rustpython_ast::{CmpOp, Expr, Ranged}; use unicode_width::UnicodeWidthStr; -use ruff_python_ast::source_code::Locator; -use ruff_python_trivia::Line; +use ruff_source_file::{Line, Locator}; use crate::line_width::{LineLength, LineWidth, TabSize}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/ambiguous_class_name.rs b/crates/ruff/src/rules/pycodestyle/rules/ambiguous_class_name.rs index 8689dfc6c5..7d439ba3a9 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/ambiguous_class_name.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/ambiguous_class_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Identifier, Ranged}; +use rustpython_ast::{Identifier, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/ambiguous_function_name.rs b/crates/ruff/src/rules/pycodestyle/rules/ambiguous_function_name.rs index df432bf72e..0bdc5915ae 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/ambiguous_function_name.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/ambiguous_function_name.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Identifier, Ranged}; +use rustpython_ast::{Identifier, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/bare_except.rs b/crates/ruff/src/rules/pycodestyle/rules/bare_except.rs index beac9e84fc..affbe1e374 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/bare_except.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/bare_except.rs @@ -1,9 +1,9 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::identifier::except; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; /// ## What it does /// Checks for bare `except` catches in `try`-`except` statements. @@ -66,7 +66,10 @@ pub(crate) fn bare_except( .iter() .any(|stmt| matches!(stmt, Stmt::Raise(ast::StmtRaise { exc: None, .. }))) { - Some(Diagnostic::new(BareExcept, except(handler, locator))) + Some(Diagnostic::new( + BareExcept, + except(handler, locator.contents()), + )) } else { None } diff --git a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs index b3fd153481..e7fe84889d 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs @@ -5,8 +5,8 @@ use rustpython_parser::Tok; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use crate::registry::Rule; use crate::settings::Settings; @@ -171,7 +171,8 @@ pub(crate) fn compound_statements( Diagnostic::new(UselessSemicolon, TextRange::new(start, end)); if settings.rules.should_fix(Rule::UselessSemicolon) { diagnostic.set_fix(Fix::automatic(Edit::deletion( - helpers::preceded_by_continuations(start, locator, indexer) + indexer + .preceded_by_continuations(start, locator) .unwrap_or(start), end, ))); diff --git a/crates/ruff/src/rules/pycodestyle/rules/doc_line_too_long.rs b/crates/ruff/src/rules/pycodestyle/rules/doc_line_too_long.rs index 5fe7d8e2fc..caaaa2032c 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/doc_line_too_long.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/doc_line_too_long.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::Line; +use ruff_source_file::Line; use crate::rules::pycodestyle::helpers::is_overlong; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/pycodestyle/rules/errors.rs b/crates/ruff/src/rules/pycodestyle/rules/errors.rs index 4b81bf466c..17f1793b9a 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/errors.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/errors.rs @@ -3,7 +3,7 @@ use rustpython_parser::ParseError; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::logging::DisplayParseErrorType; diff --git a/crates/ruff/src/rules/pycodestyle/rules/imports.rs b/crates/ruff/src/rules/pycodestyle/rules/imports.rs index 4504ade301..c5b7f54952 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/imports.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/imports.rs @@ -1,8 +1,8 @@ -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs b/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs index 4e21ed18ed..fbe8e1bff3 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -3,8 +3,8 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::str::{leading_quote, trailing_quote}; +use ruff_source_file::Locator; /// ## What it does /// Checks for invalid escape sequences. diff --git a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs index 33beb8b3b1..82016dad29 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -1,14 +1,14 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{ - self, Arg, ArgWithDefault, Arguments, Constant, Expr, Identifier, Ranged, Stmt, +use rustpython_ast::{ + self as ast, Arg, ArgWithDefault, Arguments, Constant, Expr, Identifier, Ranged, Stmt, }; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::{has_leading_content, has_trailing_content}; -use ruff_python_ast::source_code::Generator; +use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; -use ruff_python_trivia::{leading_indentation, UniversalNewlines}; +use ruff_python_trivia::{has_leading_content, has_trailing_content, leading_indentation}; +use ruff_source_file::UniversalNewlines; use crate::checkers::ast::Checker; use crate::registry::AsRule; diff --git a/crates/ruff/src/rules/pycodestyle/rules/line_too_long.rs b/crates/ruff/src/rules/pycodestyle/rules/line_too_long.rs index 56cb57fab5..12fff28186 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/line_too_long.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/line_too_long.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::Line; +use ruff_source_file::Line; use crate::rules::pycodestyle::helpers::is_overlong; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs index 7bd4699cd2..cbb01c4320 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -1,6 +1,6 @@ use itertools::izip; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs index ca4b1ed3d0..0c64a4070f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs @@ -3,7 +3,7 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use ruff_text_size::TextRange; use crate::checkers::logical_lines::LogicalLinesContext; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/indentation.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/indentation.rs index 6fa4cb316c..e25c4b8786 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/indentation.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/indentation.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::DiagnosticKind; use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use super::LogicalLine; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs index 1c50f85e35..e8119544ed 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs @@ -3,7 +3,7 @@ use ruff_text_size::TextSize; use ruff_diagnostics::Edit; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs index 19ee6a1e4e..9be461e4fc 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs index 5ba42b712f..9687fa462f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{DiagnosticKind, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/mod.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/mod.rs index 7da760421b..da9bf673ad 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/mod.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/mod.rs @@ -16,9 +16,9 @@ use bitflags::bitflags; use ruff_text_size::{TextLen, TextRange, TextSize}; use rustpython_parser::lexer::LexResult; -use ruff_python_ast::source_code::Locator; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use ruff_python_trivia::is_python_whitespace; +use ruff_source_file::Locator; mod extraneous_whitespace; mod indentation; @@ -524,7 +524,7 @@ mod tests { use rustpython_parser::lexer::LexResult; use rustpython_parser::{lexer, Mode}; - use ruff_python_ast::source_code::Locator; + use ruff_source_file::Locator; use super::LogicalLines; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs index d7ea88a803..51933fe10f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs @@ -2,7 +2,7 @@ use ruff_text_size::TextRange; use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs index 3390d099e0..051f887630 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs @@ -2,7 +2,7 @@ use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; use crate::rules::pycodestyle::rules::logical_lines::{LogicalLine, LogicalLineToken}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs index c3a3f34a00..90bf9f5359 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs @@ -2,9 +2,9 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use ruff_python_trivia::PythonWhitespace; +use ruff_source_file::Locator; use crate::checkers::logical_lines::LogicalLinesContext; use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs index 3cb6c0694d..c69145712c 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs @@ -2,7 +2,7 @@ use ruff_text_size::{TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::token_kind::TokenKind; +use ruff_python_parser::token_kind::TokenKind; use crate::checkers::logical_lines::LogicalLinesContext; use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; diff --git a/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs b/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs index ea876524e4..be44b9951f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs @@ -2,7 +2,8 @@ use ruff_text_size::{TextLen, TextRange}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; /// ## What it does /// Checks for files missing a new line at the end of the file. diff --git a/crates/ruff/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs b/crates/ruff/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs index 09179082fd..5d4a5c47be 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs @@ -2,7 +2,8 @@ use ruff_text_size::{TextLen, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::{leading_indentation, Line}; +use ruff_python_trivia::leading_indentation; +use ruff_source_file::Line; /// ## What it does /// Checks for mixed tabs and spaces in indentation. diff --git a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs index 243670ced6..8ce5daf0ae 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, CmpOp, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, CmpOp, Expr, Ranged, UnaryOp}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pycodestyle/rules/tab_indentation.rs b/crates/ruff/src/rules/pycodestyle/rules/tab_indentation.rs index 3070d1599c..5a513c234a 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/tab_indentation.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/tab_indentation.rs @@ -2,8 +2,9 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Indexer; -use ruff_python_trivia::{leading_indentation, Line}; +use ruff_python_index::Indexer; +use ruff_python_trivia::leading_indentation; +use ruff_source_file::Line; /// ## What it does /// Checks for indentation that uses tabs. diff --git a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs index e121928048..bbea9d4cef 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -2,9 +2,8 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers; -use ruff_python_ast::source_code::{Indexer, Locator}; -use ruff_python_trivia::Line; +use ruff_python_index::Indexer; +use ruff_source_file::{Line, Locator}; use crate::registry::Rule; use crate::settings::Settings; @@ -96,7 +95,8 @@ pub(crate) fn trailing_whitespace( // Remove any preceding continuations, to avoid introducing a potential // syntax error. diagnostic.set_fix(Fix::automatic(Edit::range_deletion(TextRange::new( - helpers::preceded_by_continuations(line.start(), locator, indexer) + indexer + .preceded_by_continuations(line.start(), locator) .unwrap_or(range.start()), range.end(), )))); diff --git a/crates/ruff/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff/src/rules/pycodestyle/rules/type_comparison.rs index 4b9d7535b7..2bd337d993 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/type_comparison.rs @@ -1,5 +1,5 @@ use itertools::izip; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pydocstyle/helpers.rs b/crates/ruff/src/rules/pydocstyle/helpers.rs index 52b4af7c1f..17aab82f78 100644 --- a/crates/ruff/src/rules/pydocstyle/helpers.rs +++ b/crates/ruff/src/rules/pydocstyle/helpers.rs @@ -5,7 +5,7 @@ use ruff_python_ast::cast; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::str::is_implicit_concatenation; use ruff_python_semantic::{Definition, Member, MemberKind, SemanticModel}; -use ruff_python_trivia::UniversalNewlines; +use ruff_source_file::UniversalNewlines; /// Return the index of the first logical line in a string. pub(super) fn logical_line(content: &str) -> Option { diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs index 729748a04e..32bbb59845 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::{UniversalNewlineIterator, UniversalNewlines}; +use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs index 320e9101ba..a9bcc5051c 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -1,10 +1,11 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{Definition, Member, MemberKind}; -use ruff_python_trivia::{PythonWhitespace, UniversalNewlineIterator, UniversalNewlines}; +use ruff_python_trivia::PythonWhitespace; +use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs index 0472be1e64..a0057f0d3e 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -1,12 +1,13 @@ use once_cell::sync::Lazy; use regex::Regex; use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{Definition, Member, MemberKind}; -use ruff_python_trivia::{PythonWhitespace, UniversalNewlineIterator, UniversalNewlines}; +use ruff_python_trivia::PythonWhitespace; +use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs index b17ef0b3cf..b254c83471 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs index 821494356e..0fb03df11a 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs @@ -3,7 +3,7 @@ use strum::IntoEnumIterator; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::{UniversalNewlineIterator, UniversalNewlines}; +use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::sections::SectionKind; diff --git a/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs index 60ed7ae28c..5649479de2 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -3,7 +3,7 @@ use strum::IntoEnumIterator; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::{UniversalNewlineIterator, UniversalNewlines}; +use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::sections::SectionKind; diff --git a/crates/ruff/src/rules/pydocstyle/rules/indent.rs b/crates/ruff/src/rules/pydocstyle/rules/indent.rs index 273cbd807f..f97bdf88b0 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/indent.rs @@ -4,7 +4,7 @@ use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::docstrings::{clean_space, leading_space}; -use ruff_python_trivia::NewlineWithTrailingNewline; +use ruff_source_file::NewlineWithTrailingNewline; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs index a44cf8eb9f..dee434735a 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -1,11 +1,11 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{is_triple_quote, leading_quote}; use ruff_python_semantic::{Definition, Member}; -use ruff_python_trivia::{NewlineWithTrailingNewline, UniversalNewlineIterator}; +use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlineIterator}; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs b/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs index bb54a790b6..d03d32ea99 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs @@ -1,10 +1,10 @@ use ruff_text_size::{TextLen, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::docstrings::clean_space; -use ruff_python_trivia::{NewlineWithTrailingNewline, UniversalNewlines}; +use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlines}; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/no_signature.rs b/crates/ruff/src/rules/pydocstyle/rules/no_signature.rs index 60204fe24a..b32032abd4 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/no_signature.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/no_signature.rs @@ -1,9 +1,9 @@ -use rustpython_parser::ast::{self, Stmt}; +use rustpython_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{Definition, Member, MemberKind}; -use ruff_python_trivia::UniversalNewlines; +use ruff_source_file::UniversalNewlines; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs b/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs index 94ea3ee381..cf01e3fee8 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -2,7 +2,7 @@ use ruff_text_size::{TextLen, TextRange}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::NewlineWithTrailingNewline; +use ruff_source_file::NewlineWithTrailingNewline; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/non_imperative_mood.rs b/crates/ruff/src/rules/pydocstyle/rules/non_imperative_mood.rs index 0045f7d7f7..39d72e7dba 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/non_imperative_mood.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/non_imperative_mood.rs @@ -9,7 +9,7 @@ use ruff_python_ast::call_path::{from_qualified_name, CallPath}; use ruff_python_ast::cast; use ruff_python_semantic::analyze::visibility::{is_property, is_test}; use ruff_python_semantic::{Definition, Member, MemberKind}; -use ruff_python_trivia::UniversalNewlines; +use ruff_source_file::UniversalNewlines; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs index db807f7a1b..560f3ab0e1 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; -use ruff_python_trivia::NewlineWithTrailingNewline; +use ruff_source_file::NewlineWithTrailingNewline; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index 06d577ab94..53a759370b 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -3,7 +3,7 @@ use once_cell::sync::Lazy; use regex::Regex; use ruff_text_size::{TextLen, TextRange, TextSize}; use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, ArgWithDefault, Stmt}; +use rustpython_ast::{self as ast, ArgWithDefault, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; @@ -13,8 +13,8 @@ use ruff_python_ast::docstrings::{clean_space, leading_space}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::is_staticmethod; use ruff_python_semantic::{Definition, Member, MemberKind}; -use ruff_python_trivia::{NewlineWithTrailingNewline, PythonWhitespace}; -use ruff_textwrap::dedent; +use ruff_python_trivia::{textwrap::dedent, PythonWhitespace}; +use ruff_source_file::NewlineWithTrailingNewline; use crate::checkers::ast::Checker; use crate::docstrings::sections::{SectionContext, SectionContexts, SectionKind}; diff --git a/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs b/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs index caa7d59872..1f054c628c 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Quote; +use ruff_python_codegen::Quote; use crate::checkers::ast::Checker; use crate::docstrings::Docstring; diff --git a/crates/ruff/src/rules/pyflakes/fixes.rs b/crates/ruff/src/rules/pyflakes/fixes.rs index 2f61d467d6..624e7f8634 100644 --- a/crates/ruff/src/rules/pyflakes/fixes.rs +++ b/crates/ruff/src/rules/pyflakes/fixes.rs @@ -1,11 +1,12 @@ use anyhow::{Context, Ok, Result}; use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; use ruff_python_semantic::Binding; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::cst::matchers::{match_call_mut, match_dict, match_expression}; diff --git a/crates/ruff/src/rules/pyflakes/mod.rs b/crates/ruff/src/rules/pyflakes/mod.rs index 712085973e..44ae43add7 100644 --- a/crates/ruff/src/rules/pyflakes/mod.rs +++ b/crates/ruff/src/rules/pyflakes/mod.rs @@ -15,8 +15,10 @@ mod tests { use test_case::test_case; use ruff_diagnostics::Diagnostic; - use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; - use ruff_textwrap::dedent; + use ruff_python_codegen::Stylist; + use ruff_python_index::Indexer; + use ruff_python_trivia::textwrap::dedent; + use ruff_source_file::Locator; use crate::linter::{check_path, LinterResult}; use crate::registry::{AsRule, Linter, Rule}; @@ -502,7 +504,7 @@ mod tests { fn flakes(contents: &str, expected: &[Rule]) { let contents = dedent(contents); let settings = Settings::for_rules(Linter::Pyflakes.rules()); - let tokens: Vec = ruff_rustpython::tokenize(&contents); + let tokens: Vec = ruff_python_parser::tokenize(&contents); let locator = Locator::new(&contents); let stylist = Stylist::from_tokens(&tokens, &locator); let indexer = Indexer::from_tokens(&tokens, &locator); diff --git a/crates/ruff/src/rules/pyflakes/rules/assert_tuple.rs b/crates/ruff/src/rules/pyflakes/rules/assert_tuple.rs index 1939ba4aa4..69a09e4e75 100644 --- a/crates/ruff/src/rules/pyflakes/rules/assert_tuple.rs +++ b/crates/ruff/src/rules/pyflakes/rules/assert_tuple.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/break_outside_loop.rs b/crates/ruff/src/rules/pyflakes/rules/break_outside_loop.rs index 0605620081..05c71512ae 100644 --- a/crates/ruff/src/rules/pyflakes/rules/break_outside_loop.rs +++ b/crates/ruff/src/rules/pyflakes/rules/break_outside_loop.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/continue_outside_loop.rs b/crates/ruff/src/rules/pyflakes/rules/continue_outside_loop.rs index bfc551bf99..38a335c27f 100644 --- a/crates/ruff/src/rules/pyflakes/rules/continue_outside_loop.rs +++ b/crates/ruff/src/rules/pyflakes/rules/continue_outside_loop.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/default_except_not_last.rs b/crates/ruff/src/rules/pyflakes/rules/default_except_not_last.rs index 49fc869109..d897dd2a1a 100644 --- a/crates/ruff/src/rules/pyflakes/rules/default_except_not_last.rs +++ b/crates/ruff/src/rules/pyflakes/rules/default_except_not_last.rs @@ -1,9 +1,9 @@ -use rustpython_parser::ast::{self, ExceptHandler}; +use rustpython_ast::{self as ast, ExceptHandler}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::identifier::except; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; /// ## What it does /// Checks for `except` blocks that handle all exceptions, but are not the last @@ -63,7 +63,7 @@ pub(crate) fn default_except_not_last( if type_.is_none() && idx < handlers.len() - 1 { return Some(Diagnostic::new( DefaultExceptNotLast, - except(handler, locator), + except(handler, locator.contents()), )); } } diff --git a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index ac9dee4446..7cb1f8163b 100644 --- a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -1,10 +1,10 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::{lexer, Mode, StringKind, Tok}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::AsRule; diff --git a/crates/ruff/src/rules/pyflakes/rules/future_feature_not_defined.rs b/crates/ruff/src/rules/pyflakes/rules/future_feature_not_defined.rs index a00d5267e3..56fb9b37c7 100644 --- a/crates/ruff/src/rules/pyflakes/rules/future_feature_not_defined.rs +++ b/crates/ruff/src/rules/pyflakes/rules/future_feature_not_defined.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged}; +use rustpython_ast::{Alias, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/if_tuple.rs b/crates/ruff/src/rules/pyflakes/rules/if_tuple.rs index 0fe40fd842..d6f86b5e23 100644 --- a/crates/ruff/src/rules/pyflakes/rules/if_tuple.rs +++ b/crates/ruff/src/rules/pyflakes/rules/if_tuple.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, StmtIf}; +use rustpython_ast::{self as ast, Expr, Ranged, StmtIf}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/imports.rs b/crates/ruff/src/rules/pyflakes/rules/imports.rs index 4f6be6c9ab..1170b4e114 100644 --- a/crates/ruff/src/rules/pyflakes/rules/imports.rs +++ b/crates/ruff/src/rules/pyflakes/rules/imports.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::OneIndexed; +use ruff_source_file::OneIndexed; /// ## What it does /// Checks for import bindings that are shadowed by loop variables. diff --git a/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs b/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs index ea5cbfd90f..5e8755d538 100644 --- a/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -1,9 +1,10 @@ use log::error; -use rustpython_parser::ast::{CmpOp, Expr, Ranged}; +use rustpython_ast::{CmpOp, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers; +use ruff_python_parser::locate_cmp_ops; use crate::checkers::ast::Checker; use crate::registry::AsRule; @@ -85,7 +86,7 @@ pub(crate) fn invalid_literal_comparison( let mut diagnostic = Diagnostic::new(IsLiteral { cmp_op: op.into() }, expr.range()); if checker.patch(diagnostic.kind.rule()) { if lazy_located.is_none() { - lazy_located = Some(helpers::locate_cmp_ops(expr, checker.locator())); + lazy_located = Some(locate_cmp_ops(expr, checker.locator().contents())); } if let Some(located_op) = lazy_located.as_ref().and_then(|located| located.get(index)) diff --git a/crates/ruff/src/rules/pyflakes/rules/invalid_print_syntax.rs b/crates/ruff/src/rules/pyflakes/rules/invalid_print_syntax.rs index 9cc7a3eeaf..fe7211cd9a 100644 --- a/crates/ruff/src/rules/pyflakes/rules/invalid_print_syntax.rs +++ b/crates/ruff/src/rules/pyflakes/rules/invalid_print_syntax.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs index 0bbdfffb2b..31f5ad8adb 100644 --- a/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/redefined_while_unused.rs b/crates/ruff/src/rules/pyflakes/rules/redefined_while_unused.rs index e320e607ad..f8af8854ab 100644 --- a/crates/ruff/src/rules/pyflakes/rules/redefined_while_unused.rs +++ b/crates/ruff/src/rules/pyflakes/rules/redefined_while_unused.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Violation; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::OneIndexed; +use ruff_source_file::OneIndexed; /// ## What it does /// Checks for variable definitions that redefine (or "shadow") unused diff --git a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs index 5b9043910b..6cdcbdc8b5 100644 --- a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs @@ -1,7 +1,7 @@ use std::hash::BuildHasherDefault; use rustc_hash::{FxHashMap, FxHashSet}; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/return_outside_function.rs b/crates/ruff/src/rules/pyflakes/rules/return_outside_function.rs index 54acb483fd..a2ab90a41d 100644 --- a/crates/ruff/src/rules/pyflakes/rules/return_outside_function.rs +++ b/crates/ruff/src/rules/pyflakes/rules/return_outside_function.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/starred_expressions.rs b/crates/ruff/src/rules/pyflakes/rules/starred_expressions.rs index 723d2dcc31..aab23dd666 100644 --- a/crates/ruff/src/rules/pyflakes/rules/starred_expressions.rs +++ b/crates/ruff/src/rules/pyflakes/rules/starred_expressions.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/strings.rs b/crates/ruff/src/rules/pyflakes/rules/strings.rs index 160304ab97..aff48a1d99 100644 --- a/crates/ruff/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff/src/rules/pyflakes/rules/strings.rs @@ -2,7 +2,7 @@ use std::string::ToString; use ruff_text_size::TextRange; use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Constant, Expr, Identifier, Keyword}; +use rustpython_ast::{self as ast, Constant, Expr, Identifier, Keyword}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs index a3da7f7878..b4d5ca2226 100644 --- a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs @@ -1,13 +1,13 @@ use itertools::Itertools; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::contains_effect; -use ruff_python_ast::source_code::Locator; use ruff_python_semantic::Scope; +use ruff_source_file::Locator; use crate::autofix::edits::delete_stmt; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pyflakes/rules/yield_outside_function.rs b/crates/ruff/src/rules/pyflakes/rules/yield_outside_function.rs index f57f092ce5..ffaf92bb39 100644 --- a/crates/ruff/src/rules/pyflakes/rules/yield_outside_function.rs +++ b/crates/ruff/src/rules/pyflakes/rules/yield_outside_function.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/blanket_noqa.rs b/crates/ruff/src/rules/pygrep_hooks/rules/blanket_noqa.rs index 268a092e61..e8524a0030 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/blanket_noqa.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/blanket_noqa.rs @@ -1,8 +1,9 @@ -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; use crate::noqa::Directive; diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs b/crates/ruff/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs index 775d69395a..3f7cad8445 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs @@ -6,7 +6,8 @@ use ruff_text_size::TextSize; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Indexer, Locator}; +use ruff_python_index::Indexer; +use ruff_source_file::Locator; /// ## What it does /// Check for `type: ignore` annotations that suppress all type warnings, as diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs b/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs index 19765c7876..fddc81b98d 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/invalid_mock_access.rs b/crates/ruff/src/rules/pygrep_hooks/rules/invalid_mock_access.rs index d0b52d3ca8..5ae4d4fc6e 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/invalid_mock_access.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/invalid_mock_access.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/no_eval.rs b/crates/ruff/src/rules/pygrep_hooks/rules/no_eval.rs index a5d8572f95..8e66b5da2f 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/no_eval.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/no_eval.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/helpers.rs b/crates/ruff/src/rules/pylint/helpers.rs index 10185d1ef1..cf68493ca4 100644 --- a/crates/ruff/src/rules/pylint/helpers.rs +++ b/crates/ruff/src/rules/pylint/helpers.rs @@ -1,8 +1,8 @@ use std::fmt; use ruff_python_ast::helpers::find_keyword; +use rustpython_ast::{CmpOp, Constant, Expr, Keyword}; use rustpython_parser::ast; -use rustpython_parser::ast::{CmpOp, Constant, Expr, Keyword}; use ruff_python_semantic::analyze::function_type; use ruff_python_semantic::{ScopeKind, SemanticModel}; diff --git a/crates/ruff/src/rules/pylint/rules/assert_on_string_literal.rs b/crates/ruff/src/rules/pylint/rules/assert_on_string_literal.rs index a529d9f256..fc7f5b0677 100644 --- a/crates/ruff/src/rules/pylint/rules/assert_on_string_literal.rs +++ b/crates/ruff/src/rules/pylint/rules/assert_on_string_literal.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/await_outside_async.rs b/crates/ruff/src/rules/pylint/rules/await_outside_async.rs index 850cf7a9f7..0ba9037fe1 100644 --- a/crates/ruff/src/rules/pylint/rules/await_outside_async.rs +++ b/crates/ruff/src/rules/pylint/rules/await_outside_async.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/bad_str_strip_call.rs b/crates/ruff/src/rules/pylint/rules/bad_str_strip_call.rs index 5cb9e49ba1..3ff8236ca7 100644 --- a/crates/ruff/src/rules/pylint/rules/bad_str_strip_call.rs +++ b/crates/ruff/src/rules/pylint/rules/bad_str_strip_call.rs @@ -1,7 +1,7 @@ use std::fmt; use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/bad_string_format_type.rs b/crates/ruff/src/rules/pylint/rules/bad_string_format_type.rs index 47103806e6..d1bd29c2e9 100644 --- a/crates/ruff/src/rules/pylint/rules/bad_string_format_type.rs +++ b/crates/ruff/src/rules/pylint/rules/bad_string_format_type.rs @@ -2,8 +2,8 @@ use std::str::FromStr; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use rustpython_format::cformat::{CFormatPart, CFormatSpec, CFormatStrOrBytes, CFormatString}; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; use rustpython_parser::{lexer, Mode}; use ruff_diagnostics::{Diagnostic, Violation}; diff --git a/crates/ruff/src/rules/pylint/rules/bidirectional_unicode.rs b/crates/ruff/src/rules/pylint/rules/bidirectional_unicode.rs index 15e0b1c8e5..68ce969d50 100644 --- a/crates/ruff/src/rules/pylint/rules/bidirectional_unicode.rs +++ b/crates/ruff/src/rules/pylint/rules/bidirectional_unicode.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::Line; +use ruff_source_file::Line; const BIDI_UNICODE: [char; 10] = [ '\u{202A}', //{LEFT-TO-RIGHT EMBEDDING} diff --git a/crates/ruff/src/rules/pylint/rules/binary_op_exception.rs b/crates/ruff/src/rules/pylint/rules/binary_op_exception.rs index fc871a02ec..b2c65e0418 100644 --- a/crates/ruff/src/rules/pylint/rules/binary_op_exception.rs +++ b/crates/ruff/src/rules/pylint/rules/binary_op_exception.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/collapsible_else_if.rs b/crates/ruff/src/rules/pylint/rules/collapsible_else_if.rs index 1ad81b4cf7..561a013394 100644 --- a/crates/ruff/src/rules/pylint/rules/collapsible_else_if.rs +++ b/crates/ruff/src/rules/pylint/rules/collapsible_else_if.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{ElifElseClause, Ranged, Stmt}; +use rustpython_ast::{ElifElseClause, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs b/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs index 60f1cbad8c..5224399fa7 100644 --- a/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs +++ b/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs @@ -1,6 +1,6 @@ use anyhow::bail; use itertools::Itertools; -use rustpython_parser::ast::{self, CmpOp, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/comparison_of_constant.rs b/crates/ruff/src/rules/pylint/rules/comparison_of_constant.rs index 0caac387c4..d2ed350c65 100644 --- a/crates/ruff/src/rules/pylint/rules/comparison_of_constant.rs +++ b/crates/ruff/src/rules/pylint/rules/comparison_of_constant.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{self, CmpOp, Expr, Ranged}; +use rustpython_ast::{self as ast, CmpOp, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff/src/rules/pylint/rules/comparison_with_itself.rs index 7758eb2989..e055012986 100644 --- a/crates/ruff/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff/src/rules/pylint/rules/comparison_with_itself.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{CmpOp, Expr, Ranged}; +use rustpython_ast::{CmpOp, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/continue_in_finally.rs b/crates/ruff/src/rules/pylint/rules/continue_in_finally.rs index 84a553c929..f11b6d55c7 100644 --- a/crates/ruff/src/rules/pylint/rules/continue_in_finally.rs +++ b/crates/ruff/src/rules/pylint/rules/continue_in_finally.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/duplicate_bases.rs b/crates/ruff/src/rules/pylint/rules/duplicate_bases.rs index 860e393565..0757975a54 100644 --- a/crates/ruff/src/rules/pylint/rules/duplicate_bases.rs +++ b/crates/ruff/src/rules/pylint/rules/duplicate_bases.rs @@ -1,7 +1,7 @@ use std::hash::BuildHasherDefault; use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/duplicate_value.rs b/crates/ruff/src/rules/pylint/rules/duplicate_value.rs index 46ba673cc8..c2e5a08521 100644 --- a/crates/ruff/src/rules/pylint/rules/duplicate_value.rs +++ b/crates/ruff/src/rules/pylint/rules/duplicate_value.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashSet; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/import_self.rs b/crates/ruff/src/rules/pylint/rules/import_self.rs index 63ba4cfb99..88ecbb679f 100644 --- a/crates/ruff/src/rules/pylint/rules/import_self.rs +++ b/crates/ruff/src/rules/pylint/rules/import_self.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged}; +use rustpython_ast::{Alias, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/invalid_envvar_default.rs b/crates/ruff/src/rules/pylint/rules/invalid_envvar_default.rs index e07dd669f0..07cb4e9175 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_envvar_default.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_envvar_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/invalid_envvar_value.rs b/crates/ruff/src/rules/pylint/rules/invalid_envvar_value.rs index cb64bcdcc3..424d45087a 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_envvar_value.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_envvar_value.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Operator, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Operator, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/invalid_str_return.rs b/crates/ruff/src/rules/pylint/rules/invalid_str_return.rs index 9f43d0d96c..bee5e9eef9 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_str_return.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_str_return.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt}; +use rustpython_ast::{Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs b/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs index 5bccae0694..2bd640f326 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs @@ -4,7 +4,7 @@ use ruff_diagnostics::AlwaysAutofixableViolation; use ruff_diagnostics::Edit; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; /// ## What it does /// Checks for strings that contain the control character `BS`. diff --git a/crates/ruff/src/rules/pylint/rules/iteration_over_set.rs b/crates/ruff/src/rules/pylint/rules/iteration_over_set.rs index 38725f7e4f..d990ef7b50 100644 --- a/crates/ruff/src/rules/pylint/rules/iteration_over_set.rs +++ b/crates/ruff/src/rules/pylint/rules/iteration_over_set.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/load_before_global_declaration.rs b/crates/ruff/src/rules/pylint/rules/load_before_global_declaration.rs index b48184442a..fa8585ed0f 100644 --- a/crates/ruff/src/rules/pylint/rules/load_before_global_declaration.rs +++ b/crates/ruff/src/rules/pylint/rules/load_before_global_declaration.rs @@ -1,8 +1,8 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::OneIndexed; +use ruff_source_file::OneIndexed; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pylint/rules/logging.rs b/crates/ruff/src/rules/pylint/rules/logging.rs index d561bcfb3d..a1fc13abb3 100644 --- a/crates/ruff/src/rules/pylint/rules/logging.rs +++ b/crates/ruff/src/rules/pylint/rules/logging.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/magic_value_comparison.rs b/crates/ruff/src/rules/pylint/rules/magic_value_comparison.rs index 2a3b1e7a53..f83de2a116 100644 --- a/crates/ruff/src/rules/pylint/rules/magic_value_comparison.rs +++ b/crates/ruff/src/rules/pylint/rules/magic_value_comparison.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{self, Constant, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff/src/rules/pylint/rules/manual_import_from.rs index 0343cd1eb7..cd566b1eb8 100644 --- a/crates/ruff/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff/src/rules/pylint/rules/manual_import_from.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Alias, Identifier, Int, Ranged, Stmt}; +use rustpython_ast::{self as ast, Alias, Identifier, Int, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/named_expr_without_context.rs b/crates/ruff/src/rules/pylint/rules/named_expr_without_context.rs index 27627585c8..912787c97d 100644 --- a/crates/ruff/src/rules/pylint/rules/named_expr_without_context.rs +++ b/crates/ruff/src/rules/pylint/rules/named_expr_without_context.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff/src/rules/pylint/rules/nested_min_max.rs index d7f2edb71c..58d72a8003 100644 --- a/crates/ruff/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff/src/rules/pylint/rules/nested_min_max.rs @@ -1,9 +1,8 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Expr, Keyword, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::has_comments; use ruff_python_semantic::SemanticModel; use crate::{checkers::ast::Checker, registry::AsRule}; @@ -150,7 +149,7 @@ pub(crate) fn nested_min_max( }) { let mut diagnostic = Diagnostic::new(NestedMinMax { func: min_max }, expr.range()); if checker.patch(diagnostic.kind.rule()) { - if !has_comments(expr, checker.locator(), checker.indexer()) { + if !checker.indexer().has_comments(expr, checker.locator()) { let flattened_expr = Expr::Call(ast::ExprCall { func: Box::new(func.clone()), args: collect_nested_args(min_max, args, checker.semantic()), diff --git a/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs b/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs index 08d229a25f..ba1d213e9e 100644 --- a/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs +++ b/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Arguments, Decorator, Expr, Stmt}; +use rustpython_ast::{self as ast, Arguments, Decorator, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/redefined_loop_name.rs b/crates/ruff/src/rules/pylint/rules/redefined_loop_name.rs index ec9fd9e28d..9c6e148304 100644 --- a/crates/ruff/src/rules/pylint/rules/redefined_loop_name.rs +++ b/crates/ruff/src/rules/pylint/rules/redefined_loop_name.rs @@ -1,7 +1,7 @@ use std::{fmt, iter}; use regex::Regex; -use rustpython_parser::ast::{self, Expr, ExprContext, Ranged, Stmt, WithItem}; +use rustpython_ast::{self as ast, Expr, ExprContext, Ranged, Stmt, WithItem}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/repeated_equality_comparison_target.rs b/crates/ruff/src/rules/pylint/rules/repeated_equality_comparison_target.rs index 055f92ca2e..d975e6de8e 100644 --- a/crates/ruff/src/rules/pylint/rules/repeated_equality_comparison_target.rs +++ b/crates/ruff/src/rules/pylint/rules/repeated_equality_comparison_target.rs @@ -3,12 +3,12 @@ use std::ops::Deref; use itertools::{any, Itertools}; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{BoolOp, CmpOp, Expr, ExprBoolOp, ExprCompare, Ranged}; +use rustpython_ast::{BoolOp, CmpOp, Expr, ExprBoolOp, ExprCompare, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::hashable::HashableExpr; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pylint/rules/repeated_isinstance_calls.rs b/crates/ruff/src/rules/pylint/rules/repeated_isinstance_calls.rs index c4038767cc..ab33eb7f5d 100644 --- a/crates/ruff/src/rules/pylint/rules/repeated_isinstance_calls.rs +++ b/crates/ruff/src/rules/pylint/rules/repeated_isinstance_calls.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; -use rustpython_parser::ast::{self, BoolOp, Expr, Ranged}; +use rustpython_ast::{self as ast, BoolOp, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/return_in_init.rs b/crates/ruff/src/rules/pylint/rules/return_in_init.rs index 0a6a81ebdc..f0e0f3a4af 100644 --- a/crates/ruff/src/rules/pylint/rules/return_in_init.rs +++ b/crates/ruff/src/rules/pylint/rules/return_in_init.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs b/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs index 1cc8f1712d..efd0c7b494 100644 --- a/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs +++ b/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/single_string_slots.rs b/crates/ruff/src/rules/pylint/rules/single_string_slots.rs index 54ca42e694..6a5460ee12 100644 --- a/crates/ruff/src/rules/pylint/rules/single_string_slots.rs +++ b/crates/ruff/src/rules/pylint/rules/single_string_slots.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Stmt, StmtClassDef}; +use rustpython_ast::{self as ast, Constant, Expr, Stmt, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs b/crates/ruff/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs index 22a2d6647a..c1eec1e51f 100644 --- a/crates/ruff/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs +++ b/crates/ruff/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::{find_keyword, is_const_none}; -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs index 073ddf9898..1331d16f03 100644 --- a/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs index 4db54ced09..baff183f89 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Arguments, Stmt}; +use rustpython_ast::{Arguments, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/too_many_branches.rs b/crates/ruff/src/rules/pylint/rules/too_many_branches.rs index 32e2cf728b..a83f6d8d9e 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_branches.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_branches.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -183,7 +183,7 @@ pub(crate) fn too_many_branches( #[cfg(test)] mod tests { use anyhow::Result; - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::Parse; use super::num_branches; diff --git a/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs b/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs index 6b7f7de10a..0bb799fbeb 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -98,7 +98,7 @@ pub(crate) fn too_many_return_statements( #[cfg(test)] mod tests { use anyhow::Result; - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::Parse; use super::num_returns; diff --git a/crates/ruff/src/rules/pylint/rules/too_many_statements.rs b/crates/ruff/src/rules/pylint/rules/too_many_statements.rs index 0832b55c83..f9a7f7921d 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_statements.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_statements.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -166,7 +166,7 @@ pub(crate) fn too_many_statements( #[cfg(test)] mod tests { use anyhow::Result; - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::Parse; use super::num_statements; diff --git a/crates/ruff/src/rules/pylint/rules/type_bivariance.rs b/crates/ruff/src/rules/pylint/rules/type_bivariance.rs index 42033c2812..15bc18cddd 100644 --- a/crates/ruff/src/rules/pylint/rules/type_bivariance.rs +++ b/crates/ruff/src/rules/pylint/rules/type_bivariance.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/type_name_incorrect_variance.rs b/crates/ruff/src/rules/pylint/rules/type_name_incorrect_variance.rs index 3ccde61c50..427a855a13 100644 --- a/crates/ruff/src/rules/pylint/rules/type_name_incorrect_variance.rs +++ b/crates/ruff/src/rules/pylint/rules/type_name_incorrect_variance.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/type_param_name_mismatch.rs b/crates/ruff/src/rules/pylint/rules/type_param_name_mismatch.rs index e7bbc7ae04..1bb47a473e 100644 --- a/crates/ruff/src/rules/pylint/rules/type_param_name_mismatch.rs +++ b/crates/ruff/src/rules/pylint/rules/type_param_name_mismatch.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/unexpected_special_method_signature.rs b/crates/ruff/src/rules/pylint/rules/unexpected_special_method_signature.rs index e77b612130..736aee30fc 100644 --- a/crates/ruff/src/rules/pylint/rules/unexpected_special_method_signature.rs +++ b/crates/ruff/src/rules/pylint/rules/unexpected_special_method_signature.rs @@ -1,6 +1,6 @@ use std::cmp::Ordering; -use rustpython_parser::ast::{Arguments, Decorator, Stmt}; +use rustpython_ast::{Arguments, Decorator, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs b/crates/ruff/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs index 528cbee097..5751b1c2bd 100644 --- a/crates/ruff/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs +++ b/crates/ruff/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/useless_else_on_loop.rs b/crates/ruff/src/rules/pylint/rules/useless_else_on_loop.rs index d512b01692..caf60c1149 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_else_on_loop.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_else_on_loop.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, MatchCase, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, MatchCase, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; @@ -109,7 +109,7 @@ pub(crate) fn useless_else_on_loop( if !orelse.is_empty() && !loop_exits_early(body) { checker.diagnostics.push(Diagnostic::new( UselessElseOnLoop, - identifier::else_(stmt, checker.locator()).unwrap(), + identifier::else_(stmt, checker.locator().contents()).unwrap(), )); } } diff --git a/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs b/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs index 481be6265a..065b144c01 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Alias, Ranged}; +use rustpython_ast::{Alias, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/useless_return.rs b/crates/ruff/src/rules/pylint/rules/useless_return.rs index b353463d42..c2d5324deb 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_return.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/yield_from_in_async_function.rs b/crates/ruff/src/rules/pylint/rules/yield_from_in_async_function.rs index 9b329b3a19..2db4d7bac3 100644 --- a/crates/ruff/src/rules/pylint/rules/yield_from_in_async_function.rs +++ b/crates/ruff/src/rules/pylint/rules/yield_from_in_async_function.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ExprYieldFrom, Ranged}; +use rustpython_ast::{ExprYieldFrom, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/rules/yield_in_init.rs b/crates/ruff/src/rules/pylint/rules/yield_in_init.rs index 2fabc842cc..ed047b62a7 100644 --- a/crates/ruff/src/rules/pylint/rules/yield_in_init.rs +++ b/crates/ruff/src/rules/pylint/rules/yield_in_init.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pylint/settings.rs b/crates/ruff/src/rules/pylint/settings.rs index c8aeb96590..fd0ff2a5f5 100644 --- a/crates/ruff/src/rules/pylint/settings.rs +++ b/crates/ruff/src/rules/pylint/settings.rs @@ -1,7 +1,7 @@ //! Settings for the `pylint` plugin. use anyhow::anyhow; -use rustpython_parser::ast::Constant; +use rustpython_ast::Constant; use serde::{Deserialize, Serialize}; use ruff_macros::{CacheKey, CombineOptions, ConfigurationOptions}; diff --git a/crates/ruff/src/rules/pyupgrade/fixes.rs b/crates/ruff/src/rules/pyupgrade/fixes.rs index b20e351635..bcaee59295 100644 --- a/crates/ruff/src/rules/pyupgrade/fixes.rs +++ b/crates/ruff/src/rules/pyupgrade/fixes.rs @@ -1,12 +1,13 @@ use anyhow::Result; use libcst_native::ParenthesizableWhitespace; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use rustpython_parser::{lexer, Mode, Tok}; use crate::autofix::codemods::CodegenStylist; use ruff_diagnostics::Edit; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::cst::matchers::{ match_call_mut, match_expression, match_function_def, match_indented_block, match_statement, diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 95c24d3042..e0029ec4a5 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -1,14 +1,12 @@ use anyhow::{bail, Result}; use log::debug; use ruff_text_size::TextRange; -use rustpython_parser::ast::{ - self, Constant, Expr, ExprContext, Identifier, Keyword, Ranged, Stmt, -}; +use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Identifier, Keyword, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_dunder; -use ruff_python_ast::source_code::Generator; +use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::identifiers::is_identifier; diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 73f6d9c504..3239d86838 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -1,14 +1,12 @@ use anyhow::{bail, Result}; use log::debug; use ruff_text_size::TextRange; -use rustpython_parser::ast::{ - self, Constant, Expr, ExprContext, Identifier, Keyword, Ranged, Stmt, -}; +use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Identifier, Keyword, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::{find_keyword, is_dunder}; -use ruff_python_ast::source_code::Generator; +use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::identifiers::is_identifier; diff --git a/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs index 91a018ffcd..570ba3306e 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index 80d480a611..61f61f4a10 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs index dd98ea9876..7b9b1e0e3d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs @@ -1,10 +1,11 @@ use itertools::Itertools; -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; use ruff_python_ast::whitespace::indentation; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs index e4dbdd7d5d..5878357576 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -4,14 +4,15 @@ use libcst_native::{ ImportNames, Name, NameOrAttribute, ParenthesizableWhitespace, }; use log::error; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use crate::autofix::codemods::CodegenStylist; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::collect_call_path; -use ruff_python_ast::source_code::{Locator, Stylist}; use ruff_python_ast::whitespace::indentation; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::cst::matchers::{match_import, match_import_from, match_statement}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index 80bd2aecb6..9f38f4d74e 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -1,6 +1,6 @@ use once_cell::sync::Lazy; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs index 185932b8eb..719c74e7ad 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -4,7 +4,7 @@ use rustpython_parser::Tok; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::registry::Rule; use crate::settings::Settings; diff --git a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs index cfccd458df..334ebec882 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs @@ -2,15 +2,15 @@ use std::borrow::Cow; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use rustpython_format::{ FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate, }; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::str::{is_implicit_concatenation, leading_quote, trailing_quote}; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::line_width::LineLength; diff --git a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs index 3919c18a22..5dc7eeb5c9 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs @@ -2,11 +2,12 @@ use anyhow::{anyhow, Result}; use libcst_native::{Arg, Expression}; use once_cell::sync::Lazy; use regex::Regex; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index 68d045d50c..656e6753c1 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Decorator, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Decorator, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index 594025e287..e919cf0c7a 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Decorator, Expr, Ranged}; +use rustpython_ast::{self as ast, Decorator, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs index d53a16b0d2..402f8c7b59 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs @@ -2,7 +2,7 @@ use std::fmt; use std::str::FromStr; use num_bigint::BigInt; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs index 259615755a..381f6517de 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs index 6739f5b680..5fb7759eb0 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, ExceptHandler, Expr, ExprContext, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, ExprContext, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs index bb2c5e54c2..adb1350419 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use num_bigint::{BigInt, Sign}; use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{self, CmpOp, Constant, ElifElseClause, Expr, Ranged, StmtIf}; +use rustpython_ast::{self as ast, CmpOp, Constant, ElifElseClause, Expr, Ranged, StmtIf}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs index 88fea3a7fc..a82fc6760a 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -1,18 +1,18 @@ use std::str::FromStr; use ruff_text_size::TextRange; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use rustpython_format::cformat::{ CConversionFlags, CFormatPart, CFormatPrecision, CFormatQuantity, CFormatString, }; -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_python_ast::whitespace::indentation; use ruff_python_stdlib::identifiers::is_identifier; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::AsRule; diff --git a/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs index f77876df7b..7ee67310df 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -2,14 +2,14 @@ use std::str::FromStr; use anyhow::{anyhow, Result}; use ruff_text_size::TextSize; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use rustpython_parser::{lexer, Mode}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::find_keyword; -use ruff_python_ast::source_code::Locator; use ruff_python_semantic::SemanticModel; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs b/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs index ae14c2d481..d32f8fb7ab 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -1,10 +1,10 @@ use anyhow::Result; -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::find_keyword; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::autofix::edits::remove_argument; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs b/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs index 64b3e59aab..3eefd69850 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{Expr, Keyword, Ranged}; +use rustpython_ast::{Expr, Keyword, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs index b9e032ca8b..cb56187487 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Arg, ArgWithDefault, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Arg, ArgWithDefault, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs index 9be33ea2c0..51ada115d8 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs index ea8d0955ce..5ac4936636 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 4058be5de3..1e430a0c46 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs index 4ea985a854..115585f90d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs index a0cd87fd1f..835b4433d2 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs @@ -1,7 +1,7 @@ use std::ops::Add; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, Ranged}; +use rustpython_ast::{self as ast, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs index 0b3932e705..e404757408 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -3,7 +3,7 @@ use regex::Regex; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_trivia::Line; +use ruff_source_file::Line; /// ## What it does /// Checks for unnecessary UTF-8 encoding declarations. diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 5124033c56..3e85b88d8c 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -1,10 +1,10 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Keyword, Ranged}; use rustpython_parser::{lexer, Mode, Tok}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::autofix::edits::remove_argument; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 7c9fa994d0..e067a64330 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use rustpython_parser::ast::{Alias, Ranged, Stmt}; +use rustpython_ast::{Alias, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs b/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs index c24342461f..bd634d4c65 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs index 8082d1b374..e96f758574 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs index 37b9a0b8ae..3018b976e7 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -1,11 +1,11 @@ use itertools::Either::{Left, Right}; use itertools::Itertools; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; use ruff_python_semantic::analyze::typing::Pep604Operator; +use ruff_source_file::Locator; use crate::checkers::ast::Checker; use crate::registry::AsRule; diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index 7ffa04286d..147f421395 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, Operator, Ranged}; +use rustpython_ast::{self as ast, Expr, Operator, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs index 2b4b1fae2d..d8e847c190 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs index 45f921a8a2..ea26a66e0f 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs index 8917ba0246..3d7e530f92 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashMap; -use rustpython_parser::ast::{self, Expr, ExprContext, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, ExprContext, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/pyupgrade/types.rs b/crates/ruff/src/rules/pyupgrade/types.rs index ab7223aa8e..0d47cfe485 100644 --- a/crates/ruff/src/rules/pyupgrade/types.rs +++ b/crates/ruff/src/rules/pyupgrade/types.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Constant; +use rustpython_ast::Constant; use serde::{Deserialize, Serialize}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/ruff/src/rules/ruff/mod.rs b/crates/ruff/src/rules/ruff/mod.rs index 18c15fda9e..f85b8045ce 100644 --- a/crates/ruff/src/rules/ruff/mod.rs +++ b/crates/ruff/src/rules/ruff/mod.rs @@ -12,7 +12,7 @@ mod tests { use rustc_hash::FxHashSet; use test_case::test_case; - use ruff_python_ast::source_code::SourceFileBuilder; + use ruff_source_file::SourceFileBuilder; use crate::pyproject_toml::lint_pyproject_toml; use crate::registry::Rule; diff --git a/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs index e9bdca4adf..7248721070 100644 --- a/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -4,7 +4,7 @@ use std::fmt; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, DiagnosticKind, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::registry::AsRule; use crate::rules::ruff::rules::confusables::confusable; diff --git a/crates/ruff/src/rules/ruff/rules/asyncio_dangling_task.rs b/crates/ruff/src/rules/ruff/rules/asyncio_dangling_task.rs index 9652411ca1..695c0a19e2 100644 --- a/crates/ruff/src/rules/ruff/rules/asyncio_dangling_task.rs +++ b/crates/ruff/src/rules/ruff/rules/asyncio_dangling_task.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs index b35ee4d61d..53aef1b68a 100644 --- a/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -1,9 +1,8 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, ExprContext, Operator, Ranged}; +use rustpython_ast::{self as ast, Expr, ExprContext, Operator, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::helpers::has_comments; use crate::checkers::ast::Checker; use crate::registry::AsRule; @@ -192,7 +191,7 @@ pub(crate) fn collection_literal_concatenation(checker: &mut Checker, expr: &Exp expr.range(), ); if checker.patch(diagnostic.kind.rule()) { - if !has_comments(expr, checker.locator(), checker.indexer()) { + if !checker.indexer().has_comments(expr, checker.locator()) { // This suggestion could be unsafe if the non-literal expression in the // expression has overridden the `__add__` (or `__radd__`) magic methods. diagnostic.set_fix(Fix::suggested(Edit::range_replacement( diff --git a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index 379ee7dcad..87f82844e2 100644 --- a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -2,11 +2,12 @@ use anyhow::{bail, Result}; use libcst_native::{ ConcatenatedString, Expression, FormattedStringContent, FormattedStringExpression, }; -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::source_code::{Locator, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_source_file::Locator; use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/ruff/rules/function_call_in_dataclass_default.rs b/crates/ruff/src/rules/ruff/rules/function_call_in_dataclass_default.rs index 3b52cac788..da5efc15d7 100644 --- a/crates/ruff/src/rules/ruff/rules/function_call_in_dataclass_default.rs +++ b/crates/ruff/src/rules/ruff/rules/function_call_in_dataclass_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/helpers.rs b/crates/ruff/src/rules/ruff/rules/helpers.rs index 8ba7e01624..b95980c920 100644 --- a/crates/ruff/src/rules/ruff/rules/helpers.rs +++ b/crates/ruff/src/rules/ruff/rules/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use ruff_python_ast::helpers::map_callable; use ruff_python_semantic::{BindingKind, SemanticModel}; diff --git a/crates/ruff/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff/src/rules/ruff/rules/implicit_optional.rs index 301b5ddb79..8ca107d555 100644 --- a/crates/ruff/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff/src/rules/ruff/rules/implicit_optional.rs @@ -2,12 +2,12 @@ use std::fmt; use anyhow::Result; use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Constant, Expr, Operator, Ranged}; +use rustpython_ast::{self as ast, ArgWithDefault, Arguments, Constant, Expr, Operator, Ranged}; use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; -use ruff_python_ast::typing::parse_type_annotation; +use ruff_python_parser::typing::parse_type_annotation; use crate::checkers::ast::Checker; use crate::importer::ImportRequest; @@ -191,7 +191,8 @@ pub(crate) fn implicit_optional(checker: &mut Checker, arguments: &Arguments) { }) = annotation.as_ref() { // Quoted annotation. - if let Ok((annotation, kind)) = parse_type_annotation(string, *range, checker.locator()) + if let Ok((annotation, kind)) = + parse_type_annotation(string, *range, checker.locator().contents()) { let Some(expr) = type_hint_explicitly_allows_none( &annotation, diff --git a/crates/ruff/src/rules/ruff/rules/invalid_index_type.rs b/crates/ruff/src/rules/ruff/rules/invalid_index_type.rs index 50719e2a28..4c591ecba3 100644 --- a/crates/ruff/src/rules/ruff/rules/invalid_index_type.rs +++ b/crates/ruff/src/rules/ruff/rules/invalid_index_type.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Constant, Expr, ExprConstant, ExprSlice, ExprSubscript, Ranged}; +use rustpython_ast::{Constant, Expr, ExprConstant, ExprSlice, ExprSubscript, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/mutable_class_default.rs b/crates/ruff/src/rules/ruff/rules/mutable_class_default.rs index c1d17c30d5..41278fdc04 100644 --- a/crates/ruff/src/rules/ruff/rules/mutable_class_default.rs +++ b/crates/ruff/src/rules/ruff/rules/mutable_class_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/mutable_dataclass_default.rs b/crates/ruff/src/rules/ruff/rules/mutable_dataclass_default.rs index 2b47c32a46..07b3e19e71 100644 --- a/crates/ruff/src/rules/ruff/rules/mutable_dataclass_default.rs +++ b/crates/ruff/src/rules/ruff/rules/mutable_dataclass_default.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Ranged, Stmt}; +use rustpython_ast::{self as ast, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/pairwise_over_zipped.rs b/crates/ruff/src/rules/ruff/rules/pairwise_over_zipped.rs index 1b3f234a78..66510f4974 100644 --- a/crates/ruff/src/rules/ruff/rules/pairwise_over_zipped.rs +++ b/crates/ruff/src/rules/ruff/rules/pairwise_over_zipped.rs @@ -1,5 +1,5 @@ use num_traits::ToPrimitive; -use rustpython_parser::ast::{self, Constant, Expr, Ranged, UnaryOp}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/static_key_dict_comprehension.rs b/crates/ruff/src/rules/ruff/rules/static_key_dict_comprehension.rs index 4165230bc8..77f8d23663 100644 --- a/crates/ruff/src/rules/ruff/rules/static_key_dict_comprehension.rs +++ b/crates/ruff/src/rules/ruff/rules/static_key_dict_comprehension.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::{Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index 1bab0e9f36..d657a99a56 100644 --- a/crates/ruff/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use num_bigint::BigInt; use num_traits::{One, Zero}; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{self, Comprehension, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Comprehension, Constant, Expr, Ranged}; use unicode_width::UnicodeWidthStr; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; diff --git a/crates/ruff/src/rules/ruff/rules/unreachable.rs b/crates/ruff/src/rules/ruff/rules/unreachable.rs index 6b3e81fd5d..59decf78e6 100644 --- a/crates/ruff/src/rules/ruff/rules/unreachable.rs +++ b/crates/ruff/src/rules/ruff/rules/unreachable.rs @@ -1,7 +1,7 @@ use std::{fmt, iter, usize}; use log::error; -use rustpython_parser::ast::{ +use rustpython_ast::{ Expr, Identifier, MatchCase, Pattern, PatternMatchAs, Ranged, Stmt, StmtAsyncFor, StmtAsyncWith, StmtFor, StmtMatch, StmtReturn, StmtTry, StmtTryStar, StmtWhile, StmtWith, }; @@ -1053,7 +1053,7 @@ mod tests { use std::fs; use std::path::PathBuf; - use rustpython_parser::ast::Ranged; + use rustpython_ast::Ranged; use rustpython_parser::{parse, Mode}; use std::fmt::Write; use test_case::test_case; diff --git a/crates/ruff/src/rules/ruff/typing.rs b/crates/ruff/src/rules/ruff/typing.rs index e239ada9f1..8cf8a7e884 100644 --- a/crates/ruff/src/rules/ruff/typing.rs +++ b/crates/ruff/src/rules/ruff/typing.rs @@ -1,11 +1,11 @@ use itertools::Either::{Left, Right}; -use rustpython_parser::ast::{self, Constant, Expr, Operator}; +use rustpython_ast::{self as ast, Constant, Expr, Operator}; use ruff_python_ast::call_path::CallPath; -use ruff_python_ast::source_code::Locator; -use ruff_python_ast::typing::parse_type_annotation; +use ruff_python_parser::typing::parse_type_annotation; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::sys::is_known_standard_library; +use ruff_source_file::Locator; /// Returns `true` if the given call path is a known type. /// @@ -115,7 +115,7 @@ impl<'a> TypingTarget<'a> { value: Constant::Str(string), range, .. - }) => parse_type_annotation(string, *range, locator) + }) => parse_type_annotation(string, *range, locator.contents()) .map_or(None, |(expr, _)| Some(TypingTarget::ForwardReference(expr))), _ => semantic.resolve_call_path(expr).map_or( // If we can't resolve the call path, it must be defined in the diff --git a/crates/ruff/src/rules/tryceratops/helpers.rs b/crates/ruff/src/rules/tryceratops/helpers.rs index c103922a1a..ccb5c12fea 100644 --- a/crates/ruff/src/rules/tryceratops/helpers.rs +++ b/crates/ruff/src/rules/tryceratops/helpers.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; diff --git a/crates/ruff/src/rules/tryceratops/rules/error_instead_of_exception.rs b/crates/ruff/src/rules/tryceratops/rules/error_instead_of_exception.rs index d0a5fd8795..4a9a8cf596 100644 --- a/crates/ruff/src/rules/tryceratops/rules/error_instead_of_exception.rs +++ b/crates/ruff/src/rules/tryceratops/rules/error_instead_of_exception.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_args.rs b/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_args.rs index a4ff800789..2ffabd29ee 100644 --- a/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_args.rs +++ b/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_args.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Constant, Expr, Ranged}; +use rustpython_ast::{self as ast, Constant, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_class.rs b/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_class.rs index e12cce062f..cfe59539af 100644 --- a/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_class.rs +++ b/crates/ruff/src/rules/tryceratops/rules/raise_vanilla_class.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_ast::{self as ast, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/raise_within_try.rs b/crates/ruff/src/rules/tryceratops/rules/raise_within_try.rs index 90baf84a06..227a23a655 100644 --- a/crates/ruff/src/rules/tryceratops/rules/raise_within_try.rs +++ b/crates/ruff/src/rules/tryceratops/rules/raise_within_try.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/reraise_no_cause.rs b/crates/ruff/src/rules/tryceratops/rules/reraise_no_cause.rs index 8cdcef2a1f..d88a2b28f7 100644 --- a/crates/ruff/src/rules/tryceratops/rules/reraise_no_cause.rs +++ b/crates/ruff/src/rules/tryceratops/rules/reraise_no_cause.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, Stmt}; +use rustpython_ast::{Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/try_consider_else.rs b/crates/ruff/src/rules/tryceratops/rules/try_consider_else.rs index 0ed6b3b27c..75e6eb9d94 100644 --- a/crates/ruff/src/rules/tryceratops/rules/try_consider_else.rs +++ b/crates/ruff/src/rules/tryceratops/rules/try_consider_else.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/type_check_without_type_error.rs b/crates/ruff/src/rules/tryceratops/rules/type_check_without_type_error.rs index a38078120d..599f5d788d 100644 --- a/crates/ruff/src/rules/tryceratops/rules/type_check_without_type_error.rs +++ b/crates/ruff/src/rules/tryceratops/rules/type_check_without_type_error.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; -use rustpython_parser::ast::{self, Expr, Ranged, Stmt, StmtIf}; +use rustpython_ast::{self as ast, Expr, Ranged, Stmt, StmtIf}; use crate::checkers::ast::Checker; diff --git a/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs b/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs index f256ff0f91..fd157ad052 100644 --- a/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs +++ b/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, ExceptHandlerExceptHandler, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, ExceptHandlerExceptHandler, Expr, Ranged, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/verbose_log_message.rs b/crates/ruff/src/rules/tryceratops/rules/verbose_log_message.rs index 5dfedad5e3..93cffc4b93 100644 --- a/crates/ruff/src/rules/tryceratops/rules/verbose_log_message.rs +++ b/crates/ruff/src/rules/tryceratops/rules/verbose_log_message.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged}; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff/src/rules/tryceratops/rules/verbose_raise.rs index 0ffc668598..dba4718133 100644 --- a/crates/ruff/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff/src/rules/tryceratops/rules/verbose_raise.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, ExceptHandler, Expr, Ranged, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Expr, Ranged, Stmt}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; diff --git a/crates/ruff/src/test.rs b/crates/ruff/src/test.rs index 82814908db..64b4899680 100644 --- a/crates/ruff/src/test.rs +++ b/crates/ruff/src/test.rs @@ -6,12 +6,14 @@ use std::path::Path; #[cfg(not(fuzzing))] use anyhow::Result; use itertools::Itertools; -use ruff_textwrap::dedent; use rustc_hash::FxHashMap; use rustpython_parser::lexer::LexResult; use ruff_diagnostics::{AutofixKind, Diagnostic}; -use ruff_python_ast::source_code::{Indexer, Locator, SourceFileBuilder, Stylist}; +use ruff_python_codegen::Stylist; +use ruff_python_index::Indexer; +use ruff_python_trivia::textwrap::dedent; +use ruff_source_file::{Locator, SourceFileBuilder}; use crate::autofix::{fix_file, FixResult}; use crate::directives; @@ -98,7 +100,7 @@ pub(crate) fn max_iterations() -> usize { /// asserts that autofixes converge after a fixed number of iterations. fn test_contents(source_kind: &mut SourceKind, path: &Path, settings: &Settings) -> Vec { let contents = source_kind.content().to_string(); - let tokens: Vec = ruff_rustpython::tokenize(&contents); + let tokens: Vec = ruff_python_parser::tokenize(&contents); let locator = Locator::new(&contents); let stylist = Stylist::from_tokens(&tokens, &locator); let indexer = Indexer::from_tokens(&tokens, &locator); @@ -160,7 +162,7 @@ fn test_contents(source_kind: &mut SourceKind, path: &Path, settings: &Settings) notebook.update(&source_map, &fixed_contents); }; - let tokens: Vec = ruff_rustpython::tokenize(&fixed_contents); + let tokens: Vec = ruff_python_parser::tokenize(&fixed_contents); let locator = Locator::new(&fixed_contents); let stylist = Stylist::from_tokens(&tokens, &locator); let indexer = Indexer::from_tokens(&tokens, &locator); diff --git a/crates/ruff_benchmark/Cargo.toml b/crates/ruff_benchmark/Cargo.toml index 56617c41d6..4b74f86daa 100644 --- a/crates/ruff_benchmark/Cargo.toml +++ b/crates/ruff_benchmark/Cargo.toml @@ -38,6 +38,7 @@ ruff.path = "../ruff" ruff_python_ast.path = "../ruff_python_ast" ruff_python_formatter = { path = "../ruff_python_formatter" } criterion = { version = "0.5.1"} +rustpython-ast = { workspace = true } rustpython-parser.workspace = true [target.'cfg(target_os = "windows")'.dev-dependencies] diff --git a/crates/ruff_benchmark/benches/parser.rs b/crates/ruff_benchmark/benches/parser.rs index e08836e685..958f9f0719 100644 --- a/crates/ruff_benchmark/benches/parser.rs +++ b/crates/ruff_benchmark/benches/parser.rs @@ -4,7 +4,7 @@ use criterion::measurement::WallTime; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; -use rustpython_parser::ast::{Stmt, Suite}; +use rustpython_ast::{Stmt, Suite}; use rustpython_parser::Parse; #[cfg(target_os = "windows")] diff --git a/crates/ruff_cli/Cargo.toml b/crates/ruff_cli/Cargo.toml index 983d02d85d..552db97b5a 100644 --- a/crates/ruff_cli/Cargo.toml +++ b/crates/ruff_cli/Cargo.toml @@ -26,11 +26,12 @@ doc = false ruff = { path = "../ruff", features = ["clap"] } ruff_cache = { path = "../ruff_cache" } ruff_diagnostics = { path = "../ruff_diagnostics" } +ruff_macros = { path = "../ruff_macros" } ruff_python_ast = { path = "../ruff_python_ast" } ruff_python_formatter = { path = "../ruff_python_formatter" } +ruff_source_file = { path = "../ruff_source_file" } +ruff_python_trivia = { path = "../ruff_python_trivia" } ruff_text_size = { workspace = true } -ruff_textwrap = { path = "../ruff_textwrap" } -ruff_macros = { path = "../ruff_macros" } annotate-snippets = { version = "0.9.1", features = ["color"] } anyhow = { workspace = true } diff --git a/crates/ruff_cli/src/cache.rs b/crates/ruff_cli/src/cache.rs index 59494361ba..908a70c709 100644 --- a/crates/ruff_cli/src/cache.rs +++ b/crates/ruff_cli/src/cache.rs @@ -16,7 +16,7 @@ use ruff::warn_user; use ruff_cache::{CacheKey, CacheKeyHasher}; use ruff_diagnostics::{DiagnosticKind, Fix}; use ruff_python_ast::imports::ImportMap; -use ruff_python_ast::source_code::SourceFileBuilder; +use ruff_source_file::SourceFileBuilder; use ruff_text_size::{TextRange, TextSize}; use crate::diagnostics::Diagnostics; diff --git a/crates/ruff_cli/src/commands/run.rs b/crates/ruff_cli/src/commands/run.rs index fba477192d..006dadd774 100644 --- a/crates/ruff_cli/src/commands/run.rs +++ b/crates/ruff_cli/src/commands/run.rs @@ -20,7 +20,7 @@ use ruff::settings::{flags, AllSettings}; use ruff::{fs, packaging, resolver, warn_user_once, IOError}; use ruff_diagnostics::Diagnostic; use ruff_python_ast::imports::ImportMap; -use ruff_python_ast::source_code::SourceFileBuilder; +use ruff_source_file::SourceFileBuilder; use crate::args::Overrides; use crate::cache::{self, Cache}; diff --git a/crates/ruff_cli/src/diagnostics.rs b/crates/ruff_cli/src/diagnostics.rs index 29da5529b2..5e494a0482 100644 --- a/crates/ruff_cli/src/diagnostics.rs +++ b/crates/ruff_cli/src/diagnostics.rs @@ -29,8 +29,8 @@ use ruff::{fs, IOError}; use ruff_diagnostics::Diagnostic; use ruff_macros::CacheKey; use ruff_python_ast::imports::ImportMap; -use ruff_python_ast::source_code::{LineIndex, SourceCode, SourceFileBuilder}; use ruff_python_stdlib::path::{is_jupyter_notebook, is_project_toml}; +use ruff_source_file::{LineIndex, SourceCode, SourceFileBuilder}; #[derive(CacheKey)] pub(crate) struct FileCacheKey { diff --git a/crates/ruff_dev/Cargo.toml b/crates/ruff_dev/Cargo.toml index f356a44b61..9900cc9428 100644 --- a/crates/ruff_dev/Cargo.toml +++ b/crates/ruff_dev/Cargo.toml @@ -15,9 +15,10 @@ ruff = { path = "../ruff", features = ["schemars"] } ruff_cli = { path = "../ruff_cli" } ruff_diagnostics = { path = "../ruff_diagnostics" } ruff_formatter = { path = "../ruff_formatter" } +ruff_python_codegen = { path = "../ruff_python_codegen" } ruff_python_formatter = { path = "../ruff_python_formatter" } ruff_python_stdlib = { path = "../ruff_python_stdlib" } -ruff_textwrap = { path = "../ruff_textwrap" } +ruff_python_trivia = { path = "../ruff_python_trivia" } anyhow = { workspace = true } clap = { workspace = true } @@ -30,6 +31,7 @@ once_cell = { workspace = true } pretty_assertions = { version = "1.3.0" } rayon = "1.7.0" regex = { workspace = true } +rustpython-ast = { workspace = true } rustpython-format = { workspace = true } rustpython-parser = { workspace = true } schemars = { workspace = true } diff --git a/crates/ruff_dev/src/print_ast.rs b/crates/ruff_dev/src/print_ast.rs index d19f07a373..130f9b5bd0 100644 --- a/crates/ruff_dev/src/print_ast.rs +++ b/crates/ruff_dev/src/print_ast.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::PathBuf; use anyhow::Result; -use rustpython_parser::ast::Suite; +use rustpython_ast::Suite; use rustpython_parser::Parse; #[derive(clap::Args)] diff --git a/crates/ruff_dev/src/round_trip.rs b/crates/ruff_dev/src/round_trip.rs index 394ec4b190..a85d57e8cb 100644 --- a/crates/ruff_dev/src/round_trip.rs +++ b/crates/ruff_dev/src/round_trip.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use anyhow::Result; use ruff::jupyter; -use ruff::round_trip; +use ruff_python_codegen::round_trip; use ruff_python_stdlib::path::is_jupyter_notebook; #[derive(clap::Args)] diff --git a/crates/ruff_macros/Cargo.toml b/crates/ruff_macros/Cargo.toml index 6b48c144cd..2cd64bbe54 100644 --- a/crates/ruff_macros/Cargo.toml +++ b/crates/ruff_macros/Cargo.toml @@ -15,7 +15,7 @@ proc-macro = true doctest = false [dependencies] -ruff_textwrap = { path = "../ruff_textwrap" } +ruff_python_trivia = { path = "../ruff_python_trivia" } proc-macro2 = { workspace = true } quote = { workspace = true } diff --git a/crates/ruff_macros/src/config.rs b/crates/ruff_macros/src/config.rs index bfbfc8227e..35cf86e498 100644 --- a/crates/ruff_macros/src/config.rs +++ b/crates/ruff_macros/src/config.rs @@ -1,4 +1,4 @@ -use ruff_textwrap::dedent; +use ruff_python_trivia::textwrap::dedent; use quote::{quote, quote_spanned}; use syn::parse::{Parse, ParseStream}; diff --git a/crates/ruff_python_ast/Cargo.toml b/crates/ruff_python_ast/Cargo.toml index 110b198aea..89969a380e 100644 --- a/crates/ruff_python_ast/Cargo.toml +++ b/crates/ruff_python_ast/Cargo.toml @@ -14,25 +14,23 @@ license = { workspace = true } [dependencies] ruff_python_trivia = { path = "../ruff_python_trivia" } +ruff_source_file = { path = "../ruff_source_file" } ruff_text_size = { workspace = true } -anyhow = { workspace = true } bitflags = { workspace = true } is-macro = { workspace = true } -itertools = { workspace = true } memchr = { workspace = true } num-bigint = { workspace = true } num-traits = { workspace = true } once_cell = { workspace = true } rustc-hash = { workspace = true } -rustpython-literal = { workspace = true } -rustpython-parser = { workspace = true } rustpython-ast = { workspace = true } serde = { workspace = true, optional = true } smallvec = { workspace = true } [dev-dependencies] insta = { workspace = true } +rustpython-parser = { workspace = true } [features] serde = ["dep:serde", "ruff_text_size/serde"] diff --git a/crates/ruff_python_ast/src/all.rs b/crates/ruff_python_ast/src/all.rs index 9cfb0eef5b..2ee1324b65 100644 --- a/crates/ruff_python_ast/src/all.rs +++ b/crates/ruff_python_ast/src/all.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use rustpython_parser::ast::{self, Constant, Expr, Stmt}; +use rustpython_ast::{self as ast, Constant, Expr, Stmt}; bitflags! { #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_python_ast/src/call_path.rs b/crates/ruff_python_ast/src/call_path.rs index 829ba901bc..7d0a12bebe 100644 --- a/crates/ruff_python_ast/src/call_path.rs +++ b/crates/ruff_python_ast/src/call_path.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr}; +use rustpython_ast::{self as ast, Expr}; use smallvec::{smallvec, SmallVec}; /// A representation of a qualified name, like `typing.List`. diff --git a/crates/ruff_python_ast/src/cast.rs b/crates/ruff_python_ast/src/cast.rs index 98889d6673..bd55f1bfb8 100644 --- a/crates/ruff_python_ast/src/cast.rs +++ b/crates/ruff_python_ast/src/cast.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Decorator, Stmt}; +use rustpython_ast::{self as ast, Decorator, Stmt}; pub fn name(stmt: &Stmt) -> &str { match stmt { diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index 2825347f0d..5bea363d7e 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -2,7 +2,7 @@ //! ability to compare expressions for equality (via [`Eq`] and [`Hash`]). use num_bigint::BigInt; -use rustpython_parser::ast; +use rustpython_ast as ast; #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] pub enum ComparableExprContext { diff --git a/crates/ruff_python_ast/src/hashable.rs b/crates/ruff_python_ast/src/hashable.rs index b20f0efb67..0890eed133 100644 --- a/crates/ruff_python_ast/src/hashable.rs +++ b/crates/ruff_python_ast/src/hashable.rs @@ -1,6 +1,6 @@ use std::hash::Hash; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use crate::comparable::ComparableExpr; diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index b51bc23fc0..f09b46fdbb 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -1,21 +1,15 @@ use std::borrow::Cow; -use std::ops::Sub; use std::path::Path; use num_traits::Zero; -use ruff_text_size::{TextRange, TextSize}; -use rustpython_ast::CmpOp; -use rustpython_parser::ast::{ - self, Arguments, Constant, ExceptHandler, Expr, Keyword, MatchCase, Pattern, Ranged, Stmt, - TypeParam, +use ruff_text_size::TextRange; +use rustpython_ast::{ + self as ast, Arguments, Constant, ExceptHandler, Expr, Keyword, MatchCase, Pattern, Ranged, + Stmt, TypeParam, }; -use rustpython_parser::{lexer, Mode, Tok}; use smallvec::SmallVec; -use ruff_python_trivia::{is_python_whitespace, PythonWhitespace, UniversalNewlineIterator}; - use crate::call_path::CallPath; -use crate::source_code::{Indexer, Locator}; use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor}; /// Return `true` if the `Stmt` is a compound statement (as opposed to a simple statement). @@ -772,27 +766,6 @@ pub fn map_subscript(expr: &Expr) -> &Expr { } } -/// Returns `true` if a statement or expression includes at least one comment. -pub fn has_comments(node: &T, locator: &Locator, indexer: &Indexer) -> bool -where - T: Ranged, -{ - let start = if has_leading_content(node.start(), locator) { - node.start() - } else { - locator.line_start(node.start()) - }; - let end = if has_trailing_content(node.end(), locator) { - node.end() - } else { - locator.line_end(node.end()) - }; - - indexer - .comment_ranges() - .intersects(TextRange::new(start, end)) -} - /// Return `true` if the body uses `locals()`, `globals()`, `vars()`, `eval()`. /// /// Accepts a closure that determines whether a given name (e.g., `"list"`) is a Python builtin. @@ -1027,197 +1000,6 @@ where } } -/// Return `true` if the node starting the given [`TextSize`] has leading content. -pub fn has_leading_content(offset: TextSize, locator: &Locator) -> bool { - let line_start = locator.line_start(offset); - let leading = &locator.contents()[TextRange::new(line_start, offset)]; - leading.chars().any(|char| !is_python_whitespace(char)) -} - -/// Return `true` if the node ending at the given [`TextSize`] has trailing content. -pub fn has_trailing_content(offset: TextSize, locator: &Locator) -> bool { - let line_end = locator.line_end(offset); - let trailing = &locator.contents()[TextRange::new(offset, line_end)]; - - for char in trailing.chars() { - if char == '#' { - return false; - } - if !is_python_whitespace(char) { - return true; - } - } - false -} - -/// If a [`Ranged`] has a trailing comment, return the index of the hash. -pub fn trailing_comment_start_offset(located: &T, locator: &Locator) -> Option -where - T: Ranged, -{ - let line_end = locator.line_end(located.end()); - - let trailing = &locator.contents()[TextRange::new(located.end(), line_end)]; - - for (index, char) in trailing.char_indices() { - if char == '#' { - return TextSize::try_from(index).ok(); - } - if !is_python_whitespace(char) { - return None; - } - } - - None -} - -/// Return the end offset at which the empty lines following a statement. -pub fn trailing_lines_end(stmt: &Stmt, locator: &Locator) -> TextSize { - let line_end = locator.full_line_end(stmt.end()); - let rest = &locator.contents()[usize::from(line_end)..]; - - UniversalNewlineIterator::with_offset(rest, line_end) - .take_while(|line| line.trim_whitespace().is_empty()) - .last() - .map_or(line_end, |line| line.full_end()) -} - -/// Return the range of the first parenthesis pair after a given [`TextSize`]. -pub fn match_parens(start: TextSize, locator: &Locator) -> Option { - let contents = &locator.contents()[usize::from(start)..]; - - let mut fix_start = None; - let mut fix_end = None; - let mut count = 0u32; - - for (tok, range) in lexer::lex_starts_at(contents, Mode::Module, start).flatten() { - match tok { - Tok::Lpar => { - if count == 0 { - fix_start = Some(range.start()); - } - count = count.saturating_add(1); - } - Tok::Rpar => { - count = count.saturating_sub(1); - if count == 0 { - fix_end = Some(range.end()); - break; - } - } - _ => {} - } - } - - match (fix_start, fix_end) { - (Some(start), Some(end)) => Some(TextRange::new(start, end)), - _ => None, - } -} - -/// Return the `Range` of the first `Tok::Colon` token in a `Range`. -pub fn first_colon_range(range: TextRange, locator: &Locator) -> Option { - let contents = &locator.contents()[range]; - let range = lexer::lex_starts_at(contents, Mode::Module, range.start()) - .flatten() - .find(|(tok, _)| tok.is_colon()) - .map(|(_, range)| range); - range -} - -/// Given an offset at the end of a line (including newlines), return the offset of the -/// continuation at the end of that line. -fn find_continuation(offset: TextSize, locator: &Locator, indexer: &Indexer) -> Option { - let newline_pos = usize::from(offset).saturating_sub(1); - - // Skip the newline. - let newline_len = match locator.contents().as_bytes()[newline_pos] { - b'\n' => { - if locator - .contents() - .as_bytes() - .get(newline_pos.saturating_sub(1)) - == Some(&b'\r') - { - 2 - } else { - 1 - } - } - b'\r' => 1, - // No preceding line. - _ => return None, - }; - - indexer - .is_continuation(offset - TextSize::from(newline_len), locator) - .then(|| offset - TextSize::from(newline_len) - TextSize::from(1)) -} - -/// If the node starting at the given [`TextSize`] is preceded by at least one continuation line -/// (i.e., a line ending in a backslash), return the starting offset of the first such continuation -/// character. -/// -/// For example, given: -/// ```python -/// x = 1; \ -/// y = 2 -/// ``` -/// -/// When passed the offset of `y`, this function will return the offset of the backslash at the end -/// of the first line. -/// -/// Similarly, given: -/// ```python -/// x = 1; \ -/// \ -/// y = 2; -/// ``` -/// -/// When passed the offset of `y`, this function will again return the offset of the backslash at -/// the end of the first line. -pub fn preceded_by_continuations( - offset: TextSize, - locator: &Locator, - indexer: &Indexer, -) -> Option { - // Find the first preceding continuation. - let mut continuation = find_continuation(locator.line_start(offset), locator, indexer)?; - - // Continue searching for continuations, in the unlikely event that we have multiple - // continuations in a row. - loop { - let previous_line_end = locator.line_start(continuation); - if locator - .slice(TextRange::new(previous_line_end, continuation)) - .chars() - .all(is_python_whitespace) - { - if let Some(next_continuation) = find_continuation(previous_line_end, locator, indexer) - { - continuation = next_continuation; - continue; - } - } - break; - } - - Some(continuation) -} - -/// Return `true` if a `Stmt` appears to be part of a multi-statement line, with -/// other statements preceding it. -pub fn preceded_by_multi_statement_line(stmt: &Stmt, locator: &Locator, indexer: &Indexer) -> bool { - has_leading_content(stmt.start(), locator) - || preceded_by_continuations(stmt.start(), locator, indexer).is_some() -} - -/// Return `true` if a `Stmt` appears to be part of a multi-statement line, with -/// other statements following it. -pub fn followed_by_multi_statement_line(stmt: &Stmt, locator: &Locator) -> bool { - has_trailing_content(stmt.end(), locator) -} - /// Return `true` if a `Stmt` is a docstring. pub fn is_docstring_stmt(stmt: &Stmt) -> bool { if let Stmt::Expr(ast::StmtExpr { @@ -1500,166 +1282,19 @@ impl Truthiness { } } -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct LocatedCmpOp { - pub range: TextRange, - pub op: CmpOp, -} - -impl LocatedCmpOp { - fn new>(range: T, op: CmpOp) -> Self { - Self { - range: range.into(), - op, - } - } -} - -/// Extract all [`CmpOp`] operators from an expression snippet, with appropriate -/// ranges. -/// -/// `RustPython` doesn't include line and column information on [`CmpOp`] nodes. -/// `CPython` doesn't either. This method iterates over the token stream and -/// re-identifies [`CmpOp`] nodes, annotating them with valid ranges. -pub fn locate_cmp_ops(expr: &Expr, locator: &Locator) -> Vec { - // If `Expr` is a multi-line expression, we need to parenthesize it to - // ensure that it's lexed correctly. - let contents = locator.slice(expr.range()); - let parenthesized_contents = format!("({contents})"); - let mut tok_iter = lexer::lex(&parenthesized_contents, Mode::Expression) - .flatten() - .skip(1) - .map(|(tok, range)| (tok, range.sub(TextSize::from(1)))) - .filter(|(tok, _)| !matches!(tok, Tok::NonLogicalNewline | Tok::Comment(_))) - .peekable(); - - let mut ops: Vec = vec![]; - let mut count = 0u32; - loop { - let Some((tok, range)) = tok_iter.next() else { - break; - }; - if matches!(tok, Tok::Lpar) { - count = count.saturating_add(1); - continue; - } else if matches!(tok, Tok::Rpar) { - count = count.saturating_sub(1); - continue; - } - if count == 0 { - match tok { - Tok::Not => { - if let Some((_, next_range)) = - tok_iter.next_if(|(tok, _)| matches!(tok, Tok::In)) - { - ops.push(LocatedCmpOp::new( - TextRange::new(range.start(), next_range.end()), - CmpOp::NotIn, - )); - } - } - Tok::In => { - ops.push(LocatedCmpOp::new(range, CmpOp::In)); - } - Tok::Is => { - let op = if let Some((_, next_range)) = - tok_iter.next_if(|(tok, _)| matches!(tok, Tok::Not)) - { - LocatedCmpOp::new( - TextRange::new(range.start(), next_range.end()), - CmpOp::IsNot, - ) - } else { - LocatedCmpOp::new(range, CmpOp::Is) - }; - ops.push(op); - } - Tok::NotEqual => { - ops.push(LocatedCmpOp::new(range, CmpOp::NotEq)); - } - Tok::EqEqual => { - ops.push(LocatedCmpOp::new(range, CmpOp::Eq)); - } - Tok::GreaterEqual => { - ops.push(LocatedCmpOp::new(range, CmpOp::GtE)); - } - Tok::Greater => { - ops.push(LocatedCmpOp::new(range, CmpOp::Gt)); - } - Tok::LessEqual => { - ops.push(LocatedCmpOp::new(range, CmpOp::LtE)); - } - Tok::Less => { - ops.push(LocatedCmpOp::new(range, CmpOp::Lt)); - } - _ => {} - } - } - } - ops -} - #[cfg(test)] mod tests { use std::borrow::Cow; - use std::cell::RefCell; - use std::vec; - use anyhow::Result; - use ruff_text_size::{TextLen, TextRange, TextSize}; + use ruff_text_size::TextRange; use rustpython_ast::{ - self, CmpOp, Constant, Expr, ExprConstant, ExprContext, ExprName, Identifier, Ranged, Stmt, - StmtTypeAlias, TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, + self, Constant, Expr, ExprConstant, ExprContext, ExprName, Identifier, Stmt, StmtTypeAlias, + TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, }; - use rustpython_parser::ast::Suite; - use rustpython_parser::Parse; - use crate::helpers::{ - any_over_stmt, any_over_type_param, first_colon_range, has_trailing_content, - locate_cmp_ops, resolve_imported_module_path, LocatedCmpOp, - }; - use crate::source_code::Locator; - - #[test] - fn trailing_content() -> Result<()> { - let contents = "x = 1"; - let program = Suite::parse(contents, "")?; - let stmt = program.first().unwrap(); - let locator = Locator::new(contents); - assert!(!has_trailing_content(stmt.end(), &locator)); - - let contents = "x = 1; y = 2"; - let program = Suite::parse(contents, "")?; - let stmt = program.first().unwrap(); - let locator = Locator::new(contents); - assert!(has_trailing_content(stmt.end(), &locator)); - - let contents = "x = 1 "; - let program = Suite::parse(contents, "")?; - let stmt = program.first().unwrap(); - let locator = Locator::new(contents); - assert!(!has_trailing_content(stmt.end(), &locator)); - - let contents = "x = 1 # Comment"; - let program = Suite::parse(contents, "")?; - let stmt = program.first().unwrap(); - let locator = Locator::new(contents); - assert!(!has_trailing_content(stmt.end(), &locator)); - - let contents = r#" -x = 1 -y = 2 -"# - .trim(); - let program = Suite::parse(contents, "")?; - let stmt = program.first().unwrap(); - let locator = Locator::new(contents); - assert!(!has_trailing_content(stmt.end(), &locator)); - - Ok(()) - } + use crate::helpers::{any_over_stmt, any_over_type_param, resolve_imported_module_path}; #[test] fn resolve_import() { @@ -1698,101 +1333,6 @@ y = 2 ); } - #[test] - fn extract_first_colon_range() { - let contents = "with a: pass"; - let locator = Locator::new(contents); - let range = first_colon_range( - TextRange::new(TextSize::from(0), contents.text_len()), - &locator, - ) - .unwrap(); - assert_eq!(&contents[range], ":"); - assert_eq!(range, TextRange::new(TextSize::from(6), TextSize::from(7))); - } - - #[test] - fn extract_cmp_op_location() -> Result<()> { - let contents = "x == 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(4), - CmpOp::Eq - )] - ); - - let contents = "x != 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(4), - CmpOp::NotEq - )] - ); - - let contents = "x is 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(4), - CmpOp::Is - )] - ); - - let contents = "x is not 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(8), - CmpOp::IsNot - )] - ); - - let contents = "x in 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(4), - CmpOp::In - )] - ); - - let contents = "x not in 1"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(8), - CmpOp::NotIn - )] - ); - - let contents = "x != (1 is not 2)"; - let expr = Expr::parse(contents, "")?; - let locator = Locator::new(contents); - assert_eq!( - locate_cmp_ops(&expr, &locator), - vec![LocatedCmpOp::new( - TextSize::from(2)..TextSize::from(4), - CmpOp::NotEq - )] - ); - - Ok(()) - } - #[test] fn any_over_stmt_type_alias() { let seen = RefCell::new(Vec::new()); diff --git a/crates/ruff_python_ast/src/identifier.rs b/crates/ruff_python_ast/src/identifier.rs index 981602d73b..13219cbbf0 100644 --- a/crates/ruff_python_ast/src/identifier.rs +++ b/crates/ruff_python_ast/src/identifier.rs @@ -11,13 +11,10 @@ //! This module can be used to identify the [`TextRange`] of the `except` token. use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_ast::{Alias, Arg, ArgWithDefault}; -use rustpython_parser::ast::{self, ExceptHandler, Ranged, Stmt}; +use rustpython_ast::{self as ast, Alias, Arg, ArgWithDefault, ExceptHandler, Ranged, Stmt}; use ruff_python_trivia::{is_python_whitespace, Cursor}; -use crate::source_code::Locator; - pub trait Identifier { /// Return the [`TextRange`] of the identifier in the given AST node. fn identifier(&self) -> TextRange; @@ -82,14 +79,14 @@ impl Identifier for Alias { } /// Return the [`TextRange`] of the `except` token in an [`ExceptHandler`]. -pub fn except(handler: &ExceptHandler, locator: &Locator) -> TextRange { - IdentifierTokenizer::new(locator.contents(), handler.range()) +pub fn except(handler: &ExceptHandler, source: &str) -> TextRange { + IdentifierTokenizer::new(source, handler.range()) .next() .expect("Failed to find `except` token in `ExceptHandler`") } /// Return the [`TextRange`] of the `else` token in a `For`, `AsyncFor`, or `While` statement. -pub fn else_(stmt: &Stmt, locator: &Locator) -> Option { +pub fn else_(stmt: &Stmt, source: &str) -> Option { let (Stmt::For(ast::StmtFor { body, orelse, .. }) | Stmt::AsyncFor(ast::StmtAsyncFor { body, orelse, .. }) | Stmt::While(ast::StmtWhile { body, orelse, .. })) = stmt @@ -103,7 +100,7 @@ pub fn else_(stmt: &Stmt, locator: &Locator) -> Option { IdentifierTokenizer::starts_at( body.last().expect("Expected body to be non-empty").end(), - locator.contents(), + source, ) .next() } @@ -203,17 +200,15 @@ impl Iterator for IdentifierTokenizer<'_> { #[cfg(test)] mod tests { - use anyhow::Result; use ruff_text_size::{TextRange, TextSize}; use rustpython_ast::{Ranged, Stmt}; - use rustpython_parser::Parse; + use rustpython_parser::{Parse, ParseError}; use crate::identifier; use crate::identifier::IdentifierTokenizer; - use crate::source_code::Locator; #[test] - fn extract_else_range() -> Result<()> { + fn extract_else_range() -> Result<(), ParseError> { let contents = r#" for x in y: pass @@ -222,8 +217,7 @@ else: "# .trim(); let stmt = Stmt::parse(contents, "")?; - let locator = Locator::new(contents); - let range = identifier::else_(&stmt, &locator).unwrap(); + let range = identifier::else_(&stmt, contents).unwrap(); assert_eq!(&contents[range], "else"); assert_eq!( range, @@ -233,12 +227,11 @@ else: } #[test] - fn extract_global_names() -> Result<()> { + fn extract_global_names() -> Result<(), ParseError> { let contents = r#"global X,Y, Z"#.trim(); let stmt = Stmt::parse(contents, "")?; - let locator = Locator::new(contents); - let mut names = IdentifierTokenizer::new(locator.contents(), stmt.range()); + let mut names = IdentifierTokenizer::new(contents, stmt.range()); let range = names.next_token().unwrap(); assert_eq!(&contents[range], "global"); diff --git a/crates/ruff_python_ast/src/lib.rs b/crates/ruff_python_ast/src/lib.rs index 71c17096e4..098879d88d 100644 --- a/crates/ruff_python_ast/src/lib.rs +++ b/crates/ruff_python_ast/src/lib.rs @@ -10,13 +10,10 @@ pub mod identifier; pub mod imports; pub mod node; pub mod relocate; -pub mod source_code; pub mod statement_visitor; pub mod stmt_if; pub mod str; -pub mod token_kind; pub mod traversal; pub mod types; -pub mod typing; pub mod visitor; pub mod whitespace; diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index ed1ab59a9e..326d88eade 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -1,10 +1,9 @@ -use ast::{TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple}; use ruff_text_size::TextRange; use rustpython_ast::{ - Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ExceptHandler, Keyword, - MatchCase, Mod, Pattern, Stmt, TypeIgnore, WithItem, + self as ast, Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ExceptHandler, + Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeIgnore, TypeParam, + TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, WithItem, }; -use rustpython_parser::ast::{self, Expr, Ranged}; use std::ptr::NonNull; pub trait AstNode: Ranged { diff --git a/crates/ruff_python_ast/src/relocate.rs b/crates/ruff_python_ast/src/relocate.rs index 4d16c4d8ba..52fa1fed85 100644 --- a/crates/ruff_python_ast/src/relocate.rs +++ b/crates/ruff_python_ast/src/relocate.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Expr, Keyword}; +use rustpython_ast::{self as ast, Expr, Keyword}; fn relocate_keyword(keyword: &mut Keyword, location: TextRange) { relocate_expr(&mut keyword.value, location); diff --git a/crates/ruff_python_ast/src/statement_visitor.rs b/crates/ruff_python_ast/src/statement_visitor.rs index bda9fa8f64..11cf6f72ab 100644 --- a/crates/ruff_python_ast/src/statement_visitor.rs +++ b/crates/ruff_python_ast/src/statement_visitor.rs @@ -1,7 +1,6 @@ //! Specialized AST visitor trait and walk functions that only visit statements. -use rustpython_ast::ElifElseClause; -use rustpython_parser::ast::{self, ExceptHandler, MatchCase, Stmt}; +use rustpython_ast::{self as ast, ElifElseClause, ExceptHandler, MatchCase, Stmt}; /// A trait for AST visitors that only need to visit statements. pub trait StatementVisitor<'a> { diff --git a/crates/ruff_python_ast/src/stmt_if.rs b/crates/ruff_python_ast/src/stmt_if.rs index 1ad617e1d8..4c44affebd 100644 --- a/crates/ruff_python_ast/src/stmt_if.rs +++ b/crates/ruff_python_ast/src/stmt_if.rs @@ -1,20 +1,14 @@ -use crate::source_code::Locator; +use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::TextRange; use rustpython_ast::{ElifElseClause, Expr, Ranged, Stmt, StmtIf}; -use rustpython_parser::{lexer, Mode, Tok}; use std::iter; /// Return the `Range` of the first `Elif` or `Else` token in an `If` statement. -pub fn elif_else_range(clause: &ElifElseClause, locator: &Locator) -> Option { - let contents = &locator.contents()[clause.range]; - let token = lexer::lex_starts_at(contents, Mode::Module, clause.range.start()) - .flatten() +pub fn elif_else_range(clause: &ElifElseClause, contents: &str) -> Option { + let token = SimpleTokenizer::new(contents, clause.range) + .skip_trivia() .next()?; - if matches!(token.0, Tok::Elif | Tok::Else) { - Some(token.1) - } else { - None - } + matches!(token.kind, SimpleTokenKind::Elif | SimpleTokenKind::Else).then_some(token.range()) } #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -49,15 +43,13 @@ pub fn if_elif_branches(stmt_if: &StmtIf) -> impl Iterator #[cfg(test)] mod test { - use crate::source_code::Locator; use crate::stmt_if::elif_else_range; - use anyhow::Result; use ruff_text_size::TextSize; use rustpython_ast::Stmt; - use rustpython_parser::Parse; + use rustpython_parser::{Parse, ParseError}; #[test] - fn extract_elif_else_range() -> Result<()> { + fn extract_elif_else_range() -> Result<(), ParseError> { let contents = "if a: ... elif b: @@ -65,8 +57,7 @@ elif b: "; let stmt = Stmt::parse(contents, "")?; let stmt = Stmt::as_if_stmt(&stmt).unwrap(); - let locator = Locator::new(contents); - let range = elif_else_range(&stmt.elif_else_clauses[0], &locator).unwrap(); + let range = elif_else_range(&stmt.elif_else_clauses[0], contents).unwrap(); assert_eq!(range.start(), TextSize::from(14)); assert_eq!(range.end(), TextSize::from(18)); @@ -77,8 +68,7 @@ else: "; let stmt = Stmt::parse(contents, "")?; let stmt = Stmt::as_if_stmt(&stmt).unwrap(); - let locator = Locator::new(contents); - let range = elif_else_range(&stmt.elif_else_clauses[0], &locator).unwrap(); + let range = elif_else_range(&stmt.elif_else_clauses[0], contents).unwrap(); assert_eq!(range.start(), TextSize::from(14)); assert_eq!(range.end(), TextSize::from(18)); diff --git a/crates/ruff_python_ast/src/traversal.rs b/crates/ruff_python_ast/src/traversal.rs index 4e0f1108a5..fe2898e5a6 100644 --- a/crates/ruff_python_ast/src/traversal.rs +++ b/crates/ruff_python_ast/src/traversal.rs @@ -1,6 +1,5 @@ //! Utilities for manually traversing a Python AST. -use rustpython_ast::{ExceptHandler, Stmt, Suite}; -use rustpython_parser::ast; +use rustpython_ast::{self as ast, ExceptHandler, Stmt, Suite}; /// Given a [`Stmt`] and its parent, return the [`Suite`] that contains the [`Stmt`]. pub fn suite<'a>(stmt: &'a Stmt, parent: &'a Stmt) -> Option<&'a Suite> { diff --git a/crates/ruff_python_ast/src/types.rs b/crates/ruff_python_ast/src/types.rs index baa2839e1f..c7f701ab8d 100644 --- a/crates/ruff_python_ast/src/types.rs +++ b/crates/ruff_python_ast/src/types.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use rustpython_parser::ast::{Expr, Stmt}; +use rustpython_ast::{Expr, Stmt}; #[derive(Clone)] pub enum Node<'a> { diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index ee05bab054..ceedaf1622 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -2,11 +2,10 @@ pub mod preorder; -use rustpython_ast::ElifElseClause; -use rustpython_parser::ast::{ - self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Decorator, ExceptHandler, Expr, - ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, TypeParam, TypeParamTypeVar, UnaryOp, - WithItem, +use rustpython_ast::{ + self as ast, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Decorator, ElifElseClause, + ExceptHandler, Expr, ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, TypeParam, + TypeParamTypeVar, UnaryOp, WithItem, }; /// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order. @@ -803,8 +802,9 @@ mod tests { use std::fmt::{Debug, Write}; use insta::assert_snapshot; + use rustpython_ast as ast; use rustpython_parser::lexer::lex; - use rustpython_parser::{ast, parse_tokens, Mode}; + use rustpython_parser::{parse_tokens, Mode}; use crate::node::AnyNodeRef; use crate::visitor::{ diff --git a/crates/ruff_python_ast/src/visitor/preorder.rs b/crates/ruff_python_ast/src/visitor/preorder.rs index c4d277dbf2..4b022b5275 100644 --- a/crates/ruff_python_ast/src/visitor/preorder.rs +++ b/crates/ruff_python_ast/src/visitor/preorder.rs @@ -1,8 +1,7 @@ -use rustpython_ast::{ArgWithDefault, ElifElseClause, Mod, TypeIgnore}; -use rustpython_parser::ast::{ - self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ExceptHandler, - Expr, Keyword, MatchCase, Operator, Pattern, Stmt, TypeParam, TypeParamTypeVar, UnaryOp, - WithItem, +use rustpython_ast::{ + self as ast, Alias, Arg, ArgWithDefault, Arguments, BoolOp, CmpOp, Comprehension, Constant, + Decorator, ElifElseClause, ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Pattern, + Stmt, TypeIgnore, TypeParam, TypeParamTypeVar, UnaryOp, WithItem, }; /// Visitor that traverses all nodes recursively in pre-order. diff --git a/crates/ruff_python_ast/src/whitespace.rs b/crates/ruff_python_ast/src/whitespace.rs index e9bf9a50ab..146462b175 100644 --- a/crates/ruff_python_ast/src/whitespace.rs +++ b/crates/ruff_python_ast/src/whitespace.rs @@ -1,9 +1,10 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::{Ranged, Stmt}; -use ruff_python_trivia::is_python_whitespace; - -use crate::source_code::Locator; +use ruff_python_trivia::{ + has_trailing_content, indentation_at_offset, is_python_whitespace, PythonWhitespace, +}; +use ruff_source_file::{newlines::UniversalNewlineIterator, Locator}; /// Extract the leading indentation from a line. #[inline] @@ -14,14 +15,40 @@ where indentation_at_offset(locator, located.start()) } -/// Extract the leading indentation from a line. -pub fn indentation_at_offset<'a>(locator: &'a Locator, offset: TextSize) -> Option<&'a str> { - let line_start = locator.line_start(offset); - let indentation = &locator.contents()[TextRange::new(line_start, offset)]; +/// Return the end offset at which the empty lines following a statement. +pub fn trailing_lines_end(stmt: &Stmt, locator: &Locator) -> TextSize { + let line_end = locator.full_line_end(stmt.end()); + let rest = &locator.contents()[usize::from(line_end)..]; - if indentation.chars().all(is_python_whitespace) { - Some(indentation) - } else { - None - } + UniversalNewlineIterator::with_offset(rest, line_end) + .take_while(|line| line.trim_whitespace().is_empty()) + .last() + .map_or(line_end, |line| line.full_end()) +} + +/// Return `true` if a `Stmt` appears to be part of a multi-statement line, with +/// other statements following it. +pub fn followed_by_multi_statement_line(stmt: &Stmt, locator: &Locator) -> bool { + has_trailing_content(stmt.end(), locator) +} + +/// If a [`Ranged`] has a trailing comment, return the index of the hash. +pub fn trailing_comment_start_offset(located: &T, locator: &Locator) -> Option +where + T: Ranged, +{ + let line_end = locator.line_end(located.end()); + + let trailing = &locator.contents()[TextRange::new(located.end(), line_end)]; + + for (index, char) in trailing.char_indices() { + if char == '#' { + return TextSize::try_from(index).ok(); + } + if !is_python_whitespace(char) { + return None; + } + } + + None } diff --git a/crates/ruff_python_codegen/Cargo.toml b/crates/ruff_python_codegen/Cargo.toml new file mode 100644 index 0000000000..6dc8477824 --- /dev/null +++ b/crates/ruff_python_codegen/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "ruff_python_codegen" +version = "0.0.0" +publish = false +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +documentation = { workspace = true } +repository = { workspace = true } +license = { workspace = true } + +[lib] + +[dependencies] +ruff_python_ast = { path = "../ruff_python_ast" } +rustpython-parser = { workspace = true } +ruff_source_file = { path = "../ruff_source_file" } + +once_cell = { workspace = true } +rustpython-literal = { workspace = true } +rustpython-ast = { workspace = true } diff --git a/crates/ruff_python_ast/src/source_code/generator.rs b/crates/ruff_python_codegen/src/generator.rs similarity index 99% rename from crates/ruff_python_ast/src/source_code/generator.rs rename to crates/ruff_python_codegen/src/generator.rs index f386e2174e..dd60301cd7 100644 --- a/crates/ruff_python_ast/src/source_code/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -3,16 +3,16 @@ use rustpython_ast::ArgWithDefault; use std::ops::Deref; -use rustpython_literal::escape::{AsciiEscape, Escape, UnicodeEscape}; -use rustpython_parser::ast::{ - self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ConversionFlag, +use rustpython_ast::{ + self as ast, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ConversionFlag, ExceptHandler, Expr, Identifier, MatchCase, Operator, Pattern, Stmt, Suite, TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, WithItem, }; +use rustpython_literal::escape::{AsciiEscape, Escape, UnicodeEscape}; -use ruff_python_trivia::LineEnding; +use ruff_source_file::LineEnding; -use crate::source_code::stylist::{Indentation, Quote, Stylist}; +use super::stylist::{Indentation, Quote, Stylist}; mod precedence { pub(crate) const ASSIGN: u8 = 3; @@ -972,7 +972,7 @@ impl<'a> Generator<'a> { let (op, prec) = opprec!( un, op, - rustpython_parser::ast::UnaryOp, + rustpython_ast::UnaryOp, Invert("~", INVERT), Not("not ", NOT), UAdd("+", UADD), @@ -1478,10 +1478,10 @@ mod tests { use rustpython_ast::{Mod, ModModule, Stmt}; use rustpython_parser::{self, Mode, Parse}; - use ruff_python_trivia::LineEnding; + use ruff_source_file::LineEnding; - use crate::source_code::stylist::{Indentation, Quote}; - use crate::source_code::Generator; + use super::Generator; + use crate::stylist::{Indentation, Quote}; fn round_trip(contents: &str) -> String { let indentation = Indentation::default(); diff --git a/crates/ruff_python_codegen/src/lib.rs b/crates/ruff_python_codegen/src/lib.rs new file mode 100644 index 0000000000..3f01259deb --- /dev/null +++ b/crates/ruff_python_codegen/src/lib.rs @@ -0,0 +1,19 @@ +mod generator; +mod stylist; + +pub use generator::Generator; +use ruff_source_file::Locator; +use rustpython_ast::Suite; +use rustpython_parser::{lexer, Mode, Parse, ParseError}; +pub use stylist::{Quote, Stylist}; + +/// Run round-trip source code generation on a given Python code. +pub fn round_trip(code: &str, source_path: &str) -> Result { + let locator = Locator::new(code); + let python_ast = Suite::parse(code, source_path)?; + let tokens: Vec<_> = lexer::lex(code, Mode::Module).collect(); + let stylist = Stylist::from_tokens(&tokens, &locator); + let mut generator: Generator = (&stylist).into(); + generator.unparse_suite(&python_ast); + Ok(generator.generate()) +} diff --git a/crates/ruff_python_ast/src/source_code/stylist.rs b/crates/ruff_python_codegen/src/stylist.rs similarity index 96% rename from crates/ruff_python_ast/src/source_code/stylist.rs rename to crates/ruff_python_codegen/src/stylist.rs index f38256e0cd..8fa6a867b4 100644 --- a/crates/ruff_python_ast/src/source_code/stylist.rs +++ b/crates/ruff_python_codegen/src/stylist.rs @@ -4,13 +4,13 @@ use std::fmt; use std::ops::Deref; use once_cell::unsync::OnceCell; -use ruff_python_trivia::{find_newline, LineEnding}; +use ruff_source_file::{find_newline, LineEnding}; use rustpython_literal::escape::Quote as StrQuote; use rustpython_parser::lexer::LexResult; use rustpython_parser::Tok; -use crate::source_code::Locator; -use crate::str::leading_quote; +use ruff_python_ast::str::leading_quote; +use ruff_source_file::Locator; pub struct Stylist<'a> { locator: &'a Locator<'a>, @@ -166,10 +166,10 @@ mod tests { use rustpython_parser::lexer::lex; use rustpython_parser::Mode; - use ruff_python_trivia::{find_newline, LineEnding}; + use ruff_source_file::{find_newline, LineEnding}; - use crate::source_code::stylist::{Indentation, Quote}; - use crate::source_code::{Locator, Stylist}; + use super::{Indentation, Quote, Stylist}; + use ruff_source_file::Locator; #[test] fn indentation() { diff --git a/crates/ruff_python_formatter/Cargo.toml b/crates/ruff_python_formatter/Cargo.toml index 0e7653822b..cf99d2c79e 100644 --- a/crates/ruff_python_formatter/Cargo.toml +++ b/crates/ruff_python_formatter/Cargo.toml @@ -13,7 +13,9 @@ license = { workspace = true } [dependencies] ruff_formatter = { path = "../ruff_formatter" } ruff_python_trivia = { path = "../ruff_python_trivia" } +ruff_source_file = { path = "../ruff_source_file" } ruff_python_ast = { path = "../ruff_python_ast" } +ruff_python_index = { path = "../ruff_python_index" } ruff_text_size = { workspace = true } anyhow = { workspace = true } @@ -24,6 +26,7 @@ is-macro = { workspace = true } itertools = { workspace = true } once_cell = { workspace = true } rustc-hash = { workspace = true } +rustpython-ast = { workspace = true } rustpython-parser = { workspace = true } serde = { workspace = true, optional = true } smallvec = { workspace = true } @@ -44,5 +47,5 @@ test = true required-features = [ "serde" ] [features] -serde = ["dep:serde", "ruff_formatter/serde"] +serde = ["dep:serde", "ruff_formatter/serde", "ruff_source_file/serde"] default = ["serde"] diff --git a/crates/ruff_python_formatter/generate.py b/crates/ruff_python_formatter/generate.py index 98816c27e6..83e42e5eb1 100755 --- a/crates/ruff_python_formatter/generate.py +++ b/crates/ruff_python_formatter/generate.py @@ -90,7 +90,7 @@ for group, group_nodes in nodes_grouped.items(): code = f""" use crate::{{verbatim_text, FormatNodeRule, PyFormatter}}; use ruff_formatter::{{write, Buffer, FormatResult}}; - use rustpython_parser::ast::{node}; + use rustpython_ast::{node}; #[derive(Default)] pub struct Format{node}; diff --git a/crates/ruff_python_formatter/src/builders.rs b/crates/ruff_python_formatter/src/builders.rs index c23938edd9..5cafe4e961 100644 --- a/crates/ruff_python_formatter/src/builders.rs +++ b/crates/ruff_python_formatter/src/builders.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use crate::comments::{dangling_comments, SourceComment}; use ruff_formatter::{format_args, write, Argument, Arguments}; @@ -377,7 +377,7 @@ impl<'ast> Format> for EmptyWithDanglingComments<'_> { #[cfg(test)] mod tests { - use rustpython_parser::ast::ModModule; + use rustpython_ast::ModModule; use rustpython_parser::Parse; use ruff_formatter::format; diff --git a/crates/ruff_python_formatter/src/cli.rs b/crates/ruff_python_formatter/src/cli.rs index 47ee266131..5c645ee450 100644 --- a/crates/ruff_python_formatter/src/cli.rs +++ b/crates/ruff_python_formatter/src/cli.rs @@ -8,7 +8,7 @@ use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; use ruff_formatter::SourceCode; -use ruff_python_ast::source_code::CommentRangesBuilder; +use ruff_python_index::CommentRangesBuilder; use crate::{format_node, PyFormatOptions}; diff --git a/crates/ruff_python_formatter/src/comments/debug.rs b/crates/ruff_python_formatter/src/comments/debug.rs index 37be2ed9c0..c30e7f73e6 100644 --- a/crates/ruff_python_formatter/src/comments/debug.rs +++ b/crates/ruff_python_formatter/src/comments/debug.rs @@ -1,7 +1,7 @@ use std::fmt::{Debug, Formatter, Write}; use itertools::Itertools; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_formatter::SourceCode; @@ -179,7 +179,7 @@ impl Debug for DebugNodeCommentSlice<'_> { mod tests { use insta::assert_debug_snapshot; use ruff_text_size::{TextRange, TextSize}; - use rustpython_parser::ast::{StmtBreak, StmtContinue}; + use rustpython_ast::{StmtBreak, StmtContinue}; use ruff_formatter::SourceCode; use ruff_python_ast::node::AnyNode; diff --git a/crates/ruff_python_formatter/src/comments/format.rs b/crates/ruff_python_formatter/src/comments/format.rs index f9dfc8ec1f..331e8c4b8d 100644 --- a/crates/ruff_python_formatter/src/comments/format.rs +++ b/crates/ruff_python_formatter/src/comments/format.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_formatter::{format_args, write, FormatError, SourceCode}; use ruff_python_ast::node::{AnyNodeRef, AstNode}; diff --git a/crates/ruff_python_formatter/src/comments/mod.rs b/crates/ruff_python_formatter/src/comments/mod.rs index 71912c60fd..01a2915dd5 100644 --- a/crates/ruff_python_formatter/src/comments/mod.rs +++ b/crates/ruff_python_formatter/src/comments/mod.rs @@ -92,7 +92,7 @@ use std::cell::Cell; use std::fmt::Debug; use std::rc::Rc; -use rustpython_parser::ast::{Mod, Ranged}; +use rustpython_ast::{Mod, Ranged}; pub(crate) use format::{ dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments, @@ -100,7 +100,7 @@ pub(crate) use format::{ }; use ruff_formatter::{SourceCode, SourceCodeSlice}; use ruff_python_ast::node::AnyNodeRef; -use ruff_python_ast::source_code::CommentRanges; +use ruff_python_index::CommentRanges; use crate::comments::debug::{DebugComment, DebugComments}; use crate::comments::map::MultiMap; @@ -414,12 +414,12 @@ struct CommentsData<'a> { #[cfg(test)] mod tests { use insta::assert_debug_snapshot; - use rustpython_parser::ast::Mod; + use rustpython_ast::Mod; use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; use ruff_formatter::SourceCode; - use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder}; + use ruff_python_index::{CommentRanges, CommentRangesBuilder}; use crate::comments::Comments; diff --git a/crates/ruff_python_formatter/src/comments/node_key.rs b/crates/ruff_python_formatter/src/comments/node_key.rs index 38e8f026c7..3601b22940 100644 --- a/crates/ruff_python_formatter/src/comments/node_key.rs +++ b/crates/ruff_python_formatter/src/comments/node_key.rs @@ -54,7 +54,7 @@ mod tests { use crate::comments::node_key::NodeRefEqualityKey; use ruff_python_ast::node::AnyNodeRef; use ruff_text_size::TextRange; - use rustpython_parser::ast::StmtContinue; + use rustpython_ast::StmtContinue; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index 8f257a9c4a..d544d918f5 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -1,15 +1,15 @@ use std::cmp::Ordering; use ruff_text_size::TextRange; +use rustpython_ast::{Expr, ExprIfExp, ExprSlice, Ranged}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, ExprIfExp, ExprSlice, Ranged}; use ruff_python_ast::node::{AnyNodeRef, AstNode}; -use ruff_python_ast::source_code::Locator; use ruff_python_ast::whitespace; use ruff_python_trivia::{ - PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer, UniversalNewlines, + indentation_at_offset, PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer, }; +use ruff_source_file::{Locator, UniversalNewlines}; use crate::comments::visitor::{CommentPlacement, DecoratedComment}; use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection}; @@ -89,10 +89,9 @@ fn handle_match_comment<'a>( let next_case = match_stmt.cases.get(current_case_index + 1); - let comment_indentation = - whitespace::indentation_at_offset(locator, comment.slice().range().start()) - .unwrap_or_default() - .len(); + let comment_indentation = indentation_at_offset(locator, comment.slice().range().start()) + .unwrap_or_default() + .len(); let match_case_indentation = whitespace::indentation(locator, match_case).unwrap().len(); if let Some(next_case) = next_case { @@ -174,10 +173,9 @@ fn handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comme // it now depends on the indentation level of the comment if it is a leading comment for e.g. // the following `finally` or indeed a trailing comment of the previous body's last statement. - let comment_indentation = - whitespace::indentation_at_offset(locator, comment.slice().range().start()) - .unwrap_or_default() - .len(); + let comment_indentation = indentation_at_offset(locator, comment.slice().range().start()) + .unwrap_or_default() + .len(); let Some(except_indentation) = whitespace::indentation(locator, preceding_except_handler).map(str::len) @@ -269,10 +267,9 @@ fn handle_in_between_bodies_own_line_comment<'a>( // it now depends on the indentation level of the comment if it is a leading comment for e.g. // the following `elif` or indeed a trailing comment of the previous body's last statement. - let comment_indentation = - whitespace::indentation_at_offset(locator, comment.slice().range().start()) - .unwrap_or_default() - .len(); + let comment_indentation = indentation_at_offset(locator, comment.slice().range().start()) + .unwrap_or_default() + .len(); let Some(preceding_indentation) = whitespace::indentation(locator, &preceding).map(str::len) else { @@ -445,10 +442,9 @@ fn own_line_comment_after_branch<'a>( // We only care about the length because indentations with mixed spaces and tabs are only valid if // the indent-level doesn't depend on the tab width (the indent level must be the same if the tab width is 1 or 8). - let comment_indentation = - whitespace::indentation_at_offset(locator, comment.slice().range().start()) - .unwrap_or_default() - .len(); + let comment_indentation = indentation_at_offset(locator, comment.slice().range().start()) + .unwrap_or_default() + .len(); // Keep the comment on the entire statement in case it's a trailing comment // ```python @@ -459,10 +455,9 @@ fn own_line_comment_after_branch<'a>( // # Trailing if comment // ``` // Here we keep the comment a trailing comment of the `if` - let preceding_node_indentation = - whitespace::indentation_at_offset(locator, preceding_node.start()) - .unwrap_or_default() - .len(); + let preceding_node_indentation = indentation_at_offset(locator, preceding_node.start()) + .unwrap_or_default() + .len(); if comment_indentation == preceding_node_indentation { return CommentPlacement::Default(comment); } diff --git a/crates/ruff_python_formatter/src/comments/visitor.rs b/crates/ruff_python_formatter/src/comments/visitor.rs index 87d6b317f6..6a92e90a91 100644 --- a/crates/ruff_python_formatter/src/comments/visitor.rs +++ b/crates/ruff_python_formatter/src/comments/visitor.rs @@ -1,14 +1,15 @@ use std::iter::Peekable; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{ +use rustpython_ast::{ Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ElifElseClause, ExceptHandler, Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, WithItem, }; use ruff_formatter::{SourceCode, SourceCodeSlice}; use ruff_python_ast::node::AnyNodeRef; -use ruff_python_ast::source_code::{CommentRanges, Locator}; +use ruff_python_index::CommentRanges; +use ruff_source_file::Locator; // The interface is designed to only export the members relevant for iterating nodes in // pre-order. #[allow(clippy::wildcard_imports)] diff --git a/crates/ruff_python_formatter/src/context.rs b/crates/ruff_python_formatter/src/context.rs index e68a43982f..049fd67e54 100644 --- a/crates/ruff_python_formatter/src/context.rs +++ b/crates/ruff_python_formatter/src/context.rs @@ -1,7 +1,7 @@ use crate::comments::Comments; use crate::PyFormatOptions; use ruff_formatter::{FormatContext, GroupId, SourceCode}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use std::fmt::{Debug, Formatter}; #[derive(Clone)] diff --git a/crates/ruff_python_formatter/src/expression/expr_attribute.rs b/crates/ruff_python_formatter/src/expression/expr_attribute.rs index e5a8602caa..197b6e2154 100644 --- a/crates/ruff_python_formatter/src/expression/expr_attribute.rs +++ b/crates/ruff_python_formatter/src/expression/expr_attribute.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Constant, Expr, ExprAttribute, ExprConstant}; +use rustpython_ast::{Constant, Expr, ExprAttribute, ExprConstant}; use ruff_formatter::write; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_await.rs b/crates/ruff_python_formatter/src/expression/expr_await.rs index b18fa487b7..09368240b9 100644 --- a/crates/ruff_python_formatter/src/expression/expr_await.rs +++ b/crates/ruff_python_formatter/src/expression/expr_await.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::ExprAwait; +use rustpython_ast::ExprAwait; use ruff_formatter::write; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_bin_op.rs b/crates/ruff_python_formatter/src/expression/expr_bin_op.rs index 472bd33881..cc37c5a9ff 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bin_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bin_op.rs @@ -1,6 +1,6 @@ use std::iter; -use rustpython_parser::ast::{ +use rustpython_ast::{ Constant, Expr, ExprAttribute, ExprBinOp, ExprConstant, ExprUnaryOp, Operator, UnaryOp, }; use smallvec::SmallVec; diff --git a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs index e6f646774f..1bb46d7e5f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs @@ -6,7 +6,7 @@ use crate::expression::parentheses::{ use crate::prelude::*; use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::{BoolOp, ExprBoolOp}; +use rustpython_ast::{BoolOp, ExprBoolOp}; #[derive(Default)] pub struct FormatExprBoolOp { diff --git a/crates/ruff_python_formatter/src/expression/expr_call.rs b/crates/ruff_python_formatter/src/expression/expr_call.rs index ad9b3a0a5f..c0bbfbbb1e 100644 --- a/crates/ruff_python_formatter/src/expression/expr_call.rs +++ b/crates/ruff_python_formatter/src/expression/expr_call.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Expr, ExprCall, Ranged}; +use rustpython_ast::{Expr, ExprCall, Ranged}; use crate::builders::empty_parenthesized_with_dangling_comments; use ruff_formatter::write; diff --git a/crates/ruff_python_formatter/src/expression/expr_compare.rs b/crates/ruff_python_formatter/src/expression/expr_compare.rs index c1ded61d3d..b30799b125 100644 --- a/crates/ruff_python_formatter/src/expression/expr_compare.rs +++ b/crates/ruff_python_formatter/src/expression/expr_compare.rs @@ -7,7 +7,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::{CmpOp, ExprCompare}; +use rustpython_ast::{CmpOp, ExprCompare}; #[derive(Default)] pub struct FormatExprCompare { diff --git a/crates/ruff_python_formatter/src/expression/expr_constant.rs b/crates/ruff_python_formatter/src/expression/expr_constant.rs index aaf7c9d6c3..1d938975f0 100644 --- a/crates/ruff_python_formatter/src/expression/expr_constant.rs +++ b/crates/ruff_python_formatter/src/expression/expr_constant.rs @@ -1,5 +1,5 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{Constant, ExprConstant, Ranged}; +use rustpython_ast::{Constant, ExprConstant, Ranged}; use ruff_formatter::FormatRuleWithOptions; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index 59d6b18093..3badcf658f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -6,8 +6,8 @@ use crate::FormatNodeRule; use ruff_formatter::{format_args, write}; use ruff_python_ast::node::AnyNodeRef; use ruff_text_size::TextRange; -use rustpython_parser::ast::Ranged; -use rustpython_parser::ast::{Expr, ExprDict}; +use rustpython_ast::Ranged; +use rustpython_ast::{Expr, ExprDict}; #[derive(Default)] pub struct FormatExprDict; diff --git a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs index c57d6e1f4b..8451159244 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs @@ -7,7 +7,7 @@ use ruff_formatter::prelude::{ }; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprDictComp; +use rustpython_ast::ExprDictComp; #[derive(Default)] pub struct FormatExprDictComp; diff --git a/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs b/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs index d2f224efd5..b62c7d24f4 100644 --- a/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs +++ b/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprFormattedValue; +use rustpython_ast::ExprFormattedValue; #[derive(Default)] pub struct FormatExprFormattedValue; diff --git a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs index 5b93663fb0..fa448edee0 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -6,7 +6,7 @@ use crate::AsFormat; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::{format_args, write, Buffer, FormatResult, FormatRuleWithOptions}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprGeneratorExp; +use rustpython_ast::ExprGeneratorExp; #[derive(Eq, PartialEq, Debug, Default)] pub enum GeneratorExpParentheses { diff --git a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs index 7e974a9f23..2ee4b0249c 100644 --- a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs @@ -7,7 +7,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::{format_args, write}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprIfExp; +use rustpython_ast::ExprIfExp; #[derive(Default)] pub struct FormatExprIfExp; diff --git a/crates/ruff_python_formatter/src/expression/expr_joined_str.rs b/crates/ruff_python_formatter/src/expression/expr_joined_str.rs index cf54ebffcb..50fb63aa9d 100644 --- a/crates/ruff_python_formatter/src/expression/expr_joined_str.rs +++ b/crates/ruff_python_formatter/src/expression/expr_joined_str.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprJoinedStr; +use rustpython_ast::ExprJoinedStr; #[derive(Default)] pub struct FormatExprJoinedStr; diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index abafdd3c26..65e3b39fd7 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -7,7 +7,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprLambda; +use rustpython_ast::ExprLambda; #[derive(Default)] pub struct FormatExprLambda; diff --git a/crates/ruff_python_formatter/src/expression/expr_list.rs b/crates/ruff_python_formatter/src/expression/expr_list.rs index bd13210967..d64637baa1 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalPa use crate::prelude::*; use crate::FormatNodeRule; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::{ExprList, Ranged}; +use rustpython_ast::{ExprList, Ranged}; #[derive(Default)] pub struct FormatExprList; diff --git a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs index 9d4a223d2c..48a5283c0a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs @@ -5,7 +5,7 @@ use crate::AsFormat; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::{format_args, write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprListComp; +use rustpython_ast::ExprListComp; #[derive(Default)] pub struct FormatExprListComp; diff --git a/crates/ruff_python_formatter/src/expression/expr_name.rs b/crates/ruff_python_formatter/src/expression/expr_name.rs index b3963adb42..315d6cebc4 100644 --- a/crates/ruff_python_formatter/src/expression/expr_name.rs +++ b/crates/ruff_python_formatter/src/expression/expr_name.rs @@ -3,7 +3,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::{write, FormatContext}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprName; +use rustpython_ast::ExprName; #[derive(Default)] pub struct FormatExprName; @@ -37,7 +37,7 @@ impl NeedsParentheses for ExprName { #[cfg(test)] mod tests { use ruff_text_size::{TextRange, TextSize}; - use rustpython_parser::ast::{ModModule, Ranged}; + use rustpython_ast::{ModModule, Ranged}; use rustpython_parser::Parse; #[test] diff --git a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs index 4a009b8746..82f88da634 100644 --- a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs +++ b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs @@ -4,7 +4,7 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprNamedExpr; +use rustpython_ast::ExprNamedExpr; #[derive(Default)] pub struct FormatExprNamedExpr; diff --git a/crates/ruff_python_formatter/src/expression/expr_set.rs b/crates/ruff_python_formatter/src/expression/expr_set.rs index 5c7a27bf4d..12341148e3 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{ExprSet, Ranged}; +use rustpython_ast::{ExprSet, Ranged}; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs index a539d8e6a1..26bb401b84 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs @@ -5,7 +5,7 @@ use crate::AsFormat; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::{format_args, write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprSetComp; +use rustpython_ast::ExprSetComp; #[derive(Default)] pub struct FormatExprSetComp; diff --git a/crates/ruff_python_formatter/src/expression/expr_slice.rs b/crates/ruff_python_formatter/src/expression/expr_slice.rs index 2423e74cfe..046ee0bf4d 100644 --- a/crates/ruff_python_formatter/src/expression/expr_slice.rs +++ b/crates/ruff_python_formatter/src/expression/expr_slice.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, ExprSlice, ExprUnaryOp, Ranged, UnaryOp}; +use rustpython_ast::{Expr, ExprSlice, ExprUnaryOp, Ranged, UnaryOp}; use ruff_formatter::prelude::{hard_line_break, line_suffix_boundary, space, text}; use ruff_formatter::{write, Buffer, Format, FormatError, FormatResult}; diff --git a/crates/ruff_python_formatter/src/expression/expr_starred.rs b/crates/ruff_python_formatter/src/expression/expr_starred.rs index 6027ef8430..d2cfe361bb 100644 --- a/crates/ruff_python_formatter/src/expression/expr_starred.rs +++ b/crates/ruff_python_formatter/src/expression/expr_starred.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::ExprStarred; +use rustpython_ast::ExprStarred; use ruff_formatter::write; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_subscript.rs b/crates/ruff_python_formatter/src/expression/expr_subscript.rs index e5289594ca..e17733425a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_subscript.rs +++ b/crates/ruff_python_formatter/src/expression/expr_subscript.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, ExprSubscript}; +use rustpython_ast::{Expr, ExprSubscript}; use ruff_formatter::{format_args, write}; use ruff_python_ast::node::{AnyNodeRef, AstNode}; diff --git a/crates/ruff_python_formatter/src/expression/expr_tuple.rs b/crates/ruff_python_formatter/src/expression/expr_tuple.rs index 098a7a572e..9a3fc0d9c6 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -1,6 +1,6 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::ExprTuple; -use rustpython_parser::ast::{Expr, Ranged}; +use rustpython_ast::ExprTuple; +use rustpython_ast::{Expr, Ranged}; use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/expr_unary_op.rs b/crates/ruff_python_formatter/src/expression/expr_unary_op.rs index 3e2ac39068..4ff22f7d96 100644 --- a/crates/ruff_python_formatter/src/expression/expr_unary_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_unary_op.rs @@ -1,6 +1,6 @@ use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::UnaryOp; -use rustpython_parser::ast::{ExprUnaryOp, Ranged}; +use rustpython_ast::UnaryOp; +use rustpython_ast::{ExprUnaryOp, Ranged}; use ruff_formatter::prelude::{hard_line_break, space, text}; use ruff_formatter::{Format, FormatContext, FormatResult}; diff --git a/crates/ruff_python_formatter/src/expression/expr_yield.rs b/crates/ruff_python_formatter/src/expression/expr_yield.rs index 106e3489e7..818d8101ae 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield.rs @@ -5,7 +5,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprYield; +use rustpython_ast::ExprYield; #[derive(Default)] pub struct FormatExprYield; diff --git a/crates/ruff_python_formatter/src/expression/expr_yield_from.rs b/crates/ruff_python_formatter/src/expression/expr_yield_from.rs index ffab491cc9..24a65bda3f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield_from.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield_from.rs @@ -5,7 +5,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::ExprYieldFrom; +use rustpython_ast::ExprYieldFrom; #[derive(Default)] pub struct FormatExprYieldFrom; diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index b146a35f6b..ba65b1b4e2 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; +use rustpython_ast::{Expr, Operator}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Operator}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions}; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/expression/number.rs b/crates/ruff_python_formatter/src/expression/number.rs index ba6dba40be..a8ee2d957a 100644 --- a/crates/ruff_python_formatter/src/expression/number.rs +++ b/crates/ruff_python_formatter/src/expression/number.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use ruff_text_size::TextSize; -use rustpython_parser::ast::{ExprConstant, Ranged}; +use rustpython_ast::{ExprConstant, Ranged}; use crate::prelude::*; diff --git a/crates/ruff_python_formatter/src/expression/parentheses.rs b/crates/ruff_python_formatter/src/expression/parentheses.rs index 87f76a8ac6..265e7d7cd9 100644 --- a/crates/ruff_python_formatter/src/expression/parentheses.rs +++ b/crates/ruff_python_formatter/src/expression/parentheses.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_formatter::prelude::tag::Condition; use ruff_formatter::{format_args, write, Argument, Arguments}; diff --git a/crates/ruff_python_formatter/src/expression/string.rs b/crates/ruff_python_formatter/src/expression/string.rs index 87e9ff824b..cd2188c114 100644 --- a/crates/ruff_python_formatter/src/expression/string.rs +++ b/crates/ruff_python_formatter/src/expression/string.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use bitflags::bitflags; use ruff_text_size::{TextLen, TextRange, TextSize}; -use rustpython_parser::ast::{ExprConstant, Ranged}; +use rustpython_ast::{ExprConstant, Ranged}; use rustpython_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType}; use rustpython_parser::{Mode, Tok}; diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index d1a7420291..10e29821cc 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -13,9 +13,10 @@ use ruff_formatter::{ }; use ruff_formatter::{Formatted, Printed, SourceCode}; use ruff_python_ast::node::{AnyNodeRef, AstNode, NodeKind}; -use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator}; +use ruff_python_index::{CommentRanges, CommentRangesBuilder}; +use ruff_source_file::Locator; use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::{Mod, Ranged}; +use rustpython_ast::{Mod, Ranged}; use rustpython_parser::lexer::{lex, LexicalError}; use rustpython_parser::{parse_tokens, Mode, ParseError}; use std::borrow::Cow; @@ -249,7 +250,7 @@ mod tests { use crate::{format_module, format_node, PyFormatOptions}; use anyhow::Result; use insta::assert_snapshot; - use ruff_python_ast::source_code::CommentRangesBuilder; + use ruff_python_index::CommentRangesBuilder; use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; diff --git a/crates/ruff_python_formatter/src/module/mod.rs b/crates/ruff_python_formatter/src/module/mod.rs index 0638d4907c..bd4b5021fc 100644 --- a/crates/ruff_python_formatter/src/module/mod.rs +++ b/crates/ruff_python_formatter/src/module/mod.rs @@ -1,7 +1,7 @@ use crate::context::PyFormatContext; use crate::{AsFormat, IntoFormat, PyFormatter}; use ruff_formatter::{Format, FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; -use rustpython_parser::ast::Mod; +use rustpython_ast::Mod; pub(crate) mod mod_expression; pub(crate) mod mod_function_type; diff --git a/crates/ruff_python_formatter/src/module/mod_expression.rs b/crates/ruff_python_formatter/src/module/mod_expression.rs index f6e49fb696..fc2b33686f 100644 --- a/crates/ruff_python_formatter/src/module/mod_expression.rs +++ b/crates/ruff_python_formatter/src/module/mod_expression.rs @@ -1,6 +1,6 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::{Format, FormatResult}; -use rustpython_parser::ast::ModExpression; +use rustpython_ast::ModExpression; #[derive(Default)] pub struct FormatModExpression; diff --git a/crates/ruff_python_formatter/src/module/mod_function_type.rs b/crates/ruff_python_formatter/src/module/mod_function_type.rs index 822d7d9553..8749526dbd 100644 --- a/crates/ruff_python_formatter/src/module/mod_function_type.rs +++ b/crates/ruff_python_formatter/src/module/mod_function_type.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::ModFunctionType; +use rustpython_ast::ModFunctionType; #[derive(Default)] pub struct FormatModFunctionType; diff --git a/crates/ruff_python_formatter/src/module/mod_interactive.rs b/crates/ruff_python_formatter/src/module/mod_interactive.rs index 2477a1b18d..34ff8d3279 100644 --- a/crates/ruff_python_formatter/src/module/mod_interactive.rs +++ b/crates/ruff_python_formatter/src/module/mod_interactive.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::ModInteractive; +use rustpython_ast::ModInteractive; #[derive(Default)] pub struct FormatModInteractive; diff --git a/crates/ruff_python_formatter/src/module/mod_module.rs b/crates/ruff_python_formatter/src/module/mod_module.rs index 0d0fee7c00..dd25b71d5a 100644 --- a/crates/ruff_python_formatter/src/module/mod_module.rs +++ b/crates/ruff_python_formatter/src/module/mod_module.rs @@ -2,7 +2,7 @@ use crate::statement::suite::SuiteLevel; use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::hard_line_break; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::ModModule; +use rustpython_ast::ModModule; #[derive(Default)] pub struct FormatModModule; diff --git a/crates/ruff_python_formatter/src/other/alias.rs b/crates/ruff_python_formatter/src/other/alias.rs index f59dd012bd..7ad9dd9822 100644 --- a/crates/ruff_python_formatter/src/other/alias.rs +++ b/crates/ruff_python_formatter/src/other/alias.rs @@ -1,7 +1,7 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, Format, FormatResult}; -use rustpython_parser::ast::Alias; +use rustpython_ast::Alias; #[derive(Default)] pub struct FormatAlias; diff --git a/crates/ruff_python_formatter/src/other/arg.rs b/crates/ruff_python_formatter/src/other/arg.rs index 3974223faa..634ab0dd34 100644 --- a/crates/ruff_python_formatter/src/other/arg.rs +++ b/crates/ruff_python_formatter/src/other/arg.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; -use rustpython_parser::ast::Arg; +use rustpython_ast::Arg; #[derive(Default)] pub struct FormatArg; diff --git a/crates/ruff_python_formatter/src/other/arg_with_default.rs b/crates/ruff_python_formatter/src/other/arg_with_default.rs index c6badb551a..a76b9e88cd 100644 --- a/crates/ruff_python_formatter/src/other/arg_with_default.rs +++ b/crates/ruff_python_formatter/src/other/arg_with_default.rs @@ -1,5 +1,5 @@ use ruff_formatter::write; -use rustpython_parser::ast::ArgWithDefault; +use rustpython_ast::ArgWithDefault; use crate::prelude::*; use crate::FormatNodeRule; diff --git a/crates/ruff_python_formatter/src/other/arguments.rs b/crates/ruff_python_formatter/src/other/arguments.rs index b90db94d19..d852b398f7 100644 --- a/crates/ruff_python_formatter/src/other/arguments.rs +++ b/crates/ruff_python_formatter/src/other/arguments.rs @@ -1,7 +1,7 @@ use std::usize; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Arguments, Ranged}; +use rustpython_ast::{Arguments, Ranged}; use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_python_ast::node::{AnyNodeRef, AstNode}; diff --git a/crates/ruff_python_formatter/src/other/comprehension.rs b/crates/ruff_python_formatter/src/other/comprehension.rs index d35c8d5cb6..ba2ef20e3f 100644 --- a/crates/ruff_python_formatter/src/other/comprehension.rs +++ b/crates/ruff_python_formatter/src/other/comprehension.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use crate::AsFormat; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::{format_args, write, Buffer, FormatResult}; -use rustpython_parser::ast::{Comprehension, Expr, Ranged}; +use rustpython_ast::{Comprehension, Expr, Ranged}; #[derive(Default)] pub struct FormatComprehension; diff --git a/crates/ruff_python_formatter/src/other/decorator.rs b/crates/ruff_python_formatter/src/other/decorator.rs index 88b1a92d65..703cfb7036 100644 --- a/crates/ruff_python_formatter/src/other/decorator.rs +++ b/crates/ruff_python_formatter/src/other/decorator.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize; use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; -use rustpython_parser::ast::Decorator; +use rustpython_ast::Decorator; #[derive(Default)] pub struct FormatDecorator; diff --git a/crates/ruff_python_formatter/src/other/elif_else_clause.rs b/crates/ruff_python_formatter/src/other/elif_else_clause.rs index 4766178f7b..55d1b7a44a 100644 --- a/crates/ruff_python_formatter/src/other/elif_else_clause.rs +++ b/crates/ruff_python_formatter/src/other/elif_else_clause.rs @@ -1,7 +1,7 @@ use crate::statement::stmt_if::format_elif_else_clause; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::FormatResult; -use rustpython_parser::ast::ElifElseClause; +use rustpython_ast::ElifElseClause; /// Note that this implementation misses the leading newlines before the leading comments because /// it does not have access to the last node of the previous branch. The `StmtIf` therefore doesn't diff --git a/crates/ruff_python_formatter/src/other/except_handler_except_handler.rs b/crates/ruff_python_formatter/src/other/except_handler_except_handler.rs index a66fd39963..95e792ee34 100644 --- a/crates/ruff_python_formatter/src/other/except_handler_except_handler.rs +++ b/crates/ruff_python_formatter/src/other/except_handler_except_handler.rs @@ -6,7 +6,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::FormatRuleWithOptions; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AstNode; -use rustpython_parser::ast::ExceptHandlerExceptHandler; +use rustpython_ast::ExceptHandlerExceptHandler; #[derive(Copy, Clone, Default)] pub enum ExceptHandlerKind { diff --git a/crates/ruff_python_formatter/src/other/identifier.rs b/crates/ruff_python_formatter/src/other/identifier.rs index 40e588b491..506fb5241f 100644 --- a/crates/ruff_python_formatter/src/other/identifier.rs +++ b/crates/ruff_python_formatter/src/other/identifier.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use crate::AsFormat; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule}; -use rustpython_parser::ast::{Identifier, Ranged}; +use rustpython_ast::{Identifier, Ranged}; pub struct FormatIdentifier; diff --git a/crates/ruff_python_formatter/src/other/keyword.rs b/crates/ruff_python_formatter/src/other/keyword.rs index 47d3db19fc..d8985abfa7 100644 --- a/crates/ruff_python_formatter/src/other/keyword.rs +++ b/crates/ruff_python_formatter/src/other/keyword.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; -use rustpython_parser::ast::Keyword; +use rustpython_ast::Keyword; #[derive(Default)] pub struct FormatKeyword; diff --git a/crates/ruff_python_formatter/src/other/match_case.rs b/crates/ruff_python_formatter/src/other/match_case.rs index f4b79d1960..b9feea3343 100644 --- a/crates/ruff_python_formatter/src/other/match_case.rs +++ b/crates/ruff_python_formatter/src/other/match_case.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::MatchCase; +use rustpython_ast::MatchCase; #[derive(Default)] pub struct FormatMatchCase; diff --git a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs b/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs index b622a705e3..574f4a7da6 100644 --- a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs +++ b/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::TypeIgnoreTypeIgnore; +use rustpython_ast::TypeIgnoreTypeIgnore; #[derive(Default)] pub struct FormatTypeIgnoreTypeIgnore; diff --git a/crates/ruff_python_formatter/src/other/with_item.rs b/crates/ruff_python_formatter/src/other/with_item.rs index 960180b473..e5ce34624a 100644 --- a/crates/ruff_python_formatter/src/other/with_item.rs +++ b/crates/ruff_python_formatter/src/other/with_item.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::WithItem; +use rustpython_ast::WithItem; use ruff_formatter::{write, Buffer, FormatResult}; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs index 3f67d87b93..5acd82349b 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchAs; +use rustpython_ast::PatternMatchAs; #[derive(Default)] pub struct FormatPatternMatchAs; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs index a64f4b2207..9d2700379a 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchClass; +use rustpython_ast::PatternMatchClass; #[derive(Default)] pub struct FormatPatternMatchClass; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs index b3fca1d5d4..09454a3411 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchMapping; +use rustpython_ast::PatternMatchMapping; #[derive(Default)] pub struct FormatPatternMatchMapping; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs index 487e884ec8..418d9bdbd8 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchOr; +use rustpython_ast::PatternMatchOr; #[derive(Default)] pub struct FormatPatternMatchOr; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs index c2fa31ecf9..ea1a21e6cb 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchSequence; +use rustpython_ast::PatternMatchSequence; #[derive(Default)] pub struct FormatPatternMatchSequence; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs index 352098e9d1..f2004b3375 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchSingleton; +use rustpython_ast::PatternMatchSingleton; #[derive(Default)] pub struct FormatPatternMatchSingleton; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs index 17340ae840..c3ee6b2042 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::PatternMatchStar; +use rustpython_ast::PatternMatchStar; #[derive(Default)] pub struct FormatPatternMatchStar; diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs index 0a5251f3aa..47434408dc 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::PatternMatchValue; +use rustpython_ast::PatternMatchValue; use ruff_formatter::{write, Buffer, FormatResult}; diff --git a/crates/ruff_python_formatter/src/statement/mod.rs b/crates/ruff_python_formatter/src/statement/mod.rs index 8996aab81a..2967f9aa3a 100644 --- a/crates/ruff_python_formatter/src/statement/mod.rs +++ b/crates/ruff_python_formatter/src/statement/mod.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule}; -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; pub(crate) mod stmt_ann_assign; pub(crate) mod stmt_assert; diff --git a/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs index 418b4d52c1..92629add56 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize; use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; -use rustpython_parser::ast::StmtAnnAssign; +use rustpython_ast::StmtAnnAssign; #[derive(Default)] pub struct FormatStmtAnnAssign; diff --git a/crates/ruff_python_formatter/src/statement/stmt_assert.rs b/crates/ruff_python_formatter/src/statement/stmt_assert.rs index ab09b8053d..d76dae494d 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_assert.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_assert.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtAssert; +use rustpython_ast::StmtAssert; #[derive(Default)] pub struct FormatStmtAssert; diff --git a/crates/ruff_python_formatter/src/statement/stmt_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_assign.rs index 4a2d6538e4..825ae0a7c3 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_assign.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Expr, StmtAssign}; +use rustpython_ast::{Expr, StmtAssign}; use ruff_formatter::{format_args, write, FormatError}; diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_for.rs b/crates/ruff_python_formatter/src/statement/stmt_async_for.rs index 906f19c5e0..342ed9f855 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_for.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_for.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use crate::statement::stmt_for::AnyStatementFor; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::FormatResult; -use rustpython_parser::ast::StmtAsyncFor; +use rustpython_ast::StmtAsyncFor; #[derive(Default)] pub struct FormatStmtAsyncFor; diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs b/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs index 1a001d91b7..85c6dd956e 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::StmtAsyncFunctionDef; +use rustpython_ast::StmtAsyncFunctionDef; use ruff_python_ast::function::AnyFunctionDefinition; diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_with.rs b/crates/ruff_python_formatter/src/statement/stmt_async_with.rs index e8d0e0ebd9..83bfadb5bc 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_with.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_with.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use crate::statement::stmt_with::AnyStatementWith; use crate::FormatNodeRule; -use rustpython_parser::ast::StmtAsyncWith; +use rustpython_ast::StmtAsyncWith; #[derive(Default)] pub struct FormatStmtAsyncWith; diff --git a/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs index 6682ef547b..1674753a4b 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize; use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtAugAssign; +use rustpython_ast::StmtAugAssign; #[derive(Default)] pub struct FormatStmtAugAssign; diff --git a/crates/ruff_python_formatter/src/statement/stmt_break.rs b/crates/ruff_python_formatter/src/statement/stmt_break.rs index 53cb75f6cc..d3ed9ca3a7 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_break.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_break.rs @@ -1,7 +1,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::text; use ruff_formatter::{Format, FormatResult}; -use rustpython_parser::ast::StmtBreak; +use rustpython_ast::StmtBreak; #[derive(Default)] pub struct FormatStmtBreak; diff --git a/crates/ruff_python_formatter/src/statement/stmt_class_def.rs b/crates/ruff_python_formatter/src/statement/stmt_class_def.rs index 4971b31fc0..098f764810 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_class_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_class_def.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Ranged, StmtClassDef}; +use rustpython_ast::{Ranged, StmtClassDef}; use ruff_formatter::write; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; diff --git a/crates/ruff_python_formatter/src/statement/stmt_continue.rs b/crates/ruff_python_formatter/src/statement/stmt_continue.rs index d6403fd1bf..7f43fa49e5 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_continue.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_continue.rs @@ -1,7 +1,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::text; use ruff_formatter::{Format, FormatResult}; -use rustpython_parser::ast::StmtContinue; +use rustpython_ast::StmtContinue; #[derive(Default)] pub struct FormatStmtContinue; diff --git a/crates/ruff_python_formatter/src/statement/stmt_delete.rs b/crates/ruff_python_formatter/src/statement/stmt_delete.rs index a61e86c028..e15ebd3f2d 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_delete.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_delete.rs @@ -5,7 +5,7 @@ use crate::expression::parentheses::Parenthesize; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{block_indent, format_with, space, text}; use ruff_formatter::{write, Buffer, Format, FormatResult}; -use rustpython_parser::ast::{Ranged, StmtDelete}; +use rustpython_ast::{Ranged, StmtDelete}; #[derive(Default)] pub struct FormatStmtDelete; diff --git a/crates/ruff_python_formatter/src/statement/stmt_expr.rs b/crates/ruff_python_formatter/src/statement/stmt_expr.rs index 243bbf2c9a..a2586fae20 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_expr.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_expr.rs @@ -1,5 +1,5 @@ +use rustpython_ast::{Expr, Operator, StmtExpr}; use rustpython_parser::ast; -use rustpython_parser::ast::{Expr, Operator, StmtExpr}; use crate::expression::maybe_parenthesize_expression; use crate::expression::parentheses::Parenthesize; diff --git a/crates/ruff_python_formatter/src/statement/stmt_for.rs b/crates/ruff_python_formatter/src/statement/stmt_for.rs index 9b98269d54..51983dadc6 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_for.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_for.rs @@ -7,7 +7,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::{format_args, write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; use ruff_text_size::TextRange; -use rustpython_parser::ast::{Expr, Ranged, Stmt, StmtAsyncFor, StmtFor, Suite}; +use rustpython_ast::{Expr, Ranged, Stmt, StmtAsyncFor, StmtFor, Suite}; #[derive(Debug)] struct ExprTupleWithoutParentheses<'a>(&'a Expr); diff --git a/crates/ruff_python_formatter/src/statement/stmt_function_def.rs b/crates/ruff_python_formatter/src/statement/stmt_function_def.rs index 9c3f04e6a2..fb717bf897 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_function_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_function_def.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, StmtFunctionDef}; +use rustpython_ast::{Ranged, StmtFunctionDef}; use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule}; use ruff_python_ast::function::AnyFunctionDefinition; diff --git a/crates/ruff_python_formatter/src/statement/stmt_global.rs b/crates/ruff_python_formatter/src/statement/stmt_global.rs index ae0da78e2e..7946d0da7b 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_global.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_global.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtGlobal; +use rustpython_ast::StmtGlobal; #[derive(Default)] pub struct FormatStmtGlobal; diff --git a/crates/ruff_python_formatter/src/statement/stmt_if.rs b/crates/ruff_python_formatter/src/statement/stmt_if.rs index 344013a5de..9567d13251 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_if.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_if.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; use ruff_python_ast::node::AnyNodeRef; -use rustpython_parser::ast::{ElifElseClause, StmtIf}; +use rustpython_ast::{ElifElseClause, StmtIf}; #[derive(Default)] pub struct FormatStmtIf; diff --git a/crates/ruff_python_formatter/src/statement/stmt_import.rs b/crates/ruff_python_formatter/src/statement/stmt_import.rs index 10aec39721..9187c1f8c4 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_import.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_import.rs @@ -1,7 +1,7 @@ use crate::{FormatNodeRule, FormattedIterExt, PyFormatter}; use ruff_formatter::prelude::{format_args, format_with, space, text}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtImport; +use rustpython_ast::StmtImport; #[derive(Default)] pub struct FormatStmtImport; diff --git a/crates/ruff_python_formatter/src/statement/stmt_import_from.rs b/crates/ruff_python_formatter/src/statement/stmt_import_from.rs index 6611899906..45d985a744 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_import_from.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_import_from.rs @@ -2,7 +2,7 @@ use crate::builders::{parenthesize_if_expands, PyFormatterExtensions}; use crate::{AsFormat, FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{dynamic_text, format_with, space, text}; use ruff_formatter::{write, Buffer, Format, FormatResult}; -use rustpython_parser::ast::{Ranged, StmtImportFrom}; +use rustpython_ast::{Ranged, StmtImportFrom}; #[derive(Default)] pub struct FormatStmtImportFrom; diff --git a/crates/ruff_python_formatter/src/statement/stmt_match.rs b/crates/ruff_python_formatter/src/statement/stmt_match.rs index 22d76a6676..a70775bdda 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_match.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_match.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtMatch; +use rustpython_ast::StmtMatch; #[derive(Default)] pub struct FormatStmtMatch; diff --git a/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs b/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs index 459a60b057..22d1e0adf2 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtNonlocal; +use rustpython_ast::StmtNonlocal; #[derive(Default)] pub struct FormatStmtNonlocal; diff --git a/crates/ruff_python_formatter/src/statement/stmt_pass.rs b/crates/ruff_python_formatter/src/statement/stmt_pass.rs index 0f324233b2..12dfef06cf 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_pass.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_pass.rs @@ -1,7 +1,7 @@ use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::text; use ruff_formatter::{Format, FormatResult}; -use rustpython_parser::ast::StmtPass; +use rustpython_ast::StmtPass; #[derive(Default)] pub struct FormatStmtPass; diff --git a/crates/ruff_python_formatter/src/statement/stmt_raise.rs b/crates/ruff_python_formatter/src/statement/stmt_raise.rs index 78c8591b5a..f032b2d4e1 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_raise.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_raise.rs @@ -4,7 +4,7 @@ use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, Format, FormatResult}; use crate::expression::maybe_parenthesize_expression; -use rustpython_parser::ast::StmtRaise; +use rustpython_ast::StmtRaise; #[derive(Default)] pub struct FormatStmtRaise; diff --git a/crates/ruff_python_formatter/src/statement/stmt_return.rs b/crates/ruff_python_formatter/src/statement/stmt_return.rs index c298379c47..8678e008c9 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_return.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_return.rs @@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, Format, FormatResult}; -use rustpython_parser::ast::StmtReturn; +use rustpython_ast::StmtReturn; #[derive(Default)] pub struct FormatStmtReturn; diff --git a/crates/ruff_python_formatter/src/statement/stmt_try.rs b/crates/ruff_python_formatter/src/statement/stmt_try.rs index 49bcef4387..e05434c613 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_try.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_try.rs @@ -10,7 +10,7 @@ use ruff_formatter::FormatRuleWithOptions; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::node::AnyNodeRef; use ruff_text_size::TextRange; -use rustpython_parser::ast::{ExceptHandler, Ranged, StmtTry, StmtTryStar, Suite}; +use rustpython_ast::{ExceptHandler, Ranged, StmtTry, StmtTryStar, Suite}; pub(super) enum AnyStatementTry<'a> { Try(&'a StmtTry), diff --git a/crates/ruff_python_formatter/src/statement/stmt_try_star.rs b/crates/ruff_python_formatter/src/statement/stmt_try_star.rs index 3c61258248..888c848433 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_try_star.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_try_star.rs @@ -2,7 +2,7 @@ use crate::statement::stmt_try::AnyStatementTry; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::Format; use ruff_formatter::FormatResult; -use rustpython_parser::ast::StmtTryStar; +use rustpython_ast::StmtTryStar; #[derive(Default)] pub struct FormatStmtTryStar; diff --git a/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs b/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs index bf821e8c3e..292545c182 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs @@ -1,6 +1,6 @@ use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::StmtTypeAlias; +use rustpython_ast::StmtTypeAlias; #[derive(Default)] pub struct FormatStmtTypeAlias; diff --git a/crates/ruff_python_formatter/src/statement/stmt_while.rs b/crates/ruff_python_formatter/src/statement/stmt_while.rs index d89e02fb85..64473f0dd7 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_while.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_while.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::FormatNodeRule; use ruff_formatter::write; use ruff_python_ast::node::AstNode; -use rustpython_parser::ast::{Ranged, Stmt, StmtWhile}; +use rustpython_ast::{Ranged, Stmt, StmtWhile}; #[derive(Default)] pub struct FormatStmtWhile; diff --git a/crates/ruff_python_formatter/src/statement/stmt_with.rs b/crates/ruff_python_formatter/src/statement/stmt_with.rs index 27101752d1..d35170bb7c 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_with.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_with.rs @@ -1,5 +1,5 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{Ranged, StmtAsyncWith, StmtWith, Suite, WithItem}; +use rustpython_ast::{Ranged, StmtAsyncWith, StmtWith, Suite, WithItem}; use ruff_formatter::{format_args, write, FormatError}; use ruff_python_ast::node::AnyNodeRef; diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index 80a61a8a69..1d8d1ef8c0 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{Ranged, Stmt, Suite}; +use rustpython_ast::{Ranged, Stmt, Suite}; use ruff_formatter::{ format_args, write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions, @@ -170,7 +170,7 @@ impl<'ast> IntoFormat> for Suite { #[cfg(test)] mod tests { - use rustpython_parser::ast::Suite; + use rustpython_ast::Suite; use rustpython_parser::Parse; use ruff_formatter::format; diff --git a/crates/ruff_textwrap/Cargo.toml b/crates/ruff_python_index/Cargo.toml similarity index 63% rename from crates/ruff_textwrap/Cargo.toml rename to crates/ruff_python_index/Cargo.toml index 18ecd7ab22..f94cb0b7f1 100644 --- a/crates/ruff_textwrap/Cargo.toml +++ b/crates/ruff_python_index/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ruff_textwrap" +name = "ruff_python_index" version = "0.0.0" publish = false authors = { workspace = true } @@ -10,6 +10,15 @@ documentation = { workspace = true } repository = { workspace = true } license = { workspace = true } +[lib] + [dependencies] ruff_python_trivia = { path = "../ruff_python_trivia" } +rustpython-parser = { workspace = true } ruff_text_size = { workspace = true } +ruff_source_file = { path = "../ruff_source_file" } + +itertools = { workspace = true } +rustpython-ast = { workspace = true } + +[dev-dependencies] diff --git a/crates/ruff_python_ast/src/source_code/comment_ranges.rs b/crates/ruff_python_index/src/comment_ranges.rs similarity index 100% rename from crates/ruff_python_ast/src/source_code/comment_ranges.rs rename to crates/ruff_python_index/src/comment_ranges.rs diff --git a/crates/ruff_python_ast/src/source_code/indexer.rs b/crates/ruff_python_index/src/indexer.rs similarity index 71% rename from crates/ruff_python_ast/src/source_code/indexer.rs rename to crates/ruff_python_index/src/indexer.rs index 2a60e64c86..28f3b2b9cf 100644 --- a/crates/ruff_python_ast/src/source_code/indexer.rs +++ b/crates/ruff_python_index/src/indexer.rs @@ -1,12 +1,14 @@ //! Struct used to index source code, to enable efficient lookup of tokens that //! are omitted from the AST (e.g., commented lines). +use ruff_python_trivia::{has_leading_content, has_trailing_content, is_python_whitespace}; use ruff_text_size::{TextRange, TextSize}; +use rustpython_ast::{Ranged, Stmt}; use rustpython_parser::lexer::LexResult; use rustpython_parser::{StringKind, Tok}; -use crate::source_code::comment_ranges::{CommentRanges, CommentRangesBuilder}; -use crate::source_code::Locator; +use super::comment_ranges::{CommentRanges, CommentRangesBuilder}; +use ruff_source_file::Locator; pub struct Indexer { comment_ranges: CommentRanges, @@ -151,6 +153,113 @@ impl Indexer { }; Some(self.f_string_ranges[string_range_index]) } + + /// Returns `true` if a statement or expression includes at least one comment. + pub fn has_comments(&self, node: &T, locator: &Locator) -> bool + where + T: Ranged, + { + let start = if has_leading_content(node.start(), locator) { + node.start() + } else { + locator.line_start(node.start()) + }; + let end = if has_trailing_content(node.end(), locator) { + node.end() + } else { + locator.line_end(node.end()) + }; + + self.comment_ranges().intersects(TextRange::new(start, end)) + } + + /// Given an offset at the end of a line (including newlines), return the offset of the + /// continuation at the end of that line. + fn find_continuation(&self, offset: TextSize, locator: &Locator) -> Option { + let newline_pos = usize::from(offset).saturating_sub(1); + + // Skip the newline. + let newline_len = match locator.contents().as_bytes()[newline_pos] { + b'\n' => { + if locator + .contents() + .as_bytes() + .get(newline_pos.saturating_sub(1)) + == Some(&b'\r') + { + 2 + } else { + 1 + } + } + b'\r' => 1, + // No preceding line. + _ => return None, + }; + + self.is_continuation(offset - TextSize::from(newline_len), locator) + .then(|| offset - TextSize::from(newline_len) - TextSize::from(1)) + } + + /// If the node starting at the given [`TextSize`] is preceded by at least one continuation line + /// (i.e., a line ending in a backslash), return the starting offset of the first such continuation + /// character. + /// + /// For example, given: + /// ```python + /// x = 1; \ + /// y = 2 + /// ``` + /// + /// When passed the offset of `y`, this function will return the offset of the backslash at the end + /// of the first line. + /// + /// Similarly, given: + /// ```python + /// x = 1; \ + /// \ + /// y = 2; + /// ``` + /// + /// When passed the offset of `y`, this function will again return the offset of the backslash at + /// the end of the first line. + pub fn preceded_by_continuations( + &self, + offset: TextSize, + locator: &Locator, + ) -> Option { + // Find the first preceding continuation. + let mut continuation = self.find_continuation(locator.line_start(offset), locator)?; + + // Continue searching for continuations, in the unlikely event that we have multiple + // continuations in a row. + loop { + let previous_line_end = locator.line_start(continuation); + if locator + .slice(TextRange::new(previous_line_end, continuation)) + .chars() + .all(is_python_whitespace) + { + if let Some(next_continuation) = self.find_continuation(previous_line_end, locator) + { + continuation = next_continuation; + continue; + } + } + break; + } + + Some(continuation) + } + + /// Return `true` if a `Stmt` appears to be part of a multi-statement line, with + /// other statements preceding it. + pub fn preceded_by_multi_statement_line(&self, stmt: &Stmt, locator: &Locator) -> bool { + has_leading_content(stmt.start(), locator) + || self + .preceded_by_continuations(stmt.start(), locator) + .is_some() + } } #[cfg(test)] @@ -159,7 +268,8 @@ mod tests { use rustpython_parser::lexer::LexResult; use rustpython_parser::{lexer, Mode}; - use crate::source_code::{Indexer, Locator}; + use crate::Indexer; + use ruff_source_file::Locator; #[test] fn continuation() { diff --git a/crates/ruff_python_index/src/lib.rs b/crates/ruff_python_index/src/lib.rs new file mode 100644 index 0000000000..a6ed9363ad --- /dev/null +++ b/crates/ruff_python_index/src/lib.rs @@ -0,0 +1,5 @@ +mod comment_ranges; +mod indexer; + +pub use comment_ranges::{CommentRanges, CommentRangesBuilder}; +pub use indexer::Indexer; diff --git a/crates/ruff_rustpython/Cargo.toml b/crates/ruff_python_parser/Cargo.toml similarity index 66% rename from crates/ruff_rustpython/Cargo.toml rename to crates/ruff_python_parser/Cargo.toml index e6c0bc0005..a4fbf550eb 100644 --- a/crates/ruff_rustpython/Cargo.toml +++ b/crates/ruff_python_parser/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ruff_rustpython" +name = "ruff_python_parser" version = "0.0.0" publish = false authors = { workspace = true } @@ -13,5 +13,10 @@ license = { workspace = true } [lib] [dependencies] +ruff_python_ast = { path = "../ruff_python_ast"} +ruff_text_size = { workspace = true } + anyhow = { workspace = true } +is-macro = { workspace = true } +rustpython-ast = { workspace = true } rustpython-parser = { workspace = true } diff --git a/crates/ruff_python_parser/src/lib.rs b/crates/ruff_python_parser/src/lib.rs new file mode 100644 index 0000000000..93c2f85b8e --- /dev/null +++ b/crates/ruff_python_parser/src/lib.rs @@ -0,0 +1,240 @@ +use rustpython_ast::text_size::TextSize; +use rustpython_ast::{CmpOp, Expr, Mod, ModModule, Ranged, Suite}; +use rustpython_parser as parser; +use rustpython_parser::lexer::LexResult; +use rustpython_parser::text_size::TextRange; +use rustpython_parser::{lexer, Mode, ParseError, Tok}; + +pub mod token_kind; +pub mod typing; + +/// Collect tokens up to and including the first error. +pub fn tokenize(contents: &str) -> Vec { + let mut tokens: Vec = vec![]; + for tok in lexer::lex(contents, Mode::Module) { + let is_err = tok.is_err(); + tokens.push(tok); + if is_err { + break; + } + } + tokens +} + +/// Parse a full Python program from its tokens. +pub fn parse_program_tokens( + lxr: Vec, + source_path: &str, +) -> anyhow::Result { + parser::parse_tokens(lxr, Mode::Module, source_path).map(|top| match top { + Mod::Module(ModModule { body, .. }) => body, + _ => unreachable!(), + }) +} + +/// Return the `Range` of the first `Tok::Colon` token in a `Range`. +pub fn first_colon_range(range: TextRange, source: &str) -> Option { + let contents = &source[range]; + let range = lexer::lex_starts_at(contents, Mode::Module, range.start()) + .flatten() + .find(|(tok, _)| tok.is_colon()) + .map(|(_, range)| range); + range +} + +/// Extract all [`CmpOp`] operators from an expression snippet, with appropriate +/// ranges. +/// +/// `RustPython` doesn't include line and column information on [`CmpOp`] nodes. +/// `CPython` doesn't either. This method iterates over the token stream and +/// re-identifies [`CmpOp`] nodes, annotating them with valid ranges. +pub fn locate_cmp_ops(expr: &Expr, source: &str) -> Vec { + // If `Expr` is a multi-line expression, we need to parenthesize it to + // ensure that it's lexed correctly. + let contents = &source[expr.range()]; + let parenthesized_contents = format!("({contents})"); + let mut tok_iter = lexer::lex(&parenthesized_contents, Mode::Expression) + .flatten() + .skip(1) + .map(|(tok, range)| (tok, range - TextSize::from(1))) + .filter(|(tok, _)| !matches!(tok, Tok::NonLogicalNewline | Tok::Comment(_))) + .peekable(); + + let mut ops: Vec = vec![]; + let mut count = 0u32; + loop { + let Some((tok, range)) = tok_iter.next() else { + break; + }; + if matches!(tok, Tok::Lpar) { + count = count.saturating_add(1); + continue; + } else if matches!(tok, Tok::Rpar) { + count = count.saturating_sub(1); + continue; + } + if count == 0 { + match tok { + Tok::Not => { + if let Some((_, next_range)) = + tok_iter.next_if(|(tok, _)| matches!(tok, Tok::In)) + { + ops.push(LocatedCmpOp::new( + TextRange::new(range.start(), next_range.end()), + CmpOp::NotIn, + )); + } + } + Tok::In => { + ops.push(LocatedCmpOp::new(range, CmpOp::In)); + } + Tok::Is => { + let op = if let Some((_, next_range)) = + tok_iter.next_if(|(tok, _)| matches!(tok, Tok::Not)) + { + LocatedCmpOp::new( + TextRange::new(range.start(), next_range.end()), + CmpOp::IsNot, + ) + } else { + LocatedCmpOp::new(range, CmpOp::Is) + }; + ops.push(op); + } + Tok::NotEqual => { + ops.push(LocatedCmpOp::new(range, CmpOp::NotEq)); + } + Tok::EqEqual => { + ops.push(LocatedCmpOp::new(range, CmpOp::Eq)); + } + Tok::GreaterEqual => { + ops.push(LocatedCmpOp::new(range, CmpOp::GtE)); + } + Tok::Greater => { + ops.push(LocatedCmpOp::new(range, CmpOp::Gt)); + } + Tok::LessEqual => { + ops.push(LocatedCmpOp::new(range, CmpOp::LtE)); + } + Tok::Less => { + ops.push(LocatedCmpOp::new(range, CmpOp::Lt)); + } + _ => {} + } + } + } + ops +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct LocatedCmpOp { + pub range: TextRange, + pub op: CmpOp, +} + +impl LocatedCmpOp { + fn new>(range: T, op: CmpOp) -> Self { + Self { + range: range.into(), + op, + } + } +} + +#[cfg(test)] +mod tests { + use crate::{first_colon_range, locate_cmp_ops, LocatedCmpOp}; + use anyhow::Result; + use ruff_text_size::TextSize; + use rustpython_ast::text_size::{TextLen, TextRange}; + use rustpython_ast::CmpOp; + use rustpython_ast::Expr; + use rustpython_parser::Parse; + + #[test] + fn extract_first_colon_range() { + let contents = "with a: pass"; + let range = first_colon_range( + TextRange::new(TextSize::from(0), contents.text_len()), + contents, + ) + .unwrap(); + assert_eq!(&contents[range], ":"); + assert_eq!(range, TextRange::new(TextSize::from(6), TextSize::from(7))); + } + + #[test] + fn extract_cmp_op_location() -> Result<()> { + let contents = "x == 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(4), + CmpOp::Eq + )] + ); + + let contents = "x != 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(4), + CmpOp::NotEq + )] + ); + + let contents = "x is 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(4), + CmpOp::Is + )] + ); + + let contents = "x is not 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(8), + CmpOp::IsNot + )] + ); + + let contents = "x in 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(4), + CmpOp::In + )] + ); + + let contents = "x not in 1"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(8), + CmpOp::NotIn + )] + ); + + let contents = "x != (1 is not 2)"; + let expr = Expr::parse(contents, "")?; + assert_eq!( + locate_cmp_ops(&expr, contents), + vec![LocatedCmpOp::new( + TextSize::from(2)..TextSize::from(4), + CmpOp::NotEq + )] + ); + + Ok(()) + } +} diff --git a/crates/ruff_python_ast/src/token_kind.rs b/crates/ruff_python_parser/src/token_kind.rs similarity index 99% rename from crates/ruff_python_ast/src/token_kind.rs rename to crates/ruff_python_parser/src/token_kind.rs index b031915062..dd18541b67 100644 --- a/crates/ruff_python_ast/src/token_kind.rs +++ b/crates/ruff_python_parser/src/token_kind.rs @@ -1,5 +1,6 @@ use rustpython_parser::Tok; +// TODO move to ruff_python_parser? #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum TokenKind { /// Token value for a name, commonly known as an identifier. diff --git a/crates/ruff_python_ast/src/typing.rs b/crates/ruff_python_parser/src/typing.rs similarity index 90% rename from crates/ruff_python_ast/src/typing.rs rename to crates/ruff_python_parser/src/typing.rs index dacf74e078..552abb513f 100644 --- a/crates/ruff_python_ast/src/typing.rs +++ b/crates/ruff_python_parser/src/typing.rs @@ -1,12 +1,10 @@ use anyhow::Result; +use ruff_python_ast::relocate::relocate_expr; +use ruff_python_ast::str; use ruff_text_size::{TextLen, TextRange}; -use rustpython_parser::ast::Expr; +use rustpython_ast::Expr; use rustpython_parser::Parse; -use crate::relocate::relocate_expr; -use crate::source_code::Locator; -use crate::str; - #[derive(is_macro::Is, Copy, Clone)] pub enum AnnotationKind { /// The annotation is defined as part a simple string literal, @@ -25,9 +23,9 @@ pub enum AnnotationKind { pub fn parse_type_annotation( value: &str, range: TextRange, - locator: &Locator, + source: &str, ) -> Result<(Expr, AnnotationKind)> { - let expression = &locator.contents()[range]; + let expression = &source[range]; if str::raw_contents(expression).map_or(false, |body| body == value) { // The annotation is considered "simple" if and only if the raw representation (e.g., diff --git a/crates/ruff_python_semantic/Cargo.toml b/crates/ruff_python_semantic/Cargo.toml index 08d7ab19c2..1e3ed5f1e2 100644 --- a/crates/ruff_python_semantic/Cargo.toml +++ b/crates/ruff_python_semantic/Cargo.toml @@ -16,6 +16,7 @@ license = { workspace = true } ruff_python_ast = { path = "../ruff_python_ast" } ruff_python_stdlib = { path = "../ruff_python_stdlib" } ruff_text_size = { workspace = true } +ruff_source_file = { path = "../ruff_source_file" } ruff_index = { path = "../ruff_index" } bitflags = { workspace = true } @@ -23,4 +24,5 @@ is-macro = { workspace = true } num-traits = { workspace = true } rustc-hash = { workspace = true } rustpython-parser = { workspace = true } +rustpython-ast = { workspace = true } smallvec = { workspace = true } diff --git a/crates/ruff_python_semantic/src/analyze/branch_detection.rs b/crates/ruff_python_semantic/src/analyze/branch_detection.rs index 5314f2dce5..00a276fecb 100644 --- a/crates/ruff_python_semantic/src/analyze/branch_detection.rs +++ b/crates/ruff_python_semantic/src/analyze/branch_detection.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; use std::iter; -use rustpython_parser::ast::{self, ExceptHandler, Stmt}; +use rustpython_ast::{self as ast, ExceptHandler, Stmt}; use crate::node::{NodeId, Nodes}; diff --git a/crates/ruff_python_semantic/src/analyze/function_type.rs b/crates/ruff_python_semantic/src/analyze/function_type.rs index 95b0f3845e..a39c01f80d 100644 --- a/crates/ruff_python_semantic/src/analyze/function_type.rs +++ b/crates/ruff_python_semantic/src/analyze/function_type.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::Decorator; +use rustpython_ast::Decorator; use ruff_python_ast::call_path::from_qualified_name; use ruff_python_ast::helpers::map_callable; diff --git a/crates/ruff_python_semantic/src/analyze/logging.rs b/crates/ruff_python_semantic/src/analyze/logging.rs index 0aa4624de4..3bb21f701c 100644 --- a/crates/ruff_python_semantic/src/analyze/logging.rs +++ b/crates/ruff_python_semantic/src/analyze/logging.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Keyword}; +use rustpython_ast::{self as ast, Expr, Keyword}; use ruff_python_ast::call_path::{collect_call_path, from_qualified_name}; use ruff_python_ast::helpers::{find_keyword, is_const_true}; diff --git a/crates/ruff_python_semantic/src/analyze/type_inference.rs b/crates/ruff_python_semantic/src/analyze/type_inference.rs index ff8e0fd60d..6a6565d3e6 100644 --- a/crates/ruff_python_semantic/src/analyze/type_inference.rs +++ b/crates/ruff_python_semantic/src/analyze/type_inference.rs @@ -1,7 +1,7 @@ //! Analysis rules to perform basic type inference on individual expressions. +use rustpython_ast::{Constant, Expr}; use rustpython_parser::ast; -use rustpython_parser::ast::{Constant, Expr}; /// An extremely simple type inference system for individual expressions. /// diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index eb74c3e449..6e2aaaacdc 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -1,7 +1,7 @@ //! Analysis rules for the `typing` module. use num_traits::identities::Zero; -use rustpython_parser::ast::{self, Constant, Expr, Operator}; +use rustpython_ast::{self as ast, Constant, Expr, Operator}; use ruff_python_ast::call_path::{from_qualified_name, from_unqualified_name, CallPath}; use ruff_python_ast::helpers::is_const_false; diff --git a/crates/ruff_python_semantic/src/analyze/visibility.rs b/crates/ruff_python_semantic/src/analyze/visibility.rs index e08916f660..c9be45fad7 100644 --- a/crates/ruff_python_semantic/src/analyze/visibility.rs +++ b/crates/ruff_python_semantic/src/analyze/visibility.rs @@ -1,6 +1,6 @@ use std::path::Path; -use rustpython_parser::ast::{self, Decorator, Stmt}; +use rustpython_ast::{self as ast, Decorator, Stmt}; use ruff_python_ast::call_path::{collect_call_path, CallPath}; use ruff_python_ast::helpers::map_callable; diff --git a/crates/ruff_python_semantic/src/binding.rs b/crates/ruff_python_semantic/src/binding.rs index eb93d6ffbd..42ccb1962f 100644 --- a/crates/ruff_python_semantic/src/binding.rs +++ b/crates/ruff_python_semantic/src/binding.rs @@ -2,10 +2,10 @@ use std::ops::{Deref, DerefMut}; use bitflags::bitflags; use ruff_text_size::TextRange; -use rustpython_parser::ast::Ranged; +use rustpython_ast::Ranged; use ruff_index::{newtype_index, IndexSlice, IndexVec}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::context::ExecutionContext; use crate::model::SemanticModel; diff --git a/crates/ruff_python_semantic/src/definition.rs b/crates/ruff_python_semantic/src/definition.rs index ebdf569a98..27bdd15d3d 100644 --- a/crates/ruff_python_semantic/src/definition.rs +++ b/crates/ruff_python_semantic/src/definition.rs @@ -5,7 +5,7 @@ use std::fmt::Debug; use std::ops::Deref; use ruff_index::{newtype_index, IndexSlice, IndexVec}; -use rustpython_parser::ast::{self, Stmt}; +use rustpython_ast::{self as ast, Stmt}; use crate::analyze::visibility::{ class_visibility, function_visibility, method_visibility, ModuleSource, Visibility, diff --git a/crates/ruff_python_semantic/src/globals.rs b/crates/ruff_python_semantic/src/globals.rs index 876ecfb628..ee54b5a4d1 100644 --- a/crates/ruff_python_semantic/src/globals.rs +++ b/crates/ruff_python_semantic/src/globals.rs @@ -6,8 +6,8 @@ use std::ops::Index; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; +use rustpython_ast::Stmt; use rustpython_parser::ast; -use rustpython_parser::ast::Stmt; use ruff_index::{newtype_index, IndexVec}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index a4b50b25ed..1c52a856c3 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -3,7 +3,7 @@ use std::path::Path; use bitflags::bitflags; use ruff_text_size::TextRange; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{Expr, Ranged, Stmt}; +use rustpython_ast::{Expr, Ranged, Stmt}; use smallvec::SmallVec; use ruff_python_ast::call_path::{collect_call_path, from_unqualified_name, CallPath}; diff --git a/crates/ruff_python_semantic/src/node.rs b/crates/ruff_python_semantic/src/node.rs index 6cdafd55b4..319063b1b5 100644 --- a/crates/ruff_python_semantic/src/node.rs +++ b/crates/ruff_python_semantic/src/node.rs @@ -2,7 +2,7 @@ use std::ops::{Index, IndexMut}; use ruff_index::{newtype_index, IndexVec}; use rustc_hash::FxHashMap; -use rustpython_parser::ast::Stmt; +use rustpython_ast::Stmt; use ruff_python_ast::types::RefEquality; diff --git a/crates/ruff_python_semantic/src/reference.rs b/crates/ruff_python_semantic/src/reference.rs index 75126ba1d4..6c3201f538 100644 --- a/crates/ruff_python_semantic/src/reference.rs +++ b/crates/ruff_python_semantic/src/reference.rs @@ -3,7 +3,7 @@ use ruff_text_size::TextRange; use std::ops::Deref; use ruff_index::{newtype_index, IndexSlice, IndexVec}; -use ruff_python_ast::source_code::Locator; +use ruff_source_file::Locator; use crate::context::ExecutionContext; use crate::scope::ScopeId; diff --git a/crates/ruff_python_trivia/Cargo.toml b/crates/ruff_python_trivia/Cargo.toml index 716248abcf..da9d7c1ac8 100644 --- a/crates/ruff_python_trivia/Cargo.toml +++ b/crates/ruff_python_trivia/Cargo.toml @@ -14,6 +14,7 @@ license = { workspace = true } [dependencies] ruff_text_size = { workspace = true } +ruff_source_file = { path = "../ruff_source_file" } memchr = { workspace = true } smallvec = { workspace = true } @@ -21,3 +22,5 @@ unic-ucd-ident = "0.9.0" [dev-dependencies] insta = { workspace = true } +rustpython-parser = { workspace = true } +rustpython-ast = { workspace = true } diff --git a/crates/ruff_python_trivia/src/lib.rs b/crates/ruff_python_trivia/src/lib.rs index 4e16d7ca2d..bef83ac26a 100644 --- a/crates/ruff_python_trivia/src/lib.rs +++ b/crates/ruff_python_trivia/src/lib.rs @@ -1,9 +1,8 @@ mod cursor; -mod newlines; +pub mod textwrap; mod tokenizer; mod whitespace; pub use cursor::*; -pub use newlines::*; pub use tokenizer::*; pub use whitespace::*; diff --git a/crates/ruff_textwrap/src/lib.rs b/crates/ruff_python_trivia/src/textwrap.rs similarity index 96% rename from crates/ruff_textwrap/src/lib.rs rename to crates/ruff_python_trivia/src/textwrap.rs index d3bf9975a8..33d92c0205 100644 --- a/crates/ruff_textwrap/src/lib.rs +++ b/crates/ruff_python_trivia/src/textwrap.rs @@ -4,14 +4,15 @@ use std::borrow::Cow; use std::cmp; -use ruff_python_trivia::{PythonWhitespace, UniversalNewlines}; +use crate::PythonWhitespace; +use ruff_source_file::newlines::UniversalNewlines; /// Indent each line by the given prefix. /// /// # Examples /// /// ``` -/// use ruff_textwrap::indent; +/// # use ruff_python_trivia::textwrap::indent; /// /// assert_eq!(indent("First line.\nSecond line.\n", " "), /// " First line.\n Second line.\n"); @@ -21,7 +22,7 @@ use ruff_python_trivia::{PythonWhitespace, UniversalNewlines}; /// This means that empty lines remain empty afterwards: /// /// ``` -/// use ruff_textwrap::indent; +/// # use ruff_python_trivia::textwrap::indent; /// /// assert_eq!(indent("First line.\n\n\nSecond line.\n", " "), /// " First line.\n\n\n Second line.\n"); @@ -34,7 +35,7 @@ use ruff_python_trivia::{PythonWhitespace, UniversalNewlines}; /// want a trailing space on empty lines: /// /// ``` -/// use ruff_textwrap::indent; +/// # use ruff_python_trivia::textwrap::indent; /// /// assert_eq!(indent("foo = 123\n\nprint(foo)\n", "# "), /// "# foo = 123\n#\n# print(foo)\n"); @@ -47,7 +48,7 @@ use ruff_python_trivia::{PythonWhitespace, UniversalNewlines}; /// kept unchanged: /// /// ``` -/// use ruff_textwrap::indent; +/// # use ruff_python_trivia::textwrap::indent; /// /// assert_eq!(indent(" \t Foo ", "->"), "-> \t Foo "); /// ``` @@ -75,7 +76,7 @@ pub fn indent<'a>(text: &'a str, prefix: &str) -> Cow<'a, str> { /// maximum amount of whitespace that can be removed from all lines: /// /// ``` -/// use ruff_textwrap::dedent; +/// # use ruff_python_trivia::textwrap::dedent; /// /// assert_eq!(dedent(" /// 1st line diff --git a/crates/ruff_python_trivia/src/tokenizer.rs b/crates/ruff_python_trivia/src/tokenizer.rs index 40b4df599d..896bc44559 100644 --- a/crates/ruff_python_trivia/src/tokenizer.rs +++ b/crates/ruff_python_trivia/src/tokenizer.rs @@ -189,6 +189,9 @@ pub enum SimpleTokenKind { /// `if` If, + /// `elif` + Elif, + /// `in` In, @@ -295,6 +298,7 @@ impl<'a> SimpleTokenizer<'a> { "as" => SimpleTokenKind::As, "async" => SimpleTokenKind::Async, "else" => SimpleTokenKind::Else, + "elif" => SimpleTokenKind::Elif, "if" => SimpleTokenKind::If, "in" => SimpleTokenKind::In, "match" => SimpleTokenKind::Match, // Match is a soft keyword that depends on the context but we can always lex it as a keyword and leave it to the caller (parser) to decide if it should be handled as an identifier or keyword. diff --git a/crates/ruff_python_trivia/src/whitespace.rs b/crates/ruff_python_trivia/src/whitespace.rs index 8bb161aba3..6688bd15c5 100644 --- a/crates/ruff_python_trivia/src/whitespace.rs +++ b/crates/ruff_python_trivia/src/whitespace.rs @@ -1,3 +1,41 @@ +use ruff_source_file::Locator; +use ruff_text_size::{TextRange, TextSize}; + +/// Extract the leading indentation from a line. +pub fn indentation_at_offset<'a>(locator: &'a Locator, offset: TextSize) -> Option<&'a str> { + let line_start = locator.line_start(offset); + let indentation = &locator.contents()[TextRange::new(line_start, offset)]; + + if indentation.chars().all(is_python_whitespace) { + Some(indentation) + } else { + None + } +} + +/// Return `true` if the node starting the given [`TextSize`] has leading content. +pub fn has_leading_content(offset: TextSize, locator: &Locator) -> bool { + let line_start = locator.line_start(offset); + let leading = &locator.contents()[TextRange::new(line_start, offset)]; + leading.chars().any(|char| !is_python_whitespace(char)) +} + +/// Return `true` if the node ending at the given [`TextSize`] has trailing content. +pub fn has_trailing_content(offset: TextSize, locator: &Locator) -> bool { + let line_end = locator.line_end(offset); + let trailing = &locator.contents()[TextRange::new(offset, line_end)]; + + for char in trailing.chars() { + if char == '#' { + return false; + } + if !is_python_whitespace(char) { + return true; + } + } + false +} + /// Returns `true` for [whitespace](https://docs.python.org/3/reference/lexical_analysis.html#whitespace-between-tokens) /// characters. pub const fn is_python_whitespace(c: char) -> bool { @@ -41,3 +79,50 @@ impl PythonWhitespace for str { self.trim_end_matches(is_python_whitespace) } } + +#[cfg(test)] +mod tests { + use crate::has_trailing_content; + use ruff_source_file::Locator; + use rustpython_ast::{Ranged, Suite}; + use rustpython_parser::{Parse, ParseError}; + + #[test] + fn trailing_content() -> Result<(), ParseError> { + let contents = "x = 1"; + let program = Suite::parse(contents, "")?; + let stmt = program.first().unwrap(); + let locator = Locator::new(contents); + assert!(!has_trailing_content(stmt.end(), &locator)); + + let contents = "x = 1; y = 2"; + let program = Suite::parse(contents, "")?; + let stmt = program.first().unwrap(); + let locator = Locator::new(contents); + assert!(has_trailing_content(stmt.end(), &locator)); + + let contents = "x = 1 "; + let program = Suite::parse(contents, "")?; + let stmt = program.first().unwrap(); + let locator = Locator::new(contents); + assert!(!has_trailing_content(stmt.end(), &locator)); + + let contents = "x = 1 # Comment"; + let program = Suite::parse(contents, "")?; + let stmt = program.first().unwrap(); + let locator = Locator::new(contents); + assert!(!has_trailing_content(stmt.end(), &locator)); + + let contents = r#" +x = 1 +y = 2 +"# + .trim(); + let program = Suite::parse(contents, "")?; + let stmt = program.first().unwrap(); + let locator = Locator::new(contents); + assert!(!has_trailing_content(stmt.end(), &locator)); + + Ok(()) + } +} diff --git a/crates/ruff_rustpython/src/lib.rs b/crates/ruff_rustpython/src/lib.rs deleted file mode 100644 index c0fcd72e28..0000000000 --- a/crates/ruff_rustpython/src/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -use rustpython_parser as parser; -use rustpython_parser::ast::{Mod, ModModule, Suite}; -use rustpython_parser::lexer::LexResult; -use rustpython_parser::{lexer, Mode, ParseError}; - -/// Collect tokens up to and including the first error. -pub fn tokenize(contents: &str) -> Vec { - let mut tokens: Vec = vec![]; - for tok in lexer::lex(contents, Mode::Module) { - let is_err = tok.is_err(); - tokens.push(tok); - if is_err { - break; - } - } - tokens -} - -/// Parse a full Python program from its tokens. -pub fn parse_program_tokens( - lxr: Vec, - source_path: &str, -) -> anyhow::Result { - parser::parse_tokens(lxr, Mode::Module, source_path).map(|top| match top { - Mod::Module(ModModule { body, .. }) => body, - _ => unreachable!(), - }) -} diff --git a/crates/ruff_shrinking/Cargo.toml b/crates/ruff_shrinking/Cargo.toml index 286bf82328..e20d8a783c 100644 --- a/crates/ruff_shrinking/Cargo.toml +++ b/crates/ruff_shrinking/Cargo.toml @@ -11,7 +11,7 @@ clap = { workspace = true } fs-err = "2.9.0" regex = { workspace = true } ruff_python_ast = { path = "../ruff_python_ast" } -ruff_rustpython = { path = "../ruff_rustpython" } +ruff_python_parser = { path = "../ruff_python_parser" } rustpython-ast = { workspace = true } shlex = "1.1.0" tracing = "0.1.37" diff --git a/crates/ruff_shrinking/src/main.rs b/crates/ruff_shrinking/src/main.rs index 0d8c8cd6af..1808c1e47a 100644 --- a/crates/ruff_shrinking/src/main.rs +++ b/crates/ruff_shrinking/src/main.rs @@ -275,7 +275,7 @@ impl Strategy for StrategyRemoveToken { input: &'a str, _ast: &'a Suite, ) -> Result> { - let token_ranges: Vec<_> = ruff_rustpython::tokenize(input) + let token_ranges: Vec<_> = ruff_python_parser::tokenize(input) .into_iter() // At this point we know we have valid python code .map(Result::unwrap) @@ -320,9 +320,9 @@ fn minimization_step( pattern: &Regex, last_strategy_and_idx: Option<(&'static dyn Strategy, usize)>, ) -> Result> { - let tokens = ruff_rustpython::tokenize(input); + let tokens = ruff_python_parser::tokenize(input); let ast = - ruff_rustpython::parse_program_tokens(tokens, "input.py").context("not valid python")?; + ruff_python_parser::parse_program_tokens(tokens, "input.py").context("not valid python")?; // Try the last succeeding strategy first, skipping all that failed last time if let Some((last_strategy, last_idx)) = last_strategy_and_idx { diff --git a/crates/ruff_source_file/Cargo.toml b/crates/ruff_source_file/Cargo.toml new file mode 100644 index 0000000000..bd760d785a --- /dev/null +++ b/crates/ruff_source_file/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "ruff_source_file" +version = "0.0.0" +publish = false +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +documentation = { workspace = true } +repository = { workspace = true } +license = { workspace = true } + +[lib] + +[dependencies] +memchr = { workspace = true } +once_cell = { workspace = true } +ruff_text_size = { workspace = true } +serde = { workspace = true, optional = true } + +[dev-dependencies] +insta = { workspace = true } + + +[features] +serde = ["dep:serde", "ruff_text_size/serde"] diff --git a/crates/ruff_python_ast/src/source_code/mod.rs b/crates/ruff_source_file/src/lib.rs similarity index 87% rename from crates/ruff_python_ast/src/source_code/mod.rs rename to crates/ruff_source_file/src/lib.rs index 829cc98515..bd5f2fc6a4 100644 --- a/crates/ruff_python_ast/src/source_code/mod.rs +++ b/crates/ruff_source_file/src/lib.rs @@ -3,35 +3,19 @@ use std::fmt::{Debug, Formatter}; use std::sync::Arc; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::{ast, lexer, Mode, Parse, ParseError}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -pub use comment_ranges::{CommentRanges, CommentRangesBuilder}; -pub use generator::Generator; -pub use indexer::Indexer; -pub use locator::Locator; -pub use stylist::{Quote, Stylist}; - -pub use crate::source_code::line_index::{LineIndex, OneIndexed}; - -mod comment_ranges; -mod generator; -mod indexer; -mod line_index; +pub mod line_index; mod locator; -mod stylist; +pub mod newlines; -/// Run round-trip source code generation on a given Python code. -pub fn round_trip(code: &str, source_path: &str) -> Result { - let locator = Locator::new(code); - let python_ast = ast::Suite::parse(code, source_path)?; - let tokens: Vec<_> = lexer::lex(code, Mode::Module).collect(); - let stylist = Stylist::from_tokens(&tokens, &locator); - let mut generator: Generator = (&stylist).into(); - generator.unparse_suite(&python_ast); - Ok(generator.generate()) -} +pub use crate::line_index::{LineIndex, OneIndexed}; +pub use locator::Locator; +pub use newlines::{ + find_newline, Line, LineEnding, NewlineWithTrailingNewline, UniversalNewlineIterator, + UniversalNewlines, +}; /// Gives access to the source code of a file and allows mapping between [`TextSize`] and [`SourceLocation`]. #[derive(Debug)] diff --git a/crates/ruff_python_ast/src/source_code/line_index.rs b/crates/ruff_source_file/src/line_index.rs similarity index 96% rename from crates/ruff_python_ast/src/source_code/line_index.rs rename to crates/ruff_source_file/src/line_index.rs index 157d75868e..9bf7b20985 100644 --- a/crates/ruff_python_ast/src/source_code/line_index.rs +++ b/crates/ruff_source_file/src/line_index.rs @@ -8,7 +8,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use crate::source_code::SourceLocation; +use crate::SourceLocation; /// Index for fast [byte offset](TextSize) to [`SourceLocation`] conversions. /// @@ -70,7 +70,7 @@ impl LineIndex { /// /// ``` /// # use ruff_text_size::TextSize; - /// # use ruff_python_ast::source_code::{LineIndex, OneIndexed, SourceLocation}; + /// # use ruff_source_file::{LineIndex, OneIndexed, SourceLocation}; /// let source = "def a():\n pass"; /// let index = LineIndex::from_source_text(source); /// @@ -124,7 +124,7 @@ impl LineIndex { } /// Return the number of lines in the source code. - pub(crate) fn line_count(&self) -> usize { + pub fn line_count(&self) -> usize { self.line_starts().len() } @@ -134,7 +134,7 @@ impl LineIndex { /// /// ``` /// # use ruff_text_size::TextSize; - /// # use ruff_python_ast::source_code::{LineIndex, OneIndexed, SourceLocation}; + /// # use ruff_source_file::{LineIndex, OneIndexed, SourceLocation}; /// let source = "def a():\n pass"; /// let index = LineIndex::from_source_text(source); /// @@ -158,7 +158,7 @@ impl LineIndex { } /// Returns the [byte offset](TextSize) for the `line` with the given index. - pub(crate) fn line_start(&self, line: OneIndexed, contents: &str) -> TextSize { + pub fn line_start(&self, line: OneIndexed, contents: &str) -> TextSize { let row_index = line.to_zero_indexed(); let starts = self.line_starts(); @@ -172,7 +172,7 @@ impl LineIndex { /// Returns the [byte offset](TextSize) of the `line`'s end. /// The offset is the end of the line, up to and including the newline character ending the line (if any). - pub(crate) fn line_end(&self, line: OneIndexed, contents: &str) -> TextSize { + pub fn line_end(&self, line: OneIndexed, contents: &str) -> TextSize { let row_index = line.to_zero_indexed(); let starts = self.line_starts(); @@ -187,7 +187,7 @@ impl LineIndex { /// Returns the [`TextRange`] of the `line` with the given index. /// The start points to the first character's [byte offset](TextSize), the end up to, and including /// the newline character ending the line (if any). - pub(crate) fn line_range(&self, line: OneIndexed, contents: &str) -> TextRange { + pub fn line_range(&self, line: OneIndexed, contents: &str) -> TextRange { let starts = self.line_starts(); if starts.len() == line.to_zero_indexed() { @@ -315,8 +315,8 @@ const fn unwrap(option: Option) -> T { mod tests { use ruff_text_size::TextSize; - use crate::source_code::line_index::LineIndex; - use crate::source_code::{OneIndexed, SourceLocation}; + use crate::line_index::LineIndex; + use crate::{OneIndexed, SourceLocation}; #[test] fn ascii_index() { diff --git a/crates/ruff_python_ast/src/source_code/locator.rs b/crates/ruff_source_file/src/locator.rs similarity index 94% rename from crates/ruff_python_ast/src/source_code/locator.rs rename to crates/ruff_source_file/src/locator.rs index fc982889eb..f2b1a836d0 100644 --- a/crates/ruff_python_ast/src/source_code/locator.rs +++ b/crates/ruff_source_file/src/locator.rs @@ -6,9 +6,8 @@ use memchr::{memchr2, memrchr2}; use once_cell::unsync::OnceCell; use ruff_text_size::{TextLen, TextRange, TextSize}; -use ruff_python_trivia::find_newline; - -use crate::source_code::{LineIndex, OneIndexed, SourceCode, SourceLocation}; +use crate::newlines::find_newline; +use crate::{LineIndex, OneIndexed, SourceCode, SourceLocation}; pub struct Locator<'a> { contents: &'a str, @@ -59,7 +58,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::TextSize; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\rthird line"); /// @@ -93,7 +92,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -120,7 +119,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -150,7 +149,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -174,7 +173,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -197,7 +196,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -220,7 +219,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -244,7 +243,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -276,7 +275,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -300,7 +299,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -325,7 +324,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// @@ -353,7 +352,7 @@ impl<'a> Locator<'a> { /// /// ``` /// # use ruff_text_size::{TextRange, TextSize}; - /// # use ruff_python_ast::source_code::Locator; + /// # use ruff_source_file::Locator; /// /// let locator = Locator::new("First line\nsecond line\r\nthird line"); /// diff --git a/crates/ruff_python_trivia/src/newlines.rs b/crates/ruff_source_file/src/newlines.rs similarity index 99% rename from crates/ruff_python_trivia/src/newlines.rs rename to crates/ruff_source_file/src/newlines.rs index 531657f44c..91cb953dc7 100644 --- a/crates/ruff_python_trivia/src/newlines.rs +++ b/crates/ruff_source_file/src/newlines.rs @@ -22,7 +22,7 @@ impl UniversalNewlines for str { /// /// ```rust /// # use ruff_text_size::TextSize; -/// # use ruff_python_trivia::{Line, UniversalNewlineIterator}; +/// # use ruff_source_file::{Line, UniversalNewlineIterator}; /// let mut lines = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop"); /// /// assert_eq!(lines.next_back(), Some(Line::new("bop", TextSize::from(14)))); diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index bf1fb2e08a..5304225dbd 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -21,8 +21,11 @@ default = ["console_error_panic_hook"] ruff = { path = "../ruff" } ruff_diagnostics = { path = "../ruff_diagnostics" } ruff_python_ast = { path = "../ruff_python_ast" } +ruff_python_codegen = { path = "../ruff_python_codegen" } ruff_python_formatter = { path = "../ruff_python_formatter" } -ruff_rustpython = { path = "../ruff_rustpython" } +ruff_python_index = { path = "../ruff_python_index" } +ruff_python_parser = { path = "../ruff_python_parser" } +ruff_source_file = { path = "../ruff_source_file" } console_error_panic_hook = { version = "0.1.7", optional = true } console_log = { version = "1.0.0" } diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index 12887cc0c3..c937f65aa7 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -21,10 +21,10 @@ use ruff::rules::{ use ruff::settings::configuration::Configuration; use ruff::settings::options::Options; use ruff::settings::{defaults, flags, Settings}; -use ruff_python_ast::source_code::{ - CommentRangesBuilder, Indexer, Locator, SourceLocation, Stylist, -}; +use ruff_python_codegen::Stylist; use ruff_python_formatter::{format_module, format_node, PyFormatOptions}; +use ruff_python_index::{CommentRangesBuilder, Indexer}; +use ruff_source_file::{Locator, SourceLocation}; #[wasm_bindgen(typescript_custom_section)] const TYPES: &'static str = r#" @@ -197,7 +197,7 @@ impl Workspace { pub fn check(&self, contents: &str) -> Result { // Tokenize once. - let tokens: Vec = ruff_rustpython::tokenize(contents); + let tokens: Vec = ruff_python_parser::tokenize(contents); // Map row and column locations to byte slices (lazily). let locator = Locator::new(contents); diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index 9900f4243a..85cae83782 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -3,7 +3,7 @@ use wasm_bindgen_test::wasm_bindgen_test; use ruff::registry::Rule; -use ruff_python_ast::source_code::{OneIndexed, SourceLocation}; +use ruff_source_file::{OneIndexed, SourceLocation}; use ruff_wasm::{ExpandedMessage, Workspace}; macro_rules! check { diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 62708af4ec..d57de87402 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -21,10 +21,13 @@ arbitrary = { version = "1.3.0", features = ["derive"] } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false } ruff = { path = "../crates/ruff" } ruff_python_ast = { path = "../crates/ruff_python_ast" } +ruff_python_codegen = { path = "../crates/ruff_python_codegen" } ruff_python_formatter = { path = "../crates/ruff_python_formatter" } +ruff_source_file = { path = "../crates/ruff_source_file" } similar = { version = "2.2.1" } rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" } +rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" } # Prevent this from interfering with workspaces [workspace] diff --git a/fuzz/fuzz_targets/ruff_parse_idempotency.rs b/fuzz/fuzz_targets/ruff_parse_idempotency.rs index ac4387e3b4..8dc7d361a8 100644 --- a/fuzz/fuzz_targets/ruff_parse_idempotency.rs +++ b/fuzz/fuzz_targets/ruff_parse_idempotency.rs @@ -4,11 +4,13 @@ #![no_main] use libfuzzer_sys::{fuzz_target, Corpus}; -use ruff_python_ast::source_code::round_trip; +use ruff_python_codegen::round_trip; use similar::TextDiff; fn do_fuzz(case: &[u8]) -> Corpus { - let Ok(code) = std::str::from_utf8(case) else { return Corpus::Reject; }; + let Ok(code) = std::str::from_utf8(case) else { + return Corpus::Reject; + }; // round trip it once to get a formatted version if let Ok(first) = round_trip(code, "fuzzed-source.py") { diff --git a/fuzz/fuzz_targets/ruff_parse_simple.rs b/fuzz/fuzz_targets/ruff_parse_simple.rs index 9eda53e05f..880616369e 100644 --- a/fuzz/fuzz_targets/ruff_parse_simple.rs +++ b/fuzz/fuzz_targets/ruff_parse_simple.rs @@ -4,12 +4,15 @@ #![no_main] use libfuzzer_sys::{fuzz_target, Corpus}; -use ruff_python_ast::source_code::{Generator, Locator, Stylist}; -use rustpython_parser::ast::Suite; +use ruff_python_codegen::{Generator, Stylist}; +use ruff_source_file::Locator; +use rustpython_ast::Suite; use rustpython_parser::{lexer, Mode, Parse, ParseError}; fn do_fuzz(case: &[u8]) -> Corpus { - let Ok(code) = std::str::from_utf8(case) else { return Corpus::Reject; }; + let Ok(code) = std::str::from_utf8(case) else { + return Corpus::Reject; + }; // just round-trip it once to trigger both parse and unparse let locator = Locator::new(code);