refactor(lint): prefer idiomatic for loops (#974)

This commit is contained in:
EdJoPaTo 2024-02-27 12:12:33 +01:00 committed by Josh McKinney
parent 37b957c7e1
commit 6fd5f631bb
No known key found for this signature in database
GPG key ID: 722287396A903BC5
7 changed files with 20 additions and 18 deletions

View file

@ -61,6 +61,12 @@ rand_chacha = "0.3.1"
rstest = "0.18.2"
serde_json = "1.0.109"
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
explicit_iter_loop = "warn"
needless_for_each = "warn"
[features]
#! The crate provides a set of optional features that can be enabled in your `cargo.toml` file.
#!

View file

@ -698,7 +698,7 @@ fn configure_variable_constraints(
area: Element,
) -> Result<(), AddConstraintError> {
// all variables are in the range [area.start, area.end]
for &variable in variables.iter() {
for &variable in variables {
solver.add_constraint(variable | GE(REQUIRED) | area.start)?;
solver.add_constraint(variable | LE(REQUIRED) | area.end)?;
}
@ -764,7 +764,7 @@ fn configure_flex_constraints(
let spacing_f64 = f64::from(spacing) * FLOAT_PRECISION_MULTIPLIER;
match flex {
Flex::Legacy => {
for spacer in spacers_except_first_and_last.iter() {
for spacer in spacers_except_first_and_last {
solver.add_constraint(spacer.has_size(spacing_f64, SPACER_SIZE_EQ))?;
}
if let (Some(first), Some(last)) = (spacers.first(), spacers.last()) {
@ -778,7 +778,7 @@ fn configure_flex_constraints(
for (left, right) in spacers.iter().tuple_combinations() {
solver.add_constraint(left.has_size(right, SPACER_SIZE_EQ))?
}
for spacer in spacers.iter() {
for spacer in spacers {
solver.add_constraint(spacer.has_min_size(spacing, SPACER_SIZE_EQ))?;
solver.add_constraint(spacer.has_size(area, SPACE_GROW))?;
}
@ -790,10 +790,10 @@ fn configure_flex_constraints(
for (left, right) in spacers_except_first_and_last.iter().tuple_combinations() {
solver.add_constraint(left.has_size(right.size(), SPACER_SIZE_EQ))?
}
for spacer in spacers_except_first_and_last.iter() {
for spacer in spacers_except_first_and_last {
solver.add_constraint(spacer.has_min_size(spacing, SPACER_SIZE_EQ))?;
}
for spacer in spacers_except_first_and_last.iter() {
for spacer in spacers_except_first_and_last {
solver.add_constraint(spacer.has_size(area, SPACE_GROW))?;
}
if let (Some(first), Some(last)) = (spacers.first(), spacers.last()) {

View file

@ -1,5 +1,3 @@
#![forbid(unsafe_code)]
//! ![Demo](https://github.com/ratatui-org/ratatui/blob/1d39444e3dea6f309cf9035be2417ac711c1abc9/examples/demo2-destroy.gif?raw=true)
//!
//! <div align="center">

View file

@ -470,7 +470,7 @@ impl WidgetRef for Line<'_> {
None => 0,
};
let mut x = area.left().saturating_add(offset);
for span in self.spans.iter() {
for span in &self.spans {
let span_width = span.width() as u16;
let span_area = Rect {
x,

View file

@ -128,7 +128,7 @@ mod tests {
canvas.render(buffer.area, &mut buffer);
let mut expected = Buffer::with_lines(expected_lines);
for cell in expected.content.iter_mut() {
for cell in &mut expected.content {
if cell.symbol() == "" {
cell.set_style(Style::new().red());
}

View file

@ -1355,7 +1355,7 @@ mod tests {
let expected = Buffer::with_lines(vec!["┌────┐", "│Data│", "└────┘"]);
[
for position in [
LegendPosition::TopLeft,
LegendPosition::Top,
LegendPosition::TopRight,
@ -1364,14 +1364,12 @@ mod tests {
LegendPosition::Bottom,
LegendPosition::BottomLeft,
LegendPosition::BottomRight,
]
.iter()
.for_each(|&position| {
] {
let chart = chart.clone().legend_position(Some(position));
buffer.reset();
chart.render(buffer.area, &mut buffer);
assert_eq!(buffer, expected);
});
}
}
#[test]

View file

@ -800,14 +800,14 @@ impl Table<'_> {
}
fn ensure_percentages_less_than_100(widths: &[Constraint]) {
widths.iter().for_each(|&w| {
for w in widths {
if let Constraint::Percentage(p) = w {
assert!(
p <= 100,
*p <= 100,
"Percentages should be between 0 and 100 inclusively."
)
);
}
});
}
}
impl<'a> Styled for Table<'a> {