-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed panic in missing_copyright_notice
#7029
Changes from 3 commits
9e506ce
52c08e2
ca2631a
386d5f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_copyright/mod.rs | ||
--- | ||
<filename>:1:1: CPY001 Missing copyright notice at top of file | ||
| | ||
1 | কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক | ||
| CPY001 | ||
| | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,6 +388,23 @@ impl<'a> Locator<'a> { | |
&self.contents[usize::from(offset)..] | ||
} | ||
|
||
/// Finds the closest [`TextSize`] not exceeding the offset for which `is_char_boundary` is | ||
/// `true`. | ||
/// | ||
/// Can be replaced with `str#floor_char_boundary` once it's stable. | ||
pub fn floor_char_boundary(&self, offset: TextSize) -> TextSize { | ||
if offset >= self.text_len() { | ||
self.text_len() | ||
} else { | ||
// We know that the character boundary is within four bytes. | ||
(0u32..=3u32) | ||
.map(TextSize::from) | ||
.filter_map(|index| offset.checked_sub(index)) | ||
.find(|offset| self.contents.is_char_boundary(offset.to_usize())) | ||
.unwrap_or_default() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this into a dedicated method on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for advice! |
||
|
||
/// Take the source code between the given [`TextRange`]. | ||
#[inline] | ||
pub fn slice<T: Ranged>(&self, ranged: T) -> &'a str { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this to
test_snippet
to match the pattern used in the other tests in this module. (We typically use dedicated test files like you had here, but it's nice to use the same convention within a given test suite.)