Skip to content

Commit 9f64d39

Browse files
authored
Merge pull request #286 from fox0/clippy--assertions_on_constants
Fix clippy::needless_range_loop, op_ref,assertions_on_constants, and add one test
2 parents 4bed94c + 6f5debe commit 9f64d39

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

file/split.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ impl OutputState {
151151

152152
fn write(&mut self, buf: &[u8]) -> io::Result<()> {
153153
match &mut self.outf {
154-
None => {
155-
assert!(false);
156-
Ok(())
157-
}
158154
Some(ref mut f) => f.write_all(buf),
155+
None => Ok(()),
159156
}
160157
}
161158

text/sort.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,19 +945,26 @@ fn merge_files(paths: &mut Vec<Box<dyn Read>>, output_path: &Option<PathBuf>) ->
945945
///
946946
/// A vector of strings (`Vec<String>`) where consecutive empty strings are merged with the nearest non-empty string.
947947
///
948+
/// # Examples
949+
///
950+
/// ```
951+
/// let result = merge_empty_lines(vec!["line1", "line2", "", "", "", "lineN"]);
952+
/// assert_eq!(result, vec!["line1", "line2", " lineN"]);
953+
/// ```
954+
///
948955
fn merge_empty_lines(vec: Vec<&str>) -> Vec<String> {
949956
let mut empty_count = 0;
950957
let mut result = vec![];
951958

952-
for i in 0..vec.len() {
953-
if vec[i].is_empty() {
959+
for i in vec {
960+
if i.is_empty() {
954961
empty_count += 1;
955962
} else if empty_count > 0 {
956963
let spaces = " ".repeat(empty_count);
957-
result.push(format!("{}{}", spaces, vec[i]));
964+
result.push(format!("{}{}", spaces, i));
958965
empty_count = 0;
959966
} else {
960-
result.push(vec[i].to_string());
967+
result.push(i.to_string());
961968
}
962969
}
963970

@@ -1029,3 +1036,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
10291036

10301037
std::process::exit(exit_code)
10311038
}
1039+
1040+
#[cfg(test)]
1041+
mod tests {
1042+
use super::*;
1043+
1044+
#[test]
1045+
fn test_merge_empty_lines() {
1046+
let result = merge_empty_lines(vec!["line1", "line2", "", "", "", "lineN"]);
1047+
assert_eq!(result, vec!["line1", "line2", " lineN"]);
1048+
}
1049+
}

tree/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ fn process_single_dir(
12281228
let dir_parent = {
12291229
let mut comps = canonical_dir_path.as_inner().components();
12301230

1231-
let is_dot = dir_entry.file_name().to_bytes_with_nul() == &[b'.', 0];
1231+
let is_dot = dir_entry.file_name().to_bytes_with_nul() == [b'.', 0];
12321232

12331233
if !is_dot {
12341234
comps.next_back();

0 commit comments

Comments
 (0)