mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
Move universal newline handling into its own crate (#4729)
This commit is contained in:
parent
e209b5fc5f
commit
9d0ffd33ca
49 changed files with 80 additions and 51 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -1792,6 +1792,7 @@ dependencies = [
|
|||
"ruff_cache",
|
||||
"ruff_diagnostics",
|
||||
"ruff_macros",
|
||||
"ruff_newlines",
|
||||
"ruff_python_ast",
|
||||
"ruff_python_semantic",
|
||||
"ruff_python_stdlib",
|
||||
|
@ -1959,6 +1960,14 @@ dependencies = [
|
|||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_newlines"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"ruff_text_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_python_ast"
|
||||
version = "0.0.0"
|
||||
|
@ -1973,6 +1982,7 @@ dependencies = [
|
|||
"num-bigint",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"ruff_newlines",
|
||||
"ruff_text_size",
|
||||
"rustc-hash",
|
||||
"rustpython-ast",
|
||||
|
@ -1994,6 +2004,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"once_cell",
|
||||
"ruff_formatter",
|
||||
"ruff_newlines",
|
||||
"ruff_python_ast",
|
||||
"ruff_testing_macros",
|
||||
"ruff_text_size",
|
||||
|
|
|
@ -17,6 +17,7 @@ name = "ruff"
|
|||
ruff_cache = { path = "../ruff_cache" }
|
||||
ruff_diagnostics = { path = "../ruff_diagnostics", features = ["serde"] }
|
||||
ruff_macros = { path = "../ruff_macros" }
|
||||
ruff_newlines = { path = "../ruff_newlines" }
|
||||
ruff_python_ast = { path = "../ruff_python_ast", features = ["serde"] }
|
||||
ruff_python_semantic = { path = "../ruff_python_semantic" }
|
||||
ruff_python_stdlib = { path = "../ruff_python_stdlib" }
|
||||
|
|
|
@ -9,8 +9,8 @@ use rustpython_parser::ast::{self, Excepthandler, Expr, Keyword, Ranged, Stmt};
|
|||
use rustpython_parser::{lexer, Mode, Tok};
|
||||
|
||||
use ruff_diagnostics::Edit;
|
||||
use ruff_newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::helpers;
|
||||
use ruff_python_ast::newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
||||
|
||||
use crate::cst::helpers::compose_module_path;
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruff_text_size::TextSize;
|
|||
use std::path::Path;
|
||||
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
||||
|
||||
use crate::registry::Rule;
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt, Suite};
|
|||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::Tok;
|
||||
|
||||
use ruff_python_ast::newlines::UniversalNewlineIterator;
|
||||
use ruff_newlines::UniversalNewlineIterator;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::iter::FusedIterator;
|
|||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_python_ast::whitespace;
|
||||
|
||||
use crate::docstrings::styles::SectionStyle;
|
||||
|
|
|
@ -143,7 +143,7 @@ mod tests {
|
|||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::Parse;
|
||||
|
||||
use ruff_python_ast::newlines::LineEnding;
|
||||
use ruff_newlines::LineEnding;
|
||||
use ruff_python_ast::source_code::{Locator, Stylist};
|
||||
|
||||
use super::Insertion;
|
||||
|
|
|
@ -11,7 +11,7 @@ use regex::Regex;
|
|||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_python_ast::newlines::LineEnding;
|
||||
use ruff_newlines::LineEnding;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
use crate::codes::NoqaCode;
|
||||
|
@ -514,7 +514,7 @@ mod tests {
|
|||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_python_ast::newlines::LineEnding;
|
||||
use ruff_newlines::LineEnding;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
use crate::noqa::{add_noqa_inner, NoqaMapping, NOQA_LINE_REGEX};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_text_size::TextSize;
|
||||
use rustpython_parser::ast::{Expr, Ranged, Stmt};
|
||||
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
/// Return `true` if a function's return statement include at least one
|
||||
|
|
|
@ -5,11 +5,11 @@ use rustpython_parser::ast::{self, Cmpop, Constant, Expr, ExprContext, Ranged, S
|
|||
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::comparable::{ComparableConstant, ComparableExpr, ComparableStmt};
|
||||
use ruff_python_ast::helpers::{
|
||||
any_over_expr, contains_effect, first_colon_range, has_comments, has_comments_in,
|
||||
};
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_python_semantic::model::SemanticModel;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -5,8 +5,8 @@ use rustpython_parser::ast::{self, Ranged, Stmt, Withitem};
|
|||
use ruff_diagnostics::{AutofixKind, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::helpers::{first_colon_range, has_comments_in};
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::line_width::LineWidth;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustpython_parser::ast::{Ranged, Stmt};
|
||||
use rustpython_parser::{lexer, Mode, Tok};
|
||||
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
use crate::rules::isort::types::TrailingComma;
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_text_size::{TextLen, TextRange};
|
|||
use rustpython_parser::ast::{self, Cmpop, Expr};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
use ruff_python_ast::source_code::Generator;
|
||||
|
||||
use crate::line_width::{LineLength, LineWidth, TabSize};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
use crate::rules::pycodestyle::helpers::is_overlong;
|
||||
use crate::settings::Settings;
|
||||
|
|
|
@ -3,8 +3,8 @@ use rustpython_parser::ast::{self, Arg, Arguments, Constant, Expr, Ranged, Stmt}
|
|||
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::helpers::{has_leading_content, has_trailing_content};
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_python_ast::source_code::Generator;
|
||||
use ruff_python_ast::whitespace::leading_space;
|
||||
use ruff_python_semantic::model::SemanticModel;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
use crate::rules::pycodestyle::helpers::is_overlong;
|
||||
use crate::settings::Settings;
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_text_size::{TextLen, TextRange};
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
use ruff_python_ast::whitespace::leading_space;
|
||||
|
||||
/// ## What it does
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
use ruff_python_ast::source_code::Indexer;
|
||||
use ruff_python_ast::whitespace::leading_space;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ 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::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::call_path::from_qualified_name;
|
||||
use ruff_python_ast::cast;
|
||||
use ruff_python_ast::helpers::map_callable;
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_python_ast::str::is_implicit_concatenation;
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
use ruff_python_semantic::model::SemanticModel;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::docstrings::Docstring;
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustpython_parser::ast::Ranged;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustpython_parser::ast::Ranged;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -3,7 +3,7 @@ use strum::IntoEnumIterator;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::docstrings::sections::SectionKind;
|
||||
|
|
|
@ -3,7 +3,7 @@ use strum::IntoEnumIterator;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{StrExt, UniversalNewlineIterator};
|
||||
use ruff_newlines::{StrExt, UniversalNewlineIterator};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::docstrings::sections::SectionKind;
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_text_size::{TextLen, TextRange};
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::NewlineWithTrailingNewline;
|
||||
use ruff_newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::whitespace;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustpython_parser::ast::Ranged;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{NewlineWithTrailingNewline, UniversalNewlineIterator};
|
||||
use ruff_newlines::{NewlineWithTrailingNewline, UniversalNewlineIterator};
|
||||
use ruff_python_ast::str::{is_triple_quote, leading_quote};
|
||||
use ruff_python_semantic::definition::{Definition, Member};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustpython_parser::ast::Ranged;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::{NewlineWithTrailingNewline, StrExt};
|
||||
use ruff_newlines::{NewlineWithTrailingNewline, StrExt};
|
||||
use ruff_python_ast::whitespace;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Stmt};
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -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_ast::newlines::NewlineWithTrailingNewline;
|
||||
use ruff_newlines::NewlineWithTrailingNewline;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::docstrings::Docstring;
|
||||
|
|
|
@ -5,9 +5,9 @@ use once_cell::sync::Lazy;
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_newlines::StrExt;
|
||||
use ruff_python_ast::call_path::{from_qualified_name, CallPath};
|
||||
use ruff_python_ast::cast;
|
||||
use ruff_python_ast::newlines::StrExt;
|
||||
use ruff_python_semantic::analyze::visibility::{is_property, is_test};
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::NewlineWithTrailingNewline;
|
||||
use ruff_newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::str::{leading_quote, trailing_quote};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -8,8 +8,8 @@ use rustpython_parser::ast::{self, Stmt};
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::helpers::identifier_range;
|
||||
use ruff_python_ast::newlines::NewlineWithTrailingNewline;
|
||||
use ruff_python_ast::{cast, whitespace};
|
||||
use ruff_python_semantic::analyze::visibility::is_staticmethod;
|
||||
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
/// ## What it does
|
||||
/// Check for `noqa` annotations that suppress all diagnostics, as opposed to
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
/// ## What it does
|
||||
/// Check for `type: ignore` annotations that suppress all type warnings, as
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
const BIDI_UNICODE: [char; 10] = [
|
||||
'\u{202A}', //{LEFT-TO-RIGHT EMBEDDING}
|
||||
|
|
|
@ -3,7 +3,7 @@ use regex::Regex;
|
|||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::newlines::Line;
|
||||
use ruff_newlines::Line;
|
||||
|
||||
// TODO: document referencing [PEP 3120]: https://peps.python.org/pep-3120/
|
||||
#[violation]
|
||||
|
|
13
crates/ruff_newlines/Cargo.toml
Normal file
13
crates/ruff_newlines/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "ruff_newlines"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
ruff_text_size = { workspace = true }
|
||||
|
||||
memchr = { workspace = true }
|
|
@ -22,7 +22,7 @@ impl StrExt for str {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use ruff_text_size::TextSize;
|
||||
/// # use ruff_python_ast::newlines::{Line, UniversalNewlineIterator};
|
||||
/// # use ruff_newlines::{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))));
|
||||
|
@ -340,9 +340,7 @@ impl Deref for LineEnding {
|
|||
mod tests {
|
||||
use ruff_text_size::TextSize;
|
||||
|
||||
use crate::newlines::Line;
|
||||
|
||||
use super::UniversalNewlineIterator;
|
||||
use super::{Line, UniversalNewlineIterator};
|
||||
|
||||
#[test]
|
||||
fn universal_newlines_empty_str() {
|
|
@ -8,6 +8,7 @@ rust-version = { workspace = true }
|
|||
[lib]
|
||||
|
||||
[dependencies]
|
||||
ruff_newlines = { path = "../ruff_newlines" }
|
||||
ruff_text_size = { workspace = true }
|
||||
|
||||
anyhow = { workspace = true }
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::path::Path;
|
|||
use itertools::Itertools;
|
||||
use log::error;
|
||||
use num_traits::Zero;
|
||||
use ruff_newlines::UniversalNewlineIterator;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use rustpython_parser::ast::{
|
||||
|
@ -14,7 +15,6 @@ use rustpython_parser::{lexer, Mode, Tok};
|
|||
use smallvec::SmallVec;
|
||||
|
||||
use crate::call_path::CallPath;
|
||||
use crate::newlines::UniversalNewlineIterator;
|
||||
use crate::source_code::{Indexer, Locator};
|
||||
use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor};
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ pub mod comparable;
|
|||
pub mod hashable;
|
||||
pub mod helpers;
|
||||
pub mod imports;
|
||||
pub mod newlines;
|
||||
pub mod node;
|
||||
pub mod prelude;
|
||||
pub mod relocate;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::Tok;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::ops::Deref;
|
||||
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::Tok;
|
||||
|
||||
/// Stores the ranges of comments sorted by [`TextRange::start`] in increasing order. No two ranges are overlapping.
|
||||
#[derive(Clone)]
|
||||
pub struct CommentRanges {
|
||||
|
|
|
@ -8,7 +8,8 @@ use rustpython_parser::ast::{
|
|||
Excepthandler, Expr, Identifier, MatchCase, Operator, Pattern, Stmt, Suite, Withitem,
|
||||
};
|
||||
|
||||
use crate::newlines::LineEnding;
|
||||
use ruff_newlines::LineEnding;
|
||||
|
||||
use crate::source_code::stylist::{Indentation, Quote, Stylist};
|
||||
|
||||
mod precedence {
|
||||
|
@ -1459,7 +1460,8 @@ mod tests {
|
|||
use rustpython_ast::Suite;
|
||||
use rustpython_parser::Parse;
|
||||
|
||||
use crate::newlines::LineEnding;
|
||||
use ruff_newlines::LineEnding;
|
||||
|
||||
use crate::source_code::stylist::{Indentation, Quote};
|
||||
use crate::source_code::Generator;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//! Struct used to index source code, to enable efficient lookup of tokens that
|
||||
//! are omitted from the AST (e.g., commented lines).
|
||||
|
||||
use crate::source_code::comment_ranges::{CommentRanges, CommentRangesBuilder};
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::{StringKind, Tok};
|
||||
|
||||
use crate::source_code::comment_ranges::{CommentRanges, CommentRangesBuilder};
|
||||
use crate::source_code::Locator;
|
||||
|
||||
pub struct Indexer {
|
||||
|
|
|
@ -6,7 +6,8 @@ use memchr::{memchr2, memrchr2};
|
|||
use once_cell::unsync::OnceCell;
|
||||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::newlines::find_newline;
|
||||
use ruff_newlines::find_newline;
|
||||
|
||||
use crate::source_code::{LineIndex, OneIndexed, SourceCode, SourceLocation};
|
||||
|
||||
pub struct Locator<'a> {
|
||||
|
|
|
@ -7,13 +7,13 @@ 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};
|
||||
pub use comment_ranges::{CommentRanges, CommentRangesBuilder};
|
||||
|
||||
mod comment_ranges;
|
||||
mod generator;
|
||||
|
|
|
@ -4,11 +4,11 @@ use std::fmt;
|
|||
use std::ops::Deref;
|
||||
|
||||
use once_cell::unsync::OnceCell;
|
||||
use ruff_newlines::{find_newline, LineEnding};
|
||||
use rustpython_literal::escape::Quote as StrQuote;
|
||||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::Tok;
|
||||
|
||||
use crate::newlines::{find_newline, LineEnding};
|
||||
use crate::source_code::Locator;
|
||||
use crate::str::leading_quote;
|
||||
|
||||
|
@ -166,7 +166,8 @@ mod tests {
|
|||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::Mode;
|
||||
|
||||
use crate::newlines::{find_newline, LineEnding};
|
||||
use ruff_newlines::{find_newline, LineEnding};
|
||||
|
||||
use crate::source_code::stylist::{Indentation, Quote};
|
||||
use crate::source_code::{Locator, Stylist};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ rust-version = { workspace = true }
|
|||
|
||||
[dependencies]
|
||||
ruff_formatter = { path = "../ruff_formatter" }
|
||||
ruff_newlines = { path = "../ruff_newlines" }
|
||||
ruff_python_ast = { path = "../ruff_python_ast" }
|
||||
ruff_text_size = { workspace = true }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue