Skip to content

Commit

Permalink
Fix lint errors and warnings
Browse files Browse the repository at this point in the history
The CI gods demand it

```
warning: value assigned to `used_space` is never read
```

Don't know how to fix the other one in `generate_preview_count()`,
despite rust's attempt to help:

```
warning: value assigned to `available_space` is never read
   --> src/lineprinter.rs:868:9
    |
868 |         available_space -= len;
    |         ^^^^^^^^^^^^^^^
    |
    = help: maybe it is overwritten before being read?
```
  • Loading branch information
brewingcode committed Feb 21, 2022
1 parent 452fafd commit e6666e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
59 changes: 23 additions & 36 deletions src/lineprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,17 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
available_space -= 1;
}

let mut used_space = 0;
let mut used_space;

if self.preview == Preview::Full {
let quoted_object_keys = self.mode == Mode::Line;
used_space =
self.generate_container_preview(flatjson, row, available_space, quoted_object_keys)?;
self.generate_container_preview(
flatjson,
row,
available_space,
quoted_object_keys,
)?;

if self.trailing_comma {
used_space += 1;
Expand All @@ -706,8 +711,7 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
)?;
}
}
}
else if self.preview == Preview::None {
} else if self.preview == Preview::None {
self.highlight_str(
" ",
Some(self.value_range.end),
Expand All @@ -717,10 +721,8 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
),
)?;
used_space = 1;
}
else {
used_space =
self.generate_container_count(flatjson, row, available_space)?;
} else {
used_space = self.generate_container_count(flatjson, row, available_space)?;
}

Ok(used_space)
Expand Down Expand Up @@ -826,7 +828,7 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
&mut self,
flatjson: &FlatJson,
row: &Row,
mut available_space: isize
available_space: isize,
) -> Result<isize, fmt::Error> {
debug_assert!(row.is_opening_of_container());

Expand All @@ -836,7 +838,7 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
}

let mut next_sibling = row.first_child();
let mut count:usize = 0;
let mut count: usize = 0;
while let OptionIndex::Index(child) = next_sibling {
next_sibling = flatjson[child].next_sibling;
count += 1;
Expand All @@ -846,14 +848,14 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
let mut count_str = format!(
"{} {} item{} {}",
container_type.open_str(),
count.to_string(),
count,
if count == 1 { "" } else { "s" },
container_type.close_str()
);

if count_str.len() as isize > available_space {
count_str = format!(
"{}…{}",
"{}…{}",
container_type.open_str(),
container_type.close_str()
);
Expand All @@ -862,10 +864,9 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
self.highlight_str(
&count_str,
Some(self.value_range.start),
highlighting::PREVIEW_STYLES
highlighting::PREVIEW_STYLES,
)?;
let len = count_str.chars().count() as isize;
available_space -= len;
Ok(len)
}

Expand Down Expand Up @@ -1596,15 +1597,10 @@ mod tests {
..default_line_printer(&mut term)
};

for (available_space, used_space, expected) in vec![
(14, 11, r#"[ 3 items ]"#),
(4, 3, r#"[…]"#),
(2, 0, r#""#),
]
.into_iter()
for (available_space, used_space, expected) in
vec![(14, 11, r#"[ 3 items ]"#), (4, 3, r#"[…]"#), (2, 0, r#""#)].into_iter()
{
let used =
line.generate_container_count(&fj_arr, &fj_arr[0], available_space)?;
let used = line.generate_container_count(&fj_arr, &fj_arr[0], available_space)?;
assert_eq!(
expected,
line.terminal.output(),
Expand All @@ -1617,15 +1613,10 @@ mod tests {
line.terminal.clear_output();
}

for (available_space, used_space, expected) in vec![
(14, 11, r#"{ 2 items }"#),
(4, 3, r#"{…}"#),
(2, 0, r#""#),
]
.into_iter()
for (available_space, used_space, expected) in
vec![(14, 11, r#"{ 2 items }"#), (4, 3, r#"{…}"#), (2, 0, r#""#)].into_iter()
{
let used =
line.generate_container_count(&fj_obj, &fj_obj[0], available_space)?;
let used = line.generate_container_count(&fj_obj, &fj_obj[0], available_space)?;
assert_eq!(
expected,
line.terminal.output(),
Expand All @@ -1638,13 +1629,9 @@ mod tests {
line.terminal.clear_output();
}

for (available_space, used_space, expected) in vec![
(14, 10, r#"{ 1 item }"#),
]
.into_iter()
for (available_space, used_space, expected) in vec![(14, 10, r#"{ 1 item }"#)].into_iter()
{
let used =
line.generate_container_count(&fj_one, &fj_one[0], available_space)?;
let used = line.generate_container_count(&fj_one, &fj_one[0], available_space)?;
assert_eq!(
expected,
line.terminal.output(),
Expand Down
6 changes: 2 additions & 4 deletions src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,7 @@ impl JsonViewer {
if val == Preview::None && self.mode == Mode::Line {
// Emit a warning....?
self.preview = Preview::Count;
}
else {
} else {
self.preview = val;
}
}
Expand All @@ -749,8 +748,7 @@ impl JsonViewer {
Preview::Count => Preview::None,
Preview::None => Preview::Full,
}
}
else {
} else {
self.preview = match self.preview {
Preview::Full => Preview::Count,
Preview::Count => Preview::Full,
Expand Down

0 comments on commit e6666e6

Please sign in to comment.