From eb9a1bc5f1fe1a23ed5e4453b17168b6224676dd Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 30 Dec 2023 15:48:45 -0400 Subject: [PATCH] Use consistent re-export from `ruff_source_file` (#9320) Right now, we both re-export (via `pub use`) and mark the modules themselves a `pub`, so they can be imported through two different paths. --- crates/ruff_linter/src/linter.rs | 4 ++-- crates/ruff_python_ast/src/whitespace.rs | 2 +- crates/ruff_python_trivia/src/textwrap.rs | 3 ++- crates/ruff_source_file/src/lib.rs | 13 +++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index 6e62b4d621..cbb55920fc 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -336,10 +336,10 @@ pub fn add_noqa_to_path( ); // Log any parse errors. - if let Some(err) = error { + if let Some(error) = error { error!( "{}", - DisplayParseError::new(err, locator.to_source_code(), source_kind) + DisplayParseError::new(error, locator.to_source_code(), source_kind) ); } diff --git a/crates/ruff_python_ast/src/whitespace.rs b/crates/ruff_python_ast/src/whitespace.rs index f3b906d6b9..7a1ed847c3 100644 --- a/crates/ruff_python_ast/src/whitespace.rs +++ b/crates/ruff_python_ast/src/whitespace.rs @@ -1,5 +1,5 @@ use ruff_python_trivia::{indentation_at_offset, is_python_whitespace, PythonWhitespace}; -use ruff_source_file::{newlines::UniversalNewlineIterator, Locator}; +use ruff_source_file::{Locator, UniversalNewlineIterator}; use ruff_text_size::{Ranged, TextRange, TextSize}; use crate::Stmt; diff --git a/crates/ruff_python_trivia/src/textwrap.rs b/crates/ruff_python_trivia/src/textwrap.rs index e0d07e8f3b..536aed0647 100644 --- a/crates/ruff_python_trivia/src/textwrap.rs +++ b/crates/ruff_python_trivia/src/textwrap.rs @@ -4,8 +4,9 @@ use std::borrow::Cow; use std::cmp; +use ruff_source_file::UniversalNewlines; + use crate::PythonWhitespace; -use ruff_source_file::newlines::UniversalNewlines; /// Indent each line by the given prefix. /// diff --git a/crates/ruff_source_file/src/lib.rs b/crates/ruff_source_file/src/lib.rs index fc2a10108d..457158bb8b 100644 --- a/crates/ruff_source_file/src/lib.rs +++ b/crates/ruff_source_file/src/lib.rs @@ -2,21 +2,22 @@ use std::cmp::Ordering; use std::fmt::{Debug, Formatter}; use std::sync::Arc; -use ruff_text_size::{Ranged, TextRange, TextSize}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -pub mod line_index; -mod locator; -pub mod newlines; +use ruff_text_size::{Ranged, TextRange, TextSize}; pub use crate::line_index::{LineIndex, OneIndexed}; -pub use locator::Locator; -pub use newlines::{ +pub use crate::locator::Locator; +pub use crate::newlines::{ find_newline, Line, LineEnding, NewlineWithTrailingNewline, UniversalNewlineIterator, UniversalNewlines, }; +mod line_index; +mod locator; +mod newlines; + /// Gives access to the source code of a file and allows mapping between [`TextSize`] and [`SourceLocation`]. #[derive(Debug)] pub struct SourceCode<'src, 'index> {