diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..e43ca92113 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +on: push + +name: Continuous integration + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + components: rustfmt, clippy + + - uses: actions-rs/cargo@v1 + with: + command: build + + - uses: actions-rs/cargo@v1 + with: + command: test + + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/crates/nu-command/src/do_.rs b/crates/nu-command/src/do_.rs index dba61b6024..3630e84ff6 100644 --- a/crates/nu-command/src/do_.rs +++ b/crates/nu-command/src/do_.rs @@ -26,7 +26,7 @@ impl Command for Do { ) -> Result { let block = &call.positional[0]; - let out = eval_expression(context, &block)?; + let out = eval_expression(context, block)?; match out { Value::Block { val: block_id, .. } => { diff --git a/crates/nu-command/src/each.rs b/crates/nu-command/src/each.rs index f2964b3798..9807749293 100644 --- a/crates/nu-command/src/each.rs +++ b/crates/nu-command/src/each.rs @@ -48,7 +48,7 @@ impl Command for Each { let block = engine_state.get_block(block); let state = context.enter_scope(); - state.add_var(var_id, x.clone()); + state.add_var(var_id, x); //FIXME: DON'T UNWRAP eval_block(&state, block, Value::nothing()).unwrap() @@ -63,7 +63,7 @@ impl Command for Each { let block = engine_state.get_block(block); let state = context.enter_scope(); - state.add_var(var_id, x.clone()); + state.add_var(var_id, x); //FIXME: DON'T UNWRAP eval_block(&state, block, Value::nothing()).unwrap() diff --git a/crates/nu-command/src/for_.rs b/crates/nu-command/src/for_.rs index 792a656011..7965c1fb5d 100644 --- a/crates/nu-command/src/for_.rs +++ b/crates/nu-command/src/for_.rs @@ -60,7 +60,7 @@ impl Command for For { let block = engine_state.get_block(block); let state = context.enter_scope(); - state.add_var(var_id, x.clone()); + state.add_var(var_id, x); //FIXME: DON'T UNWRAP eval_block(&state, block, Value::nothing()).unwrap() @@ -76,7 +76,7 @@ impl Command for For { let block = engine_state.get_block(block); let state = context.enter_scope(); - state.add_var(var_id, x.clone()); + state.add_var(var_id, x); //FIXME: DON'T UNWRAP eval_block(&state, block, Value::nothing()).unwrap() diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 8b9aefe656..327506bbca 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -247,12 +247,10 @@ fn calculate_end_span( && spans.len() > (signature.required_positional.len() - positional_idx) { spans.len() - (signature.required_positional.len() - positional_idx - 1) + } else if signature.num_positionals_after(positional_idx) == 0 { + spans.len() } else { - if signature.num_positionals_after(positional_idx) == 0 { - spans.len() - } else { - spans_idx + 1 - } + spans_idx + 1 } } } @@ -496,7 +494,7 @@ pub fn parse_call( let cmd_start = pos; if expand_aliases { - if let Some(expansion) = working_set.find_alias(&name) { + if let Some(expansion) = working_set.find_alias(name) { let orig_span = spans[pos]; //let mut spans = spans.to_vec(); let mut new_spans: Vec = vec![]; @@ -992,7 +990,7 @@ pub fn parse_string( //TODO: Handle error case pub fn parse_shape_name( - working_set: &StateWorkingSet, + _working_set: &StateWorkingSet, bytes: &[u8], span: Span, ) -> (SyntaxShape, Option) { @@ -1018,7 +1016,7 @@ pub fn parse_shape_name( (result, None) } -pub fn parse_type(working_set: &StateWorkingSet, bytes: &[u8]) -> Type { +pub fn parse_type(_working_set: &StateWorkingSet, bytes: &[u8]) -> Type { if bytes == b"int" { Type::Int } else { @@ -1479,7 +1477,7 @@ pub fn parse_list_expression( expr: Expr::List(args), span, ty: Type::List(Box::new(if let Some(ty) = contained_type { - ty.clone() + ty } else { Type::Unknown })), @@ -2001,14 +1999,11 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) { let signature = sig.as_signature(); working_set.exit_scope(); - match (name, signature) { - (Some(name), Some(mut signature)) => { - signature.name = name; - let decl = signature.predeclare(); + if let (Some(name), Some(mut signature)) = (name, signature) { + signature.name = name; + let decl = signature.predeclare(); - working_set.add_decl(decl); - } - _ => {} + working_set.add_decl(decl); } } } diff --git a/crates/nu-parser/src/type_check.rs b/crates/nu-parser/src/type_check.rs index 9ea5f68eaf..67a082c67f 100644 --- a/crates/nu-parser/src/type_check.rs +++ b/crates/nu-parser/src/type_check.rs @@ -15,7 +15,7 @@ pub fn type_compatible(lhs: &Type, rhs: &Type) -> bool { } pub fn math_result_type( - working_set: &StateWorkingSet, + _working_set: &StateWorkingSet, lhs: &mut Expression, op: &mut Expression, rhs: &mut Expression, diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index af1f940ac6..31ad6b6b2a 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -119,6 +119,7 @@ impl EngineState { .expect("internal error: missing variable") } + #[allow(clippy::borrowed_box)] pub fn get_decl(&self, decl_id: DeclId) -> &Box { self.decls .get(decl_id) @@ -460,6 +461,7 @@ impl<'a> StateWorkingSet<'a> { } } + #[allow(clippy::borrowed_box)] pub fn get_decl(&self, decl_id: DeclId) -> &Box { let num_permanent_decls = self.permanent_state.num_decls(); if decl_id < num_permanent_decls { diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 5476a07a94..eef982b8fe 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -249,9 +249,8 @@ impl Signature { pub fn num_positionals_after(&self, idx: usize) -> usize { let mut total = 0; - let mut curr = 0; - for positional in &self.required_positional { + for (curr, positional) in self.required_positional.iter().enumerate() { match positional.shape { SyntaxShape::Keyword(..) => { // Keywords have a required argument, so account for that @@ -265,7 +264,6 @@ impl Signature { } } } - curr += 1; } total } diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index c88bc4be60..7e47fd75d4 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -9,13 +9,11 @@ pub struct ValueStream(pub Rc>>); impl ValueStream { pub fn into_string(self) -> String { - let val: Vec = self.collect(); format!( "[{}]", - val.into_iter() - .map(|x| x.into_string()) + self.map(|x| x.into_string()) .collect::>() - .join(", ".into()) + .join(", ") ) } @@ -59,23 +57,21 @@ pub struct RowStream(Rc>>>); impl RowStream { pub fn into_string(self, headers: Vec) -> String { - let val: Vec> = self.collect(); format!( "[{}]\n[{}]", headers .iter() .map(|x| x.to_string()) .collect::>() - .join(", ".into()), - val.into_iter() - .map(|x| { - x.into_iter() - .map(|x| x.into_string()) - .collect::>() - .join(", ".into()) - }) - .collect::>() - .join("\n") + .join(", "), + self.map(|x| { + x.into_iter() + .map(|x| x.into_string()) + .collect::>() + .join(", ") + }) + .collect::>() + .join("\n") ) } }