Enable LibCST-based autofixing for SPR001 (#297)

This commit is contained in:
Charlie Marsh 2022-10-02 19:58:13 -04:00 committed by GitHub
parent 83f18193c2
commit 558d9fcbe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 183 additions and 24 deletions

View file

@ -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]
}
}