mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:36:00 +02:00
Add general refactorings (#3996)
This commit is contained in:
@ -47,7 +47,7 @@ pub fn get_flag_signature_spec(
|
||||
let mut starting_pos = arg.span.start() + 1;
|
||||
for c in remainder.chars() {
|
||||
let mut found = false;
|
||||
for (full_name, named_arg) in signature.named.iter() {
|
||||
for (full_name, named_arg) in &signature.named {
|
||||
if Some(c) == named_arg.0.get_short() {
|
||||
found = true;
|
||||
output.push((full_name.clone(), named_arg.0.clone()));
|
||||
|
@ -990,7 +990,7 @@ fn parse_arg(
|
||||
SyntaxShape::Table,
|
||||
SyntaxShape::String,
|
||||
];
|
||||
for shape in shapes.iter() {
|
||||
for shape in &shapes {
|
||||
if let (s, None) = parse_arg(*shape, scope, lite_arg) {
|
||||
return (s, None);
|
||||
}
|
||||
@ -1740,7 +1740,7 @@ fn expand_aliases_in_call(call: &mut LiteCommand, scope: &dyn ParserScope) {
|
||||
if let Some(name) = call.parts.get(0) {
|
||||
if let Some(mut expansion) = scope.get_alias(name) {
|
||||
// set the expansion's spans to point to the alias itself
|
||||
for item in expansion.iter_mut() {
|
||||
for item in &mut expansion {
|
||||
item.span = name.span;
|
||||
}
|
||||
|
||||
@ -2065,7 +2065,7 @@ pub fn classify_block(
|
||||
let mut error = None;
|
||||
|
||||
// Check for custom commands first
|
||||
for group in lite_block.block.iter() {
|
||||
for group in &lite_block.block {
|
||||
for pipeline in &group.pipelines {
|
||||
for call in &pipeline.commands {
|
||||
if let Some(first) = call.parts.first() {
|
||||
@ -2165,7 +2165,7 @@ pub fn classify_block(
|
||||
}
|
||||
|
||||
let definitions = scope.get_definitions();
|
||||
for definition in definitions.into_iter() {
|
||||
for definition in definitions {
|
||||
let name = definition.params.name.clone();
|
||||
if !output.definitions.contains_key(&name) {
|
||||
output.definitions.insert(name, definition.clone());
|
||||
@ -2335,7 +2335,7 @@ fn unit_parse_byte_units() {
|
||||
},
|
||||
];
|
||||
|
||||
for case in cases.iter() {
|
||||
for case in &cases {
|
||||
let input_len = case.string.len();
|
||||
let value_len = case.value.to_string().len();
|
||||
let input = case.string.clone().spanned(Span::new(0, input_len));
|
||||
@ -2423,7 +2423,7 @@ fn unit_parse_byte_units_decimal() {
|
||||
},
|
||||
];
|
||||
|
||||
for case in cases.iter() {
|
||||
for case in &cases {
|
||||
let input_len = case.string.len();
|
||||
let value_len = case.value_str.to_string().len();
|
||||
let input = case.string.clone().spanned(Span::new(0, input_len));
|
||||
|
@ -356,13 +356,13 @@ fn to_signature(
|
||||
) -> Signature {
|
||||
let mut sign = Signature::new(name);
|
||||
|
||||
for param in params.into_iter() {
|
||||
for param in params {
|
||||
// pub positional: Vec<(PositionalType, Description)>,
|
||||
sign.positional
|
||||
.push((param.pos_type, param.desc.unwrap_or_else(|| "".to_string())));
|
||||
}
|
||||
|
||||
for flag in flags.into_iter() {
|
||||
for flag in flags {
|
||||
sign.named.insert(
|
||||
flag.long_name,
|
||||
(flag.named_type, flag.desc.unwrap_or_else(|| "".to_string())),
|
||||
|
@ -11,14 +11,14 @@ pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>
|
||||
Expression::Garbage => vec![FlatShape::Garbage.spanned(e.span)],
|
||||
Expression::List(exprs) => {
|
||||
let mut output = vec![];
|
||||
for expr in exprs.iter() {
|
||||
for expr in exprs {
|
||||
output.append(&mut expression_to_flat_shape(expr));
|
||||
}
|
||||
output
|
||||
}
|
||||
Expression::Table(headers, cells) => {
|
||||
let mut output = vec![];
|
||||
for header in headers.iter() {
|
||||
for header in headers {
|
||||
output.append(&mut expression_to_flat_shape(header));
|
||||
}
|
||||
for row in cells {
|
||||
@ -31,7 +31,7 @@ pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>
|
||||
Expression::FullColumnPath(exprs) => {
|
||||
let mut output = vec![];
|
||||
output.append(&mut expression_to_flat_shape(&exprs.head));
|
||||
for member in exprs.tail.iter() {
|
||||
for member in &exprs.tail {
|
||||
if let UnspannedPathMember::String(_) = &member.unspanned {
|
||||
output.push(FlatShape::StringMember.spanned(member.span));
|
||||
}
|
||||
@ -102,7 +102,7 @@ pub fn shapes(commands: &Block) -> Vec<Spanned<FlatShape>> {
|
||||
}
|
||||
|
||||
if let Some(named) = &internal.args.named {
|
||||
for (_, named_arg) in named.iter() {
|
||||
for (_, named_arg) in named {
|
||||
match named_arg {
|
||||
NamedValue::PresentSwitch(span) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
@ -129,7 +129,7 @@ pub fn shapes(commands: &Block) -> Vec<Spanned<FlatShape>> {
|
||||
}
|
||||
|
||||
if let Some(named) = &call.named {
|
||||
for (_, named_arg) in named.iter() {
|
||||
for (_, named_arg) in named {
|
||||
match named_arg {
|
||||
NamedValue::PresentSwitch(span) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
|
Reference in New Issue
Block a user