mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
Rework for new clippy lints (#12736)
- **Clippy lint `assigning_clones`** - **Clippy lint `legacy_numeric_constants`** - **`clippy::float_equality_without_abs`** - **`nu-table`: clippy::zero_repeat_side_effects** --------- Co-authored-by: Ian Manske <ian.manske@pm.me>
This commit is contained in:
parent
0805f1fd90
commit
b88d8726d0
8 changed files with 31 additions and 57 deletions
|
@ -127,7 +127,7 @@ impl Command for Do {
|
||||||
let stderr_msg = match stderr {
|
let stderr_msg = match stderr {
|
||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
Some(stderr_stream) => {
|
Some(stderr_stream) => {
|
||||||
stderr_ctrlc = stderr_stream.ctrlc.clone();
|
stderr_ctrlc.clone_from(&stderr_stream.ctrlc);
|
||||||
stderr_stream.into_string().map(|s| s.item)?
|
stderr_stream.into_string().map(|s| s.item)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -152,7 +152,7 @@ impl Command for Do {
|
||||||
let exit_code: Vec<Value> = match exit_code {
|
let exit_code: Vec<Value> = match exit_code {
|
||||||
None => vec![],
|
None => vec![],
|
||||||
Some(exit_code_stream) => {
|
Some(exit_code_stream) => {
|
||||||
exit_code_ctrlc = exit_code_stream.ctrlc.clone();
|
exit_code_ctrlc.clone_from(&exit_code_stream.ctrlc);
|
||||||
exit_code_stream.into_iter().collect()
|
exit_code_stream.into_iter().collect()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -150,7 +150,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||||
head,
|
head,
|
||||||
),
|
),
|
||||||
Ordering::Less => Value::binary(
|
Ordering::Less => Value::binary(
|
||||||
if end == isize::max_value() {
|
if end == isize::MAX {
|
||||||
val.iter()
|
val.iter()
|
||||||
.skip(start as usize)
|
.skip(start as usize)
|
||||||
.copied()
|
.copied()
|
||||||
|
|
|
@ -149,7 +149,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||||
),
|
),
|
||||||
Ordering::Less => Value::string(
|
Ordering::Less => Value::string(
|
||||||
{
|
{
|
||||||
if end == isize::max_value() {
|
if end == isize::MAX {
|
||||||
if args.graphemes {
|
if args.graphemes {
|
||||||
s.graphemes(true)
|
s.graphemes(true)
|
||||||
.skip(start as usize)
|
.skip(start as usize)
|
||||||
|
@ -245,7 +245,7 @@ mod tests {
|
||||||
expectation("andre", (0, -1)),
|
expectation("andre", (0, -1)),
|
||||||
// str substring [ -4 , _ ]
|
// str substring [ -4 , _ ]
|
||||||
// str substring -4 ,
|
// str substring -4 ,
|
||||||
expectation("dres", (-4, isize::max_value())),
|
expectation("dres", (-4, isize::MAX)),
|
||||||
expectation("", (0, -110)),
|
expectation("", (0, -110)),
|
||||||
expectation("", (6, 0)),
|
expectation("", (6, 0)),
|
||||||
expectation("", (6, -1)),
|
expectation("", (6, -1)),
|
||||||
|
|
|
@ -1141,18 +1141,18 @@ mod test {
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":1.1}").unwrap();
|
let v: Value = from_str("{\"a\":1.1}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert!(vo["a"].as_f64().unwrap() - 1.1 < std::f64::EPSILON);
|
assert!((vo["a"].as_f64().unwrap() - 1.1).abs() < f64::EPSILON);
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":-1.1}").unwrap();
|
let v: Value = from_str("{\"a\":-1.1}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert!(vo["a"].as_f64().unwrap() + 1.1 > -(std::f64::EPSILON));
|
assert!((vo["a"].as_f64().unwrap() + 1.1).abs() < f64::EPSILON);
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":1e6}").unwrap();
|
let v: Value = from_str("{\"a\":1e6}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert!(vo["a"].as_f64().unwrap() - 1e6 < std::f64::EPSILON);
|
assert!((vo["a"].as_f64().unwrap() - 1e6).abs() < f64::EPSILON);
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":-1e6}").unwrap();
|
let v: Value = from_str("{\"a\":-1e6}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert!(vo["a"].as_f64().unwrap() + 1e6 > -(std::f64::EPSILON));
|
assert!((vo["a"].as_f64().unwrap() + 1e6).abs() < f64::EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn lev_distance(a: &str, b: &str, limit: usize) -> Option<usize> {
|
||||||
|
|
||||||
/// Finds the Levenshtein distance between two strings.
|
/// Finds the Levenshtein distance between two strings.
|
||||||
pub fn levenshtein_distance(a: &str, b: &str) -> usize {
|
pub fn levenshtein_distance(a: &str, b: &str) -> usize {
|
||||||
lev_distance(a, b, usize::max_value()).unwrap_or(usize::max_value())
|
lev_distance(a, b, usize::MAX).unwrap_or(usize::MAX)
|
||||||
}
|
}
|
||||||
/// Provides a word similarity score between two words that accounts for substrings being more
|
/// Provides a word similarity score between two words that accounts for substrings being more
|
||||||
/// meaningful than a typical Levenshtein distance. The lower the score, the closer the match.
|
/// meaningful than a typical Levenshtein distance. The lower the score, the closer the match.
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl PluginRegistryFile {
|
||||||
error_span: Option<Span>,
|
error_span: Option<Span>,
|
||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
// Update the Nushell version before writing
|
// Update the Nushell version before writing
|
||||||
self.nushell_version = env!("CARGO_PKG_VERSION").to_owned();
|
env!("CARGO_PKG_VERSION").clone_into(&mut self.nushell_version);
|
||||||
|
|
||||||
// Format is brotli compressed messagepack
|
// Format is brotli compressed messagepack
|
||||||
let mut brotli_writer =
|
let mut brotli_writer =
|
||||||
|
|
|
@ -2893,7 +2893,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(*lhs as f64 / *rhs as f64)
|
(*lhs as f64 / *rhs as f64)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2905,7 +2905,7 @@ impl Value {
|
||||||
if *rhs != 0.0 {
|
if *rhs != 0.0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(*lhs as f64 / *rhs)
|
(*lhs as f64 / *rhs)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2917,7 +2917,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(*lhs / *rhs as f64)
|
(*lhs / *rhs as f64)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2928,9 +2928,7 @@ impl Value {
|
||||||
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||||
if *rhs != 0.0 {
|
if *rhs != 0.0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(lhs / rhs)
|
(lhs / rhs).clamp(i64::MIN as f64, i64::MAX as f64).floor() as i64,
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
|
||||||
.floor() as i64,
|
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
@ -2941,7 +2939,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(*lhs as f64 / *rhs as f64)
|
(*lhs as f64 / *rhs as f64)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2953,7 +2951,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::filesize(
|
Ok(Value::filesize(
|
||||||
((*lhs as f64) / (*rhs as f64))
|
((*lhs as f64) / (*rhs as f64))
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2965,7 +2963,7 @@ impl Value {
|
||||||
if *rhs != 0.0 {
|
if *rhs != 0.0 {
|
||||||
Ok(Value::filesize(
|
Ok(Value::filesize(
|
||||||
(*lhs as f64 / *rhs)
|
(*lhs as f64 / *rhs)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2977,7 +2975,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::int(
|
Ok(Value::int(
|
||||||
(*lhs as f64 / *rhs as f64)
|
(*lhs as f64 / *rhs as f64)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -2989,7 +2987,7 @@ impl Value {
|
||||||
if *rhs != 0 {
|
if *rhs != 0 {
|
||||||
Ok(Value::duration(
|
Ok(Value::duration(
|
||||||
(*lhs as f64 / *rhs as f64)
|
(*lhs as f64 / *rhs as f64)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
@ -3001,7 +2999,7 @@ impl Value {
|
||||||
if *rhs != 0.0 {
|
if *rhs != 0.0 {
|
||||||
Ok(Value::duration(
|
Ok(Value::duration(
|
||||||
(*lhs as f64 / *rhs)
|
(*lhs as f64 / *rhs)
|
||||||
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
|
.clamp(i64::MIN as f64, i64::MAX as f64)
|
||||||
.floor() as i64,
|
.floor() as i64,
|
||||||
span,
|
span,
|
||||||
))
|
))
|
||||||
|
|
|
@ -47,10 +47,7 @@ fn test_rounded() {
|
||||||
╰───┴───┴───┴───╯"
|
╰───┴───┴───┴───╯"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::rounded()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::rounded()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -98,10 +95,7 @@ fn test_basic() {
|
||||||
+---+---+---+---+"
|
+---+---+---+---+"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::basic()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::basic()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -146,7 +140,7 @@ fn test_reinforced() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::reinforced()),
|
create_table_with_size(vec![], true, theme::reinforced()),
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -196,10 +190,7 @@ fn test_compact() {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::compact()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::compact()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -248,7 +239,7 @@ fn test_compact_double() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::compact_double()),
|
create_table_with_size(vec![], true, theme::compact_double()),
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -296,10 +287,7 @@ fn test_heavy() {
|
||||||
┗━━━┻━━━┻━━━┻━━━┛"
|
┗━━━┻━━━┻━━━┻━━━┛"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::heavy()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::heavy()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -334,10 +322,7 @@ fn test_light() {
|
||||||
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::light()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::light()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -367,10 +352,7 @@ fn test_none() {
|
||||||
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::none()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::none()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -418,10 +400,7 @@ fn test_thin() {
|
||||||
└───┴───┴───┴───┘"
|
└───┴───┴───┴───┘"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::thin()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::thin()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -469,10 +448,7 @@ fn test_with_love() {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(create_table_with_size(vec![], true, theme::with_love()), "");
|
||||||
create_table_with_size(vec![row(4); 0], true, theme::with_love()),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_table(data: Vec<Vec<CellInfo<String>>>, with_header: bool, theme: theme) -> String {
|
fn create_table(data: Vec<Vec<CellInfo<String>>>, with_header: bool, theme: theme) -> String {
|
||||||
|
|
Loading…
Reference in a new issue