mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 12:21:16 +02:00
Reduced LOC by replacing several instances of Value::Int {}
, Value::Float{}
, Value::Bool {}
, and Value::String {}
with Value::int()
, Value::float()
, Value::boolean()
and Value::string()
(#7412)
# Description While perusing Value.rs, I noticed the `Value::int()`, `Value::float()`, `Value::boolean()` and `Value::string()` constructors, which seem designed to make it easier to construct various Values, but which aren't used often at all in the codebase. So, using a few find-replaces regexes, I increased their usage. This reduces overall LOC because structures like this: ``` Value::Int { val: a, span: head } ``` are changed into ``` Value::int(a, head) ``` and are respected as such by the project's formatter. There are little readability concerns because the second argument to all of these is `span`, and it's almost always extremely obvious which is the span at every callsite. # User-Facing Changes None. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -50,26 +50,17 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to camelCase",
|
||||
example: " 'NuShell' | str camel-case",
|
||||
result: Some(Value::String {
|
||||
val: "nuShell".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("nuShell", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to camelCase",
|
||||
example: "'this-is-the-first-case' | str camel-case",
|
||||
result: Some(Value::String {
|
||||
val: "thisIsTheFirstCase".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("thisIsTheFirstCase", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to camelCase",
|
||||
example: " 'this_is_the_second_case' | str camel-case",
|
||||
result: Some(Value::String {
|
||||
val: "thisIsTheSecondCase".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("thisIsTheSecondCase", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to camelCase",
|
||||
@ -79,10 +70,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "nuTest".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("nuTest", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -48,18 +48,12 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Capitalize contents",
|
||||
example: "'good day' | str capitalize",
|
||||
result: Some(Value::String {
|
||||
val: "Good day".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("Good day", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Capitalize contents",
|
||||
example: "'anton' | str capitalize",
|
||||
result: Some(Value::String {
|
||||
val: "Anton".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("Anton", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Capitalize a column in a table",
|
||||
@ -69,10 +63,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "Nu_test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("Nu_test", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -48,18 +48,12 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Downcase contents",
|
||||
example: "'NU' | str downcase",
|
||||
result: Some(Value::String {
|
||||
val: "nu".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("nu", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Downcase contents",
|
||||
example: "'TESTa' | str downcase",
|
||||
result: Some(Value::String {
|
||||
val: "testa".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("testa", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Downcase contents",
|
||||
@ -68,14 +62,8 @@ impl Command for SubCommand {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::String {
|
||||
val: "ABC".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("test", Span::test_data()),
|
||||
Value::string("ABC", Span::test_data()),
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
@ -89,14 +77,8 @@ impl Command for SubCommand {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::String {
|
||||
val: "abc".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("test", Span::test_data()),
|
||||
Value::string("abc", Span::test_data()),
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
|
@ -50,26 +50,17 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to kebab-case",
|
||||
example: "'NuShell' | str kebab-case",
|
||||
result: Some(Value::String {
|
||||
val: "nu-shell".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("nu-shell", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to kebab-case",
|
||||
example: "'thisIsTheFirstCase' | str kebab-case",
|
||||
result: Some(Value::String {
|
||||
val: "this-is-the-first-case".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("this-is-the-first-case", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to kebab-case",
|
||||
example: "'THIS_IS_THE_SECOND_CASE' | str kebab-case",
|
||||
result: Some(Value::String {
|
||||
val: "this-is-the-second-case".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("this-is-the-second-case", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to kebab-case",
|
||||
@ -79,10 +70,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "nu-test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("nu-test", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -50,26 +50,17 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to PascalCase",
|
||||
example: "'nu-shell' | str pascal-case",
|
||||
result: Some(Value::String {
|
||||
val: "NuShell".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("NuShell", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to PascalCase",
|
||||
example: "'this-is-the-first-case' | str pascal-case",
|
||||
result: Some(Value::String {
|
||||
val: "ThisIsTheFirstCase".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("ThisIsTheFirstCase", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to PascalCase",
|
||||
example: "'this_is_the_second_case' | str pascal-case",
|
||||
result: Some(Value::String {
|
||||
val: "ThisIsTheSecondCase".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("ThisIsTheSecondCase", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to PascalCase",
|
||||
@ -79,10 +70,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "NuTest".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("NuTest", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -49,26 +49,17 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to SCREAMING_SNAKE_CASE",
|
||||
example: r#" "NuShell" | str screaming-snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "NU_SHELL".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("NU_SHELL", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to SCREAMING_SNAKE_CASE",
|
||||
example: r#" "this_is_the_second_case" | str screaming-snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "THIS_IS_THE_SECOND_CASE".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("THIS_IS_THE_SECOND_CASE", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to SCREAMING_SNAKE_CASE",
|
||||
example: r#""this-is-the-first-case" | str screaming-snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "THIS_IS_THE_FIRST_CASE".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("THIS_IS_THE_FIRST_CASE", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to SCREAMING_SNAKE_CASE",
|
||||
@ -78,10 +69,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "NU_TEST".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("NU_TEST", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -49,26 +49,17 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to snake_case",
|
||||
example: r#" "NuShell" | str snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "nu_shell".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("nu_shell", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to snake_case",
|
||||
example: r#" "this_is_the_second_case" | str snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "this_is_the_second_case".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("this_is_the_second_case", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to snake_case",
|
||||
example: r#""this-is-the-first-case" | str snake-case"#,
|
||||
result: Some(Value::String {
|
||||
val: "this_is_the_first_case".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("this_is_the_first_case", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to snake_case",
|
||||
@ -78,10 +69,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["lang".to_string(), "gems".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "nu_test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("nu_test", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
@ -50,18 +50,12 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert a string to Title Case",
|
||||
example: "'nu-shell' | str title-case",
|
||||
result: Some(Value::String {
|
||||
val: "Nu Shell".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("Nu Shell", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a string to Title Case",
|
||||
example: "'this is a test case' | str title-case",
|
||||
result: Some(Value::String {
|
||||
val: "This Is A Test Case".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::string("This Is A Test Case", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "convert a column from a table to Title Case",
|
||||
@ -71,10 +65,7 @@ impl Command for SubCommand {
|
||||
span: Span::test_data(),
|
||||
cols: vec!["title".to_string(), "count".to_string()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: "Nu Test".to_string(),
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::string("Nu Test", Span::test_data()),
|
||||
Value::test_int(100),
|
||||
],
|
||||
}],
|
||||
|
Reference in New Issue
Block a user