mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
refactor(lint): prefer idiomatic for loops (#974)
This commit is contained in:
parent
37b957c7e1
commit
6fd5f631bb
7 changed files with 20 additions and 18 deletions
|
@ -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.
|
||||
#!
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue