Skip to content

Commit 8ac9dab

Browse files
authored
refactor: minor tweaks found by Clippy (#639)
1 parent 64746f2 commit 8ac9dab

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/file_utils.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub fn read_file(file_path: &str) -> PyResult<String> {
2020
Ok(content) => Ok(content),
2121
Err(e) => match e.kind() {
2222
ErrorKind::NotFound => Err(PyFileNotFoundError::new_err(format!(
23-
"File not found: '{}'",
24-
file_path
23+
"File not found: '{file_path}'",
2524
))),
2625
ErrorKind::InvalidData => {
2726
let file = File::open(path).unwrap();
@@ -32,7 +31,7 @@ pub fn read_file(file_path: &str) -> PyResult<String> {
3231
.unwrap_or_else(|| guess_encoding(&buffer));
3332
read_with_encoding(&buffer, encoding)
3433
}
35-
_ => Err(PyIOError::new_err(format!("An error occurred: '{}'", e))),
34+
_ => Err(PyIOError::new_err(format!("An error occurred: '{e}'"))),
3635
},
3736
}
3837
}

src/imports/ipynb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn _extract_code_from_notebook_cells(cells: &[serde_json::Value]) -> String {
6363
let code_lines: Vec<String> = cells
6464
.iter()
6565
.filter(|cell| cell["cell_type"] == "code")
66-
.flat_map(|cell| cell["source"].as_array())
66+
.filter_map(|cell| cell["source"].as_array())
6767
.flatten()
6868
.filter_map(|line| line.as_str())
6969
.map(str::to_owned)

src/imports/shared.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn get_ast_from_file_content(file_content: &str) -> PyResult<Mod> {
2929
}
3030

3131
/// Iterates through an AST to identify and collect import statements, and returns them together with their
32-
/// respective TextRange for each occurrence.
32+
/// respective `TextRange` for each occurrence.
3333
pub fn extract_imports_from_ast(ast: Mod) -> HashMap<String, Vec<TextRange>> {
3434
let mut visitor = ImportVisitor::new();
3535

@@ -62,7 +62,7 @@ pub fn convert_imports_with_textranges_to_location_objects(
6262
.column
6363
.get();
6464
Location {
65-
file: file_path.to_string(),
65+
file: file_path.to_owned(),
6666
line: Some(start_line),
6767
column: Some(start_col),
6868
}
@@ -73,7 +73,7 @@ pub fn convert_imports_with_textranges_to_location_objects(
7373
imports_with_locations
7474
}
7575

76-
/// Transforms a Rust HashMap containing import data into a Python dictionary suitable for Python-side consumption.
76+
/// Transforms a Rust `HashMap` containing import data into a Python dictionary suitable for Python-side consumption.
7777
pub fn convert_to_python_dict(
7878
py: Python<'_>,
7979
imports_with_locations: FileToImportsMap,

src/location.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub struct Location {
1414
#[pymethods]
1515
impl Location {
1616
#[new]
17-
pub fn new(file: String, line: Option<usize>, column: Option<usize>) -> Self {
18-
Location { file, line, column }
17+
fn new(file: String, line: Option<usize>, column: Option<usize>) -> Self {
18+
Self { file, line, column }
1919
}
2020

21-
fn __repr__(&self) -> PyResult<String> {
22-
Ok(format!(
21+
fn __repr__(&self) -> String {
22+
format!(
2323
"Location(file='{}', line={:?}, column={:?})",
2424
self.file, self.line, self.column
25-
))
25+
)
2626
}
2727
}

src/visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct ImportVisitor {
1010

1111
impl ImportVisitor {
1212
pub fn new() -> Self {
13-
ImportVisitor {
13+
Self {
1414
imports: HashMap::new(),
1515
}
1616
}
@@ -49,11 +49,11 @@ impl<'a> Visitor<'a> for ImportVisitor {
4949
}
5050

5151
/// Extracts the top-level module name from a potentially nested module path.
52-
/// e.g. when a module_name is `foo.bar`, this returns `foo`.
52+
/// e.g. when a `module_name` is `foo.bar`, this returns `foo`.
5353
fn get_top_level_module_name(module_name: &str) -> String {
5454
module_name
5555
.split('.')
5656
.next()
5757
.unwrap_or(module_name)
58-
.to_string()
58+
.to_owned()
5959
}

0 commit comments

Comments
 (0)