Commit c85d2ef4 authored by matu3ba's avatar matu3ba
Browse files

fix(clippy): define and fix clippy lints, add documentation+license

clippy.toml: Add complexity thresholds for cognitive and type and the
msrv to latest stable Rust.
crates in members/: Add documentation and licence.
Some lints could not be autocorrected and Rust could not figure out
which, so manually correct all of them.
parent a7c02229
......@@ -12,16 +12,16 @@ authors = [
"Sag0Sag0 <Sag0Sag0@users.noreply.github.com>",
]
build = "build.rs"
categories = ["command-line-utilities", "config"]
description = "The Ion Shell"
documentation = "https://doc.redox-os.org/ion-manual/"
edition = "2018"
keywords = ["shell", "script", "program", "config", "configuration"]
license-file = "LICENSE"
name = "ion-shell"
readme = "README.md"
repository = "https://gitlab.redox-os.org/redox-os/ion"
version = "1.0.0-alpha"
edition = "2018"
keywords = ["shell", "script", "program", "config", "configuration"]
categories = ["command-line-utilities", "config"]
documentation = "https://doc.redox-os.org/ion-manual/"
[badges]
gitlab = { repository = "https://gitlab.redox-os.org/redox-os/ion", branch = "master" }
......
cognitive-complexity-threshold = 100
type-complexity-threshold = 1000
msrv = "1.53.0"
[package]
name = "builtins-proc"
version = "0.1.0"
authors = ["Xavier L'Heureux <xavier.lheureux@icloud.com>"]
categories = ["development-tools::procedural-macro-helpers"]
description = "Expose author list of Ion Shell as macro"
edition = "2018"
keywords = ["ion", "shell", "builtin"]
license = "MIT"
name = "builtins-proc"
readme = "README.md"
repository = "https://gitlab.redox-os.org/redox-os/ion"
version = "0.1.0"
[dependencies]
quote = "1.0"
......
......@@ -3,7 +3,6 @@ use darling::{util::Flag, FromMeta};
use proc_macro::TokenStream;
use quote::quote;
use std::{fs::File, io::Write};
use syn;
#[derive(Debug, FromMeta)]
struct MacroArgs {
......@@ -39,12 +38,11 @@ pub fn builtin(attr: TokenStream, item: TokenStream) -> TokenStream {
Please report all bugs at https://gitlab.redox-os.org/redox-os/ion/issues.
Ion is still in active development and help in finding bugs is much appreciated!";
let extra = format!(
"
let extra = "
AUTHORS
The Ion developers, under the Redox OS organisation"
);
.to_string();
let man = format!(
"NAME\n {names} - {short_description}\n\n{help}\n\n{bugs}{extra}",
names = names,
......@@ -57,7 +55,7 @@ AUTHORS
if cfg!(feature = "man") {
let mut man = File::create(format!("manual/builtins/{}.1", &ident)).unwrap();
man.write(help.as_bytes()).unwrap();
man.write_all(help.as_bytes()).unwrap();
}
let result = quote! {
......
[package]
name = "ion-ranges"
version = "0.1.0"
authors = ["Michael Murphy <mmstickman@gmail.com>"]
edition = "2018"
categories = ["development-tools"]
description = "extra traits to parse the stdlib's range"
edition = "2018"
keywords = ["shell", "range"]
license = "MIT"
name = "ion-ranges"
readme = "README.md"
repository = "https://gitlab.redox-os.org/redox-os/ion"
version = "0.1.0"
[dependencies]
......@@ -60,7 +60,7 @@ impl<K: Hash + Eq, V: Clone> Scopes<K, V> {
self.current -= 1;
}
pub fn pop_scopes<'a>(&'a mut self, index: usize) -> impl Iterator<Item = Scope<K, V>> + 'a {
pub fn pop_scopes(&mut self, index: usize) -> impl Iterator<Item = Scope<K, V>> + '_ {
self.current = index;
self.scopes.drain(index + 1..)
}
......@@ -126,7 +126,7 @@ impl<K: Hash + Eq, V: Clone> Scopes<K, V> {
None
}
Namespace::Any => self.scopes().filter_map(|scope| scope.get(name)).next(),
Namespace::Any => self.scopes().find_map(|scope| scope.get(name)),
}
}
......
#![allow(clippy::from_over_into)]
use super::Value;
use small;
use std::{
......
use ion_shell::{builtin, builtins::Status, types::Str, Shell, Signal};
use nix::{sys::signal, unistd::Pid};
use std::{error::Error, os::unix::process::CommandExt, process::Command};
use std::{os::unix::process::CommandExt, process::Command};
#[builtin(
desc = "suspend the current shell",
......@@ -92,7 +92,7 @@ pub fn exec(args: &[Str], _shell: &mut Shell<'_>) -> Status {
if clear_env {
command.env_clear();
}
Status::error(format!("ion: exec: {}", command.exec().description()))
Status::error(format!("ion: exec: {}", command.exec().to_string()))
}
None => Status::error("ion: exec: no command provided"),
}
......
......@@ -2,7 +2,11 @@ use auto_enums::auto_enum;
use glob::{glob_with, MatchOptions};
use ion_shell::{expansion::Expander, Shell};
use liner::{Completer, CursorPosition, Event, EventKind};
use std::{env, iter, path::PathBuf, str};
use std::{
env, iter,
path::{Path, PathBuf},
str,
};
pub struct IonCompleter<'a, 'b> {
shell: &'b Shell<'a>,
......@@ -256,7 +260,7 @@ impl<'a, 'b> Completer for IonFileCompleter<'a, 'b> {
}
#[auto_enum]
fn filename_completion<'a>(start: &'a str, path: &'a PathBuf) -> impl Iterator<Item = String> + 'a {
fn filename_completion<'a>(start: &'a str, path: &Path) -> impl Iterator<Item = String> + 'a {
let unescaped_start = unescape(start);
let mut split_start = unescaped_start.split('/');
......
......@@ -195,10 +195,7 @@ impl<'a> InteractiveShell<'a> {
let huponexit = self.huponexit.clone();
let set_huponexit: BuiltinFunction = &move |args, _shell| {
huponexit.set(match args.get(1).map(AsRef::as_ref) {
Some("false") | Some("off") => false,
_ => true,
});
huponexit.set(!matches!(args.get(1).map(AsRef::as_ref), Some("false") | Some("off")));
Status::SUCCESS
};
......
......@@ -79,7 +79,7 @@ fn vi_indicator_variable(mode: ViPromptMode) -> &'static str {
}
}
fn vi_prompt_indicator<'a>(shell: &mut Shell<'a>, mode: ViPromptMode) -> String {
fn vi_prompt_indicator(shell: &mut Shell, mode: ViPromptMode) -> String {
shell
.variables()
.get_str(vi_indicator_variable(mode))
......
......@@ -5,16 +5,16 @@ use std::io::ErrorKind;
impl<'a> InteractiveShell<'a> {
/// Make sure to reset the fd to blocking mode
fn to_blocking(fd: std::os::unix::io::RawFd) {
fn change_blocking(fd: std::os::unix::io::RawFd) {
fcntl(fd, FcntlArg::F_SETFL(OFlag::O_RDWR)).unwrap();
}
/// Ion's interface to Liner's `read_line` method, which handles everything related to
/// rendering, controlling, and getting input from the prompt.
pub fn readln<T: Fn(&mut Shell<'_>)>(&self, prep_for_exit: &T) -> Option<String> {
Self::to_blocking(0);
Self::to_blocking(1);
Self::to_blocking(2);
Self::change_blocking(0);
Self::change_blocking(1);
Self::change_blocking(2);
let prompt = self.prompt();
let line = self.context.borrow_mut().read_line(
prompt,
......
......@@ -183,11 +183,7 @@ fn string_var_is_not_empty(stringvar: &str, shell: &Shell<'_>) -> bool {
/// Returns true if a function with the given name is defined
fn function_is_defined(function: &str, shell: &Shell<'_>) -> bool {
if let Some(Value::Function(_)) = shell.variables().get(function) {
true
} else {
false
}
matches!(shell.variables().get(function), Some(Value::Function(_)))
}
#[cfg(test)]
mod tests {
......
......@@ -59,7 +59,7 @@ impl Status {
}
impl From<Status> for Value<Rc<types::Function>> {
fn from(status: Status) -> Self { Value::Str(status.into()) }
fn from(status: Status) -> Self { Self::Str(status.into()) }
}
impl From<Status> for types::Str {
......
......@@ -48,7 +48,7 @@ fn eval_arg(arg: &str, shell: &mut Shell<'_>) -> types::Str {
// On error returns an empty String.
fn get_var_string(name: &str, shell: &mut Shell<'_>) -> Option<types::Str> {
if name.chars().nth(0)? != '$' {
if name.chars().next()? != '$' {
return None;
}
......
#![allow(unused_braces)]
/// helpers for creating help
pub mod man_pages;
......@@ -65,7 +66,7 @@ pub type BuiltinFunction<'a> = &'a dyn Fn(&[types::Str], &mut Shell<'_>) -> Stat
// parses -N or +N patterns
// required for popd, pushd, dirs
fn parse_numeric_arg(arg: &str) -> Option<(bool, usize)> {
let b = match arg.chars().nth(0) {
let b = match arg.chars().next() {
Some('+') => Some(true),
Some('-') => Some(false),
_ => None,
......@@ -423,9 +424,9 @@ DESCRIPTION
)]
pub fn dirs(args: &[types::Str], shell: &mut Shell<'_>) -> Status {
// converts pbuf to an absolute path if possible
fn try_abs_path(pbuf: &PathBuf) -> Cow<'_, str> {
fn try_abs_path(pbuf: &Path) -> Cow<'_, str> {
Cow::Owned(
pbuf.canonicalize().unwrap_or_else(|_| pbuf.clone()).to_string_lossy().to_string(),
pbuf.canonicalize().unwrap_or_else(|_| pbuf.to_owned()).to_string_lossy().to_string(),
)
}
......
......@@ -27,7 +27,7 @@ pub fn status(args: &[types::Str], shell: &mut Shell<'_>) -> Status {
let mut interactive = false;
let mut filename = false;
let is_login = env::args().nth(0).unwrap().chars().nth(0).unwrap() == '-';
let is_login = env::args().next().unwrap().starts_with('-');
match args.len() {
1 => {
......
......@@ -23,13 +23,13 @@ impl ForValueExpression {
}
Ok(if output.is_empty() {
ForValueExpression::Multiple(output)
Self::Multiple(output)
} else if let (Some(range), true) = (ranges::parse_range(&output[0]), output.len() == 1) {
ForValueExpression::Range(range)
Self::Range(range)
} else if output.len() > 1 {
ForValueExpression::Multiple(output)
Self::Multiple(output)
} else {
ForValueExpression::Normal(output[0].clone())
Self::Normal(output[0].clone())
})
}
}
......@@ -41,7 +41,7 @@ pub enum MethodError {
}
impl<'a, 'b, E: 'b + Expander> MethodArgs<'a, 'b, E> {
pub fn array<'c>(&'c mut self) -> impl Iterator<Item = types::Str> + 'c {
pub fn array(&mut self) -> impl Iterator<Item = types::Str> + '_ {
let expand = &mut (*self.expand);
ArgumentSplitter::new(self.args)
.flat_map(move |x| expand.expand_string(x).unwrap_or_else(|_| types::Args::new()))
......
......@@ -60,12 +60,10 @@ fn escape(input: &str) -> String {
12 => output.push_str("\\f"),
13 => output.push_str("\\r"),
27 => output.push_str("\\e"),
n if n != 59
&& n != 95
&& ((n >= 33 && n < 48)
|| (n >= 58 && n < 65)
|| (n >= 91 && n < 97)
|| (n >= 123 && n < 127)) =>
n if n != 59 && n != 95 && (33..48).contains(&n)
|| (58..65).contains(&n)
|| (91..97).contains(&n)
|| (123..127).contains(&n) =>
{
output.push('\\');
output.push(n as char);
......@@ -349,9 +347,7 @@ impl<'a> StringMethod<'a> {
};
}
_ => {
return Err(
Error::from(MethodError::InvalidScalarMethod(self.method.to_string())).into()
)
return Err(Error::from(MethodError::InvalidScalarMethod(self.method.to_string())))
}
}
Ok(())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment