mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Enable LibCST-based autofixing for SPR001 (#297)
This commit is contained in:
parent
83f18193c2
commit
558d9fcbe3
8 changed files with 183 additions and 24 deletions
|
@ -134,7 +134,7 @@ impl<'a> SourceCodeLocator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn slice_source_code(&mut self, location: &Location) -> &'a str {
|
||||
pub fn slice_source_code_at(&mut self, location: &Location) -> &'a str {
|
||||
if !self.initialized {
|
||||
let mut offset = 0;
|
||||
for i in self.content.lines() {
|
||||
|
@ -147,4 +147,19 @@ impl<'a> SourceCodeLocator<'a> {
|
|||
let offset = self.offsets[location.row() - 1] + location.column() - 1;
|
||||
&self.content[offset..]
|
||||
}
|
||||
|
||||
pub fn slice_source_code_range(&mut self, start: &Location, end: &Location) -> &'a str {
|
||||
if !self.initialized {
|
||||
let mut offset = 0;
|
||||
for i in self.content.lines() {
|
||||
self.offsets.push(offset);
|
||||
offset += i.len();
|
||||
offset += 1;
|
||||
}
|
||||
self.initialized = true;
|
||||
}
|
||||
let start = self.offsets[start.row() - 1] + start.column() - 1;
|
||||
let end = self.offsets[end.row() - 1] + end.column() - 1;
|
||||
&self.content[start..end]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue