Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 2, 2024
1 parent 01f0444 commit 43e972a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
9 changes: 9 additions & 0 deletions crates/ruff_linter/src/fix/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ pub(crate) fn add_argument(
}

/// Safely adjust the indentation of the indented block at [`TextRange`].
///
/// The [`TextRange`] is assumed to represent an entire indented block, including the leading
/// indentation of that block. For example, to dedent the body here:
/// ```python
/// if True:
/// print("Hello, world!")
/// ```
///
/// The range would be the entirety of ` print("Hello, world!")`.
pub(crate) fn adjust_indentation(
range: TextRange,
indentation: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(crate) fn trailing_whitespace(
diagnostic.set_fix(Fix::applicable_edit(
Edit::range_deletion(range),
// Removing trailing whitespace is not safe inside multiline strings.
if indexer.multiline_ranges().contains(range) {
if indexer.multiline_ranges().contains_range(range) {
Applicability::Unsafe
} else {
Applicability::Safe
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_index/src/fstring_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub struct FStringRanges {
}

impl FStringRanges {
/// Returns `true` if the given range contains an f-string.
/// Returns `true` if the given range intersects with any f-string range.
pub fn intersects(&self, target: TextRange) -> bool {
self.raw
.values()
.take_while(|range| range.start() < target.end())
.any(|range| target.contains_range(*range))
.any(|range| target.intersect(*range).is_some())
}

/// Return the [`TextRange`] of the innermost f-string at the given offset.
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_python_index/src/multiline_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct MultilineRanges {

impl MultilineRanges {
/// Returns `true` if the given range is inside a multiline string.
pub fn contains(&self, target: TextRange) -> bool {
pub fn contains_range(&self, target: TextRange) -> bool {
self.ranges
.binary_search_by(|range| {
if range.contains_range(target) {
Expand All @@ -23,11 +23,11 @@ impl MultilineRanges {
.is_ok()
}

/// Returns `true` if the given range contains a multiline string.
/// Returns `true` if the given range intersects with any multiline string.
pub fn intersects(&self, target: TextRange) -> bool {
self.ranges
.binary_search_by(|range| {
if target.contains_range(*range) {
if target.intersect(*range).is_some() {
std::cmp::Ordering::Equal
} else if range.end() < target.start() {
std::cmp::Ordering::Less
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_trivia/src/comment_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ impl CommentRanges {
Self { raw: ranges }
}

/// Returns `true` if the given range includes a comment.
/// Returns `true` if the given range intersects with any comment range.
pub fn intersects(&self, target: TextRange) -> bool {
self.raw
.binary_search_by(|range| {
if target.contains_range(*range) {
if target.intersect(*range).is_some() {
std::cmp::Ordering::Equal
} else if range.end() < target.start() {
std::cmp::Ordering::Less
Expand Down

0 comments on commit 43e972a

Please sign in to comment.