mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00:00
Run a round of clippy --fix to fix a ton of lints (#7006)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com> Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
This commit is contained in:
parent
f1bde69131
commit
be5d71ea47
32 changed files with 51 additions and 53 deletions
|
@ -60,7 +60,7 @@ impl CommandCompletion {
|
|||
.matches_str(&x.to_string_lossy(), prefix)),
|
||||
Some(true)
|
||||
)
|
||||
&& is_executable::is_executable(&item.path())
|
||||
&& is_executable::is_executable(item.path())
|
||||
{
|
||||
if let Ok(name) = item.file_name().into_string() {
|
||||
executables.push(name);
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn read_plugin_file(
|
|||
|
||||
let plugin_path = engine_state.plugin_signatures.clone();
|
||||
if let Some(plugin_path) = plugin_path {
|
||||
let plugin_filename = plugin_path.to_string_lossy().to_owned();
|
||||
let plugin_filename = plugin_path.to_string_lossy();
|
||||
|
||||
if let Ok(contents) = std::fs::read(&plugin_path) {
|
||||
eval_source(
|
||||
|
@ -77,7 +77,7 @@ pub fn eval_config_contents(
|
|||
stack: &mut Stack,
|
||||
) {
|
||||
if config_path.exists() & config_path.is_file() {
|
||||
let config_filename = config_path.to_string_lossy().to_owned();
|
||||
let config_filename = config_path.to_string_lossy();
|
||||
|
||||
if let Ok(contents) = std::fs::read(&config_path) {
|
||||
eval_source(
|
||||
|
|
|
@ -372,7 +372,7 @@ impl DescriptionMenu {
|
|||
let description = self
|
||||
.get_value()
|
||||
.and_then(|suggestion| suggestion.description)
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
.unwrap_or_default()
|
||||
.lines()
|
||||
.skip(self.skipped_rows)
|
||||
.take(self.working_details.description_rows)
|
||||
|
@ -610,7 +610,7 @@ impl Menu for DescriptionMenu {
|
|||
let description_rows = self
|
||||
.get_value()
|
||||
.and_then(|suggestion| suggestion.description)
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
.unwrap_or_default()
|
||||
.lines()
|
||||
.count();
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ pub(crate) fn add_menus(
|
|||
let res = eval_block(&engine_state, &mut temp_stack, &block, input, false, false)?;
|
||||
|
||||
if let PipelineData::Value(value, None) = res {
|
||||
for menu in create_menus(&value, config)? {
|
||||
for menu in create_menus(&value)? {
|
||||
line_editor =
|
||||
add_menu(line_editor, &menu, engine_state.clone(), stack, config)?;
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
|||
span,
|
||||
},
|
||||
Value::Bool { val, .. } => Value::Binary {
|
||||
val: int_to_endian(if *val { 1i64 } else { 0 }),
|
||||
val: int_to_endian(i64::from(*val)),
|
||||
span,
|
||||
},
|
||||
Value::Date { val, .. } => Value::Binary {
|
||||
|
|
|
@ -198,7 +198,7 @@ impl Command for Ls {
|
|||
} else if full_paths || absolute_path {
|
||||
Some(path.to_string_lossy().to_string())
|
||||
} else if let Some(prefix) = &prefix {
|
||||
if let Ok(remainder) = path.strip_prefix(&prefix) {
|
||||
if let Ok(remainder) = path.strip_prefix(prefix) {
|
||||
if directory {
|
||||
// When the path is the same as the cwd, path_diff should be "."
|
||||
let path_diff =
|
||||
|
@ -215,7 +215,7 @@ impl Command for Ls {
|
|||
|
||||
Some(path_diff)
|
||||
} else {
|
||||
let new_prefix = if let Some(pfx) = diff_paths(&prefix, &cwd) {
|
||||
let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) {
|
||||
pfx
|
||||
} else {
|
||||
prefix.to_path_buf()
|
||||
|
|
|
@ -295,7 +295,7 @@ fn move_file(
|
|||
fn move_item(from: &Path, from_span: Span, to: &Path) -> Result<(), ShellError> {
|
||||
// We first try a rename, which is a quick operation. If that doesn't work, we'll try a copy
|
||||
// and remove the old file/folder. This is necessary if we're moving across filesystems or devices.
|
||||
std::fs::rename(&from, &to).or_else(|_| {
|
||||
std::fs::rename(from, to).or_else(|_| {
|
||||
match if from.is_file() {
|
||||
let mut options = fs_extra::file::CopyOptions::new();
|
||||
options.overwrite = true;
|
||||
|
|
|
@ -97,7 +97,7 @@ impl Command for Open {
|
|||
let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d'));
|
||||
let path = Path::new(path_no_whitespace);
|
||||
|
||||
if permission_denied(&path) {
|
||||
if permission_denied(path) {
|
||||
#[cfg(unix)]
|
||||
let error_msg = match path.metadata() {
|
||||
Ok(md) => format!(
|
||||
|
|
|
@ -284,8 +284,8 @@ fn rm(
|
|||
}
|
||||
|
||||
Ok(all_targets
|
||||
.into_iter()
|
||||
.map(move |(f, _)| {
|
||||
.into_keys()
|
||||
.map(move |f| {
|
||||
let is_empty = || match f.read_dir() {
|
||||
Ok(mut p) => p.next().is_none(),
|
||||
Err(_) => false,
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Command for Watch {
|
|||
.item
|
||||
.trim_end_matches(|x| matches!(x, '\x09'..='\x0d'));
|
||||
|
||||
let path = match nu_path::canonicalize_with(path_no_whitespace, &cwd) {
|
||||
let path = match nu_path::canonicalize_with(path_no_whitespace, cwd) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
|
|
|
@ -210,7 +210,7 @@ pub fn data_group(
|
|||
value.as_string()
|
||||
};
|
||||
|
||||
let group = groups.entry(group_key?).or_insert(vec![]);
|
||||
let group = groups.entry(group_key?).or_default();
|
||||
group.push(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ fn parse_aligned_columns<'a>(
|
|||
let parse_without_headers = |ls: Vec<&str>| {
|
||||
let mut indices = ls
|
||||
.iter()
|
||||
.flat_map(|s| find_indices(*s))
|
||||
.flat_map(|s| find_indices(s))
|
||||
.collect::<Vec<usize>>();
|
||||
|
||||
indices.sort_unstable();
|
||||
|
|
|
@ -284,9 +284,7 @@ pub fn run_seq(
|
|||
}
|
||||
}
|
||||
};
|
||||
if largest_dec > 0 {
|
||||
largest_dec -= 1;
|
||||
}
|
||||
largest_dec = largest_dec.saturating_sub(1);
|
||||
let separator = escape_sequences(&sep[..]);
|
||||
let terminator = match termy {
|
||||
Some(term) => escape_sequences(&term[..]),
|
||||
|
|
|
@ -96,7 +96,7 @@ pub fn median(values: &[Value], head: &Span) -> Result<Value, ShellError> {
|
|||
Ok(out.clone())
|
||||
}
|
||||
Pick::MedianAverage => {
|
||||
let idx_end = (values.len() / 2) as usize;
|
||||
let idx_end = values.len() / 2;
|
||||
let idx_start = idx_end - 1;
|
||||
|
||||
let left = sorted
|
||||
|
|
|
@ -376,8 +376,8 @@ fn helper(
|
|||
let headers = args.headers;
|
||||
let raw = args.raw;
|
||||
let login = match (user, password) {
|
||||
(Some(user), Some(password)) => Some(encode(&format!("{}:{}", user, password))),
|
||||
(Some(user), _) => Some(encode(&format!("{}:", user))),
|
||||
(Some(user), Some(password)) => Some(encode(format!("{}:{}", user, password))),
|
||||
(Some(user), _) => Some(encode(format!("{}:", user))),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ fn action(
|
|||
} => {
|
||||
match base64_config.action_type {
|
||||
ActionType::Encode => {
|
||||
Value::string(encode_config(&val, base64_config_enum), command_span)
|
||||
Value::string(encode_config(val, base64_config_enum), command_span)
|
||||
}
|
||||
|
||||
ActionType::Decode => {
|
||||
|
|
|
@ -548,7 +548,7 @@ impl ExternalCommand {
|
|||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
let mut process = std::process::Command::new(&head);
|
||||
let mut process = std::process::Command::new(head);
|
||||
|
||||
for (arg, arg_keep_raw) in self.args.iter().zip(self.arg_keep_raw.iter()) {
|
||||
// if arg is quoted, like "aa", 'aa', `aa`, or:
|
||||
|
|
|
@ -529,7 +529,7 @@ fn list_directory_contains_invalid_utf8() {
|
|||
let cwd = dirs.test();
|
||||
let path = cwd.join(s);
|
||||
|
||||
std::fs::create_dir_all(&path).expect("failed to create directory");
|
||||
std::fs::create_dir_all(path).expect("failed to create directory");
|
||||
|
||||
let actual = nu!(cwd: cwd, "ls");
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ pub fn find_in_dirs_env(
|
|||
for lib_dir in dirs {
|
||||
if let Ok(dir) = lib_dir.as_path() {
|
||||
// make sure the dir is absolute path
|
||||
if let Ok(dir_abs) = canonicalize_with(&dir, &cwd) {
|
||||
if let Ok(dir_abs) = canonicalize_with(dir, &cwd) {
|
||||
if let Ok(path) = canonicalize_with(filename, dir_abs) {
|
||||
return Ok(Some(path));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn glob_from(
|
|||
}
|
||||
(Some(p), path)
|
||||
} else {
|
||||
let path = if let Ok(p) = canonicalize_with(path, &cwd) {
|
||||
let path = if let Ok(p) = canonicalize_with(path, cwd) {
|
||||
p
|
||||
} else {
|
||||
return Err(ShellError::DirectoryNotFound(pattern.span, None));
|
||||
|
|
|
@ -335,7 +335,7 @@ impl Iterator for Paths {
|
|||
if let Some(scope) = self.scope.take() {
|
||||
if !self.dir_patterns.is_empty() {
|
||||
// Shouldn't happen, but we're using -1 as a special index.
|
||||
assert!(self.dir_patterns.len() < !0 as usize);
|
||||
assert!(self.dir_patterns.len() < !0);
|
||||
|
||||
fill_todo(&mut self.todo, &self.dir_patterns, 0, &scope, self.options);
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ impl Iterator for Paths {
|
|||
|
||||
// idx -1: was already checked by fill_todo, maybe path was '.' or
|
||||
// '..' that we can't match here because of normalization.
|
||||
if idx == !0 as usize {
|
||||
if idx == !0 {
|
||||
if self.require_dir && !is_dir(&path) {
|
||||
continue;
|
||||
}
|
||||
|
@ -771,7 +771,7 @@ fn fill_todo(
|
|||
// We know it's good, so don't make the iterator match this path
|
||||
// against the pattern again. In particular, it can't match
|
||||
// . or .. globs since these never show up as path components.
|
||||
todo.push(Ok((next_path, !0 as usize)));
|
||||
todo.push(Ok((next_path, !0)));
|
||||
} else {
|
||||
fill_todo(todo, patterns, idx + 1, &next_path, options);
|
||||
}
|
||||
|
@ -1222,7 +1222,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_path_join() {
|
||||
let pattern = Path::new("one").join(&Path::new("**/*.rs"));
|
||||
let pattern = Path::new("one").join(Path::new("**/*.rs"));
|
||||
assert!(Pattern::new(pattern.to_str().unwrap()).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,7 +469,7 @@ where
|
|||
let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32)
|
||||
+ 0x1_0000;
|
||||
|
||||
match char::from_u32(n as u32) {
|
||||
match char::from_u32(n) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return Err(self
|
||||
|
|
|
@ -3252,7 +3252,7 @@ pub fn find_in_dirs(
|
|||
for lib_dir in dirs {
|
||||
if let Ok(dir) = lib_dir.as_path() {
|
||||
// make sure the dir is absolute path
|
||||
if let Ok(dir_abs) = canonicalize_with(&dir, actual_cwd) {
|
||||
if let Ok(dir_abs) = canonicalize_with(dir, actual_cwd) {
|
||||
if let Ok(path) = canonicalize_with(filename, dir_abs) {
|
||||
return Some(path);
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ mod tests {
|
|||
fn check_expanded(s: &str) {
|
||||
let home = Path::new("/home");
|
||||
let buf = Some(PathBuf::from(home));
|
||||
assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(&home));
|
||||
assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(home));
|
||||
|
||||
// Tests the special case in expand_tilde for "/" as home
|
||||
let home = Path::new("/");
|
||||
|
|
|
@ -174,7 +174,7 @@ where
|
|||
.iter()
|
||||
.skip(skip)
|
||||
.take(amount)
|
||||
.map(|&x| x as u8)
|
||||
.copied()
|
||||
.collect();
|
||||
|
||||
if cfg.title {
|
||||
|
|
|
@ -347,14 +347,14 @@ impl Value {
|
|||
eprintln!("$config.log_level is not a string")
|
||||
}
|
||||
}
|
||||
"menus" => match create_menus(value, &config) {
|
||||
"menus" => match create_menus(value) {
|
||||
Ok(map) => config.menus = map,
|
||||
Err(e) => {
|
||||
eprintln!("$config.menus is not a valid list of menus");
|
||||
eprintln!("{:?}", e);
|
||||
}
|
||||
},
|
||||
"keybindings" => match create_keybindings(value, &config) {
|
||||
"keybindings" => match create_keybindings(value) {
|
||||
Ok(keybindings) => config.keybindings = keybindings,
|
||||
Err(e) => {
|
||||
eprintln!("$config.keybindings is not a valid keybindings list");
|
||||
|
@ -599,7 +599,7 @@ fn create_hooks(value: &Value) -> Result<Hooks, ShellError> {
|
|||
}
|
||||
|
||||
// Parses the config object to extract the strings that will compose a keybinding for reedline
|
||||
fn create_keybindings(value: &Value, config: &Config) -> Result<Vec<ParsedKeybinding>, ShellError> {
|
||||
fn create_keybindings(value: &Value) -> Result<Vec<ParsedKeybinding>, ShellError> {
|
||||
match value {
|
||||
Value::Record { cols, vals, span } => {
|
||||
// Finding the modifier value in the record
|
||||
|
@ -621,7 +621,7 @@ fn create_keybindings(value: &Value, config: &Config) -> Result<Vec<ParsedKeybin
|
|||
Value::List { vals, .. } => {
|
||||
let res = vals
|
||||
.iter()
|
||||
.map(|inner_value| create_keybindings(inner_value, config))
|
||||
.map(create_keybindings)
|
||||
.collect::<Result<Vec<Vec<ParsedKeybinding>>, ShellError>>();
|
||||
|
||||
let res = res?
|
||||
|
@ -636,7 +636,7 @@ fn create_keybindings(value: &Value, config: &Config) -> Result<Vec<ParsedKeybin
|
|||
}
|
||||
|
||||
// Parses the config object to extract the strings that will compose a keybinding for reedline
|
||||
pub fn create_menus(value: &Value, config: &Config) -> Result<Vec<ParsedMenu>, ShellError> {
|
||||
pub fn create_menus(value: &Value) -> Result<Vec<ParsedMenu>, ShellError> {
|
||||
match value {
|
||||
Value::Record { cols, vals, span } => {
|
||||
// Finding the modifier value in the record
|
||||
|
@ -667,7 +667,7 @@ pub fn create_menus(value: &Value, config: &Config) -> Result<Vec<ParsedMenu>, S
|
|||
Value::List { vals, .. } => {
|
||||
let res = vals
|
||||
.iter()
|
||||
.map(|inner_value| create_menus(inner_value, config))
|
||||
.map(create_menus)
|
||||
.collect::<Result<Vec<Vec<ParsedMenu>>, ShellError>>();
|
||||
|
||||
let res = res?.into_iter().flatten().collect::<Vec<ParsedMenu>>();
|
||||
|
|
|
@ -25,11 +25,11 @@ impl FromValue for Spanned<i64> {
|
|||
span: *span,
|
||||
}),
|
||||
Value::Filesize { val, span } => Ok(Spanned {
|
||||
item: *val as i64,
|
||||
item: *val,
|
||||
span: *span,
|
||||
}),
|
||||
Value::Duration { val, span } => Ok(Spanned {
|
||||
item: *val as i64,
|
||||
item: *val,
|
||||
span: *span,
|
||||
}),
|
||||
|
||||
|
@ -47,8 +47,8 @@ impl FromValue for i64 {
|
|||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Int { val, .. } => Ok(*val),
|
||||
Value::Filesize { val, .. } => Ok(*val as i64),
|
||||
Value::Duration { val, .. } => Ok(*val as i64),
|
||||
Value::Filesize { val, .. } => Ok(*val),
|
||||
Value::Duration { val, .. } => Ok(*val),
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"integer".into(),
|
||||
|
|
|
@ -157,7 +157,7 @@ impl ProcessInfo {
|
|||
pub fn command(&self) -> String {
|
||||
if let Ok(cmd) = &self.curr_proc.cmdline() {
|
||||
if !cmd.is_empty() {
|
||||
cmd.join(" ").replace('\n', " ").replace('\t', " ")
|
||||
cmd.join(" ").replace(['\n', '\t'], " ")
|
||||
} else {
|
||||
match self.curr_proc.stat() {
|
||||
Ok(p) => p.comm,
|
||||
|
@ -200,8 +200,8 @@ impl ProcessInfo {
|
|||
let curr_time = cs.utime + cs.stime;
|
||||
let prev_time = ps.utime + ps.stime;
|
||||
|
||||
let usage_ms = (curr_time - prev_time) * 1000
|
||||
/ procfs::ticks_per_second().unwrap_or(100) as u64;
|
||||
let usage_ms =
|
||||
(curr_time - prev_time) * 1000 / procfs::ticks_per_second().unwrap_or(100);
|
||||
let interval_ms =
|
||||
self.interval.as_secs() * 1000 + u64::from(self.interval.subsec_millis());
|
||||
usage_ms as f64 * 100.0 / interval_ms as f64
|
||||
|
|
|
@ -230,7 +230,7 @@ fn override_alignments(
|
|||
index_present: bool,
|
||||
alignments: Alignments,
|
||||
) {
|
||||
let offset = if header_present { 1 } else { 0 };
|
||||
let offset = usize::from(header_present);
|
||||
let (count_rows, count_columns) = table.shape();
|
||||
for row in offset..count_rows {
|
||||
for col in 0..count_columns {
|
||||
|
|
|
@ -131,7 +131,7 @@ pub struct Cell {
|
|||
impl From<String> for Cell {
|
||||
fn from(string: String) -> Self {
|
||||
Self {
|
||||
width: unicode_width_strip_ansi(&*string),
|
||||
width: unicode_width_strip_ansi(&string),
|
||||
contents: string,
|
||||
alignment: Alignment::Left,
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ impl NuProcess {
|
|||
}
|
||||
|
||||
pub fn construct(&self) -> Command {
|
||||
let mut command = Command::new(&executable_path());
|
||||
let mut command = Command::new(executable_path());
|
||||
|
||||
if let Some(cwd) = self.get_cwd() {
|
||||
command.current_dir(cwd);
|
||||
|
@ -84,7 +84,7 @@ impl NuProcess {
|
|||
|
||||
let paths = vec![test_bins_path()];
|
||||
|
||||
let paths_joined = match std::env::join_paths(&paths) {
|
||||
let paths_joined = match std::env::join_paths(paths) {
|
||||
Ok(all) => all,
|
||||
Err(_) => panic!("Couldn't join paths for PATH var."),
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ fn expand_path_no_change() {
|
|||
let path = "/foo/bar";
|
||||
|
||||
let cwd = std::env::current_dir().expect("Could not get current directory");
|
||||
let actual = expand_path_with(&path, cwd);
|
||||
let actual = expand_path_with(path, cwd);
|
||||
|
||||
assert_eq!(actual, PathBuf::from(path));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue