Skip to content

Commit

Permalink
Adjust clippy settings (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored May 20, 2024
1 parent ff1615c commit 39a0417
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 47 deletions.
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ members = ["cli", "parser", "shell", "interactive-shell"]
default-members = ["cli", "parser", "shell", "interactive-shell"]

[workspace.package]
categories = ["command-line-utilities", "development-tools"]
edition = "2021"
keywords = ["cli", "shell", "sh", "bash", "script"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/reubeno/brush"
version = "0.1.0"

[workspace.lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "deny", priority = -1 }
cargo = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 }
expect_used = "deny"
format_push_string = "deny"
panic = "deny"
panic_in_result_fn = "deny"
todo = "deny"
unwrap_in_result = "deny"
bool_to_int_with_if = "allow"
collapsible_else_if = "allow"
collapsible_if = "allow"
Expand All @@ -22,9 +34,9 @@ missing_panics_doc = "allow"
must_use_candidate = "allow"
redundant_closure_for_method_calls = "allow"
redundant_else = "allow"
result_large_err = "allow"
similar_names = "allow"
struct_excessive_bools = "allow"
result_large_err = "allow"

[profile.release]
opt-level = "z"
Expand Down
4 changes: 4 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "brush-cli"
description = "brush shell"
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[[bin]]
Expand Down
8 changes: 6 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ fn main() {
.without_time()
.with_filter(filter);

tracing_subscriber::registry()
if tracing_subscriber::registry()
.with(stderr_log_layer)
.try_init()
.expect("Failed to initialize tracing.");
.is_err()
{
// Something went wrong; proceed on anyway but complain audibly.
eprintln!("warning: failed to initialize tracing.");
}

//
// Run.
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ impl TestCase {
}
WhichShell::NamedShell(name) => (std::process::Command::new(name), None),
},
ShellInvocation::ExecScript(_) => todo!("UNIMPLEMENTED: exec script test"),
ShellInvocation::ExecScript(_) => unimplemented!("exec script test"),
};

for arg in &shell_config.default_args {
Expand Down
15 changes: 9 additions & 6 deletions interactive-shell/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "brush-interactive-shell"
description = "Shell"
description = "Interactive shell for brush"
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[lib]
Expand All @@ -15,10 +19,9 @@ workspace = true
[dependencies]
brush-parser = { path = "../parser" }
brush-shell = { path = "../shell" }
rustyline = { git = "https://github.com/reubeno/rustyline", rev = "023a08093e9b8ff81f9d8e096e00a23e6e83167a", features = ["derive"] }
thiserror = "1.0.61"
tokio = { version = "1.37.0", features = [
"macros",
"signal",
rustyline = { git = "https://github.com/reubeno/rustyline", rev = "023a08093e9b8ff81f9d8e096e00a23e6e83167a", features = [
"derive",
] }
thiserror = "1.0.61"
tokio = { version = "1.37.0", features = ["macros", "signal"] }
tracing = "0.1.40"
6 changes: 5 additions & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "brush-parser"
description = "Parser"
description = "Shell parser for brush"
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[lib]
Expand Down
6 changes: 5 additions & 1 deletion shell/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "brush-shell"
description = "brush Shell"
description = "Core for brush shell"
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[lib]
Expand Down
15 changes: 8 additions & 7 deletions shell/src/builtins/complete.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{arg, Parser};
use std::collections::HashMap;
use std::fmt::Write as _;
use std::io::Write;

use crate::builtin::{BuiltinCommand, BuiltinExitCode};
Expand Down Expand Up @@ -350,25 +351,25 @@ impl CompleteCommand {
}

if let Some(glob_pattern) = &spec.glob_pattern {
s.push_str(&std::format!(" -G {glob_pattern}"));
write!(s, " -G {glob_pattern}")?;
}
if let Some(word_list) = &spec.word_list {
s.push_str(&std::format!(" -W {word_list}"));
write!(s, " -W {word_list}")?;
}
if let Some(function_name) = &spec.function_name {
s.push_str(&std::format!(" -F {function_name}"));
write!(s, " -F {function_name}")?;
}
if let Some(command) = &spec.command {
s.push_str(&std::format!(" -C {command}"));
write!(s, " -C {command}")?;
}
if let Some(filter_pattern) = &spec.filter_pattern {
s.push_str(&std::format!(" -X {filter_pattern}"));
write!(s, " -X {filter_pattern}")?;
}
if let Some(prefix) = &spec.prefix {
s.push_str(&std::format!(" -P {prefix}"));
write!(s, " -P {prefix}")?;
}
if let Some(suffix) = &spec.suffix {
s.push_str(&std::format!(" -S {suffix}"));
write!(s, " -S {suffix}")?;
}

if let Some(command_name) = command_name {
Expand Down
1 change: 1 addition & 0 deletions shell/src/builtins/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ impl DeclareCommand {
Ok(true)
}

#[allow(clippy::unwrap_in_result)]
fn declaration_to_name_and_value(
declaration: &CommandArg,
) -> Result<(String, Option<String>, Option<ShellValueLiteral>, bool), error::Error> {
Expand Down
1 change: 0 additions & 1 deletion shell/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ fn decl_builtin<B: BuiltinDeclarationCommand + Send>() -> BuiltinRegistration {
}
}

#[allow(dead_code)]
fn special_decl_builtin<B: BuiltinDeclarationCommand + Send>() -> BuiltinRegistration {
BuiltinRegistration {
execute_func: exec_declaration_builtin::<B>,
Expand Down
9 changes: 4 additions & 5 deletions shell/src/builtins/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl BuiltinCommand for ReadCommand {
return error::unimp("read -u");
}

let input_line = read_line(context.stdin())?;
let input_line = read_line(context.stdin());
if let Some(input_line) = input_line {
let mut variable_names: VecDeque<String> = self.variable_names.clone().into();
for field in input_line.split_ascii_whitespace() {
Expand All @@ -105,8 +105,7 @@ impl BuiltinCommand for ReadCommand {
}
}

#[allow(clippy::unnecessary_wraps)]
fn read_line(mut file: openfiles::OpenFile) -> Result<Option<String>, crate::error::Error> {
fn read_line(mut file: openfiles::OpenFile) -> Option<String> {
let mut line = String::new();
let mut buffer = [0; 1]; // 1-byte buffer

Expand All @@ -124,8 +123,8 @@ fn read_line(mut file: openfiles::OpenFile) -> Result<Option<String>, crate::err
}

if line.is_empty() {
Ok(None)
None
} else {
Ok(Some(line))
Some(line)
}
}
13 changes: 4 additions & 9 deletions shell/src/builtins/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BuiltinCommand for TrapCommand {
} else if self.args.len() == 1 {
let signal = self.args[0].as_str();
let signal_type = parse_signal(signal)?;
Self::remove_all_handlers(&mut context, signal_type)?;
Self::remove_all_handlers(&mut context, signal_type);
Ok(BuiltinExitCode::Success)
} else {
let handler = &self.args[0];
Expand All @@ -50,7 +50,7 @@ impl BuiltinCommand for TrapCommand {
signal_types.push(parse_signal(signal)?);
}

Self::register_handler(&mut context, signal_types, handler.as_str())?;
Self::register_handler(&mut context, signal_types, handler.as_str());
Ok(BuiltinExitCode::Success)
}
}
Expand Down Expand Up @@ -86,29 +86,24 @@ impl TrapCommand {
Ok(())
}

#[allow(clippy::unnecessary_wraps)]
fn remove_all_handlers(
context: &mut crate::context::CommandExecutionContext<'_>,
signal: traps::TrapSignal,
) -> Result<(), error::Error> {
) {
context.shell.traps.remove_handlers(signal);
Ok(())
}

#[allow(clippy::unnecessary_wraps)]
fn register_handler(
context: &mut crate::context::CommandExecutionContext<'_>,
signals: Vec<traps::TrapSignal>,
handler: &str,
) -> Result<(), error::Error> {
) {
for signal in signals {
context
.shell
.traps
.register_handler(signal, handler.to_owned());
}

Ok(())
}
}

Expand Down
17 changes: 7 additions & 10 deletions shell/src/builtins/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,32 @@ pub(crate) struct UnsetCommand {

#[derive(Parser)]
#[clap(group = clap::ArgGroup::new("name-interpretation").multiple(false).required(false))]
#[allow(clippy::struct_field_names)]
pub(crate) struct UnsetNameInterpretation {
#[arg(
short = 'f',
group = "name-interpretation",
help = "treat each name as a shell function"
)]
names_are_shell_functions: bool,
shell_functions: bool,

#[arg(
short = 'v',
group = "name-interpretation",
help = "treat each name as a shell variable"
)]
names_are_shell_variables: bool,
shell_variables: bool,

#[arg(
short = 'n',
group = "name-interpretation",
help = "treat each name as a name reference"
)]
names_are_name_references: bool,
name_references: bool,
}

impl UnsetNameInterpretation {
pub fn unspecified(&self) -> bool {
!self.names_are_shell_functions
&& !self.names_are_shell_variables
&& !self.names_are_name_references
!self.shell_functions && !self.shell_variables && !self.name_references
}
}

Expand All @@ -54,14 +51,14 @@ impl BuiltinCommand for UnsetCommand {
//
// TODO: implement nameref
//
if self.name_interpretation.names_are_name_references {
if self.name_interpretation.name_references {
return crate::error::unimp("unset: name references are not yet implemented");
}

let unspecified = self.name_interpretation.unspecified();

for name in &self.names {
if unspecified || self.name_interpretation.names_are_shell_variables {
if unspecified || self.name_interpretation.shell_variables {
let parameter =
parser::word::parse_parameter(name, &context.shell.parser_options())?;

Expand Down Expand Up @@ -90,7 +87,7 @@ impl BuiltinCommand for UnsetCommand {
}

// TODO: Check if functions can be readonly.
if unspecified || self.name_interpretation.names_are_shell_functions {
if unspecified || self.name_interpretation.shell_functions {
if context.shell.funcs.remove(name).is_some() {
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions shell/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ impl<'a> WordExpander<'a> {
Ok(value.to_string())
}

#[allow(clippy::unwrap_in_result)]
fn uppercase_first_char(
&mut self,
s: String,
Expand Down Expand Up @@ -1252,6 +1253,7 @@ impl<'a> WordExpander<'a> {
}
}

#[allow(clippy::unwrap_in_result)]
fn lowercase_first_char(
&mut self,
s: String,
Expand Down
1 change: 0 additions & 1 deletion shell/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl Display for JobAnnotation {

pub struct Job {
join_handles: VecDeque<JobJoinHandle>,
#[allow(dead_code)]
pids: Vec<u32>,
annotation: JobAnnotation,

Expand Down
1 change: 1 addition & 0 deletions shell/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub(crate) fn remove_smallest_matching_suffix<'a>(
}

#[cfg(test)]
#[allow(clippy::panic_in_result_fn)]
mod tests {
use super::*;
use anyhow::Result;
Expand Down
6 changes: 4 additions & 2 deletions shell/src/shell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::collections::{HashMap, VecDeque};
use std::fmt::Write as _;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -529,10 +530,11 @@ impl Shell {
error_message.push_str(inner.to_string().as_str());

if let Some(position) = position {
error_message.push_str(&format!(
write!(
error_message,
" (detected near line {} column {})",
position.line, position.column
));
)?;
}

tracing::error!("{}", error_message);
Expand Down

0 comments on commit 39a0417

Please sign in to comment.