Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/TestingCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ jobs:
linux-ubuntu:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Fetch
run: cargo fetch
- name: Clippy
run: cargo clippy
- name: Build
run: cargo build --release --verbose
- name: Run tests
Expand All @@ -42,8 +43,9 @@ jobs:
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- name: Fetch
run: cargo fetch
- name: Clippy
run: cargo clippy
- name: Build
run: cargo build --release --verbose
- name: Run tests
run: cargo test --release --verbose

47 changes: 46 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,49 @@ chrono = { version = "0.4", default-features = false, features = ["clock"] }
libc = "0.2"
regex = "1.10"
gettext-rs = { path = "./gettext-rs" }
errno = "0.3"
errno = "0.3"

[workspace.lints.clippy]
all = {level = "deny", priority = -1}

assign_op_pattern = "warn"
bool_comparison = "warn"
clone_on_copy = "warn"
collapsible_else_if = "warn"
collapsible_if = "warn"
comparison_chain = "warn"
derivable_impls = "warn"
derived_hash_with_manual_eq = "warn"
enum_variant_names = "allow"
format_in_format_args = "warn"
if_same_then_else = "warn"
int_plus_one = "warn"
large_enum_variant = "warn"
len_zero = "warn"
let_and_return = "warn"
manual_find = "warn"
manual_flatten = "warn"
manual_map = "warn"
manual_unwrap_or = "warn"
manual_unwrap_or_default = "warn"
match_like_matches_macro = "warn"
needless_lifetimes = "warn"
needless_range_loop = "warn"
new_without_default = "warn"
nonminimal_bool = "warn"
not_unsafe_ptr_arg_deref = "warn"
precedence = "warn"
redundant_field_names = "warn"
redundant_pattern_matching = "allow"
redundant_static_lifetimes = "warn"
result_large_err = "warn"
single_match = "warn"
suspicious_open_options = "warn"
too_many_arguments = "warn"
type_complexity = "warn"
unnecessary_cast = "warn"
unnecessary_filter_map = "warn"
unwrap_or_default = "warn"
upper_case_acronyms = "warn"
while_let_loop = "allow"
wrong_self_convention = "warn"
3 changes: 3 additions & 0 deletions awk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ rand = {version = "0.8", default-features = false, features = ["small_rng"] }
[[bin]]
name = "awk"
path = "src/main.rs"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion awk/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn maybe_numeric_string<S: Into<AwkString>>(str: S) -> AwkString {
let numeric_string = is_valid_number(
str.as_str()
.trim()
.trim_start_matches(|c| c == '+' || c == '-'),
.trim_start_matches(['+', '-']),
);
str.is_numeric = numeric_string;
str
Expand Down
3 changes: 3 additions & 0 deletions calc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ path = "./expr.rs"
[[bin]]
name = "bc"
path = "./bc.rs"

[lints]
workspace = true
28 changes: 15 additions & 13 deletions calc/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,21 @@ fn cmpop(lhs: &Token, rhs: &Token, op: CmpOp) -> Result<Token, &'static str> {
let lhs_int = token_to_int(lhs);
let rhs_int = token_to_int(rhs);

// if both are integers, perform int comparison
if lhs_int.is_some() && rhs_int.is_some() {
Ok(cmpint(lhs_int.unwrap(), rhs_int.unwrap(), op))

// otherwise, convert int to string, and perform string compare
} else if let Some(val) = lhs_int {
let tmp = Token::Str(val.to_string());
cmpstr(&tmp, rhs, op)
} else if let Some(val) = rhs_int {
let tmp = Token::Str(val.to_string());
cmpstr(lhs, &tmp, op)
} else {
cmpstr(lhs, rhs, op)
match (lhs_int, rhs_int) {
(Some(lhs), Some(rhs)) => {
// if both are integers, perform int comparison
Ok(cmpint(lhs, rhs, op))
}
// otherwise, convert int to string, and perform string compare
(Some(lh), _) => {
let tmp = Token::Str(lh.to_string());
cmpstr(&tmp, rhs, op)
}
(_, Some(rh)) => {
let tmp = Token::Str(rh.to_string());
cmpstr(lhs, &tmp, op)
}
_ => cmpstr(lhs, rhs, op),
}
}

Expand Down
3 changes: 3 additions & 0 deletions datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ path = "./sleep.rs"
[[bin]]
name = "time"
path = "./time.rs"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion datetime/cal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// If only one argument is provided, assume it is the entire year
} else if args.month.is_some() && args.year.is_none() {
args.year = args.month.clone();
args.year = args.month;
args.month = None;
}

Expand Down
6 changes: 3 additions & 3 deletions datetime/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match &args.timestr {
None => show_time(args.utc, DEF_TIMESTR),
Some(timestr) => {
if timestr.starts_with("+") {
show_time(args.utc, &timestr[1..]);
if let Some(st) = timestr.strip_prefix("+") {
show_time(args.utc, st);
} else {
set_time(args.utc, &timestr)?;
set_time(args.utc, timestr)?;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ path = "./strip.rs"
[[bin]]
name = "strings"
path = "./strings.rs"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion dev/ar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ArchiveMember {
writer.write_all(&object::archive::TERMINATOR)?;
writer.write_all(&self.data)?;
if self.data.len() % 2 != 0 {
writer.write_all(&[b'\n'])?;
writer.write_all(b"\n")?;
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions display/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ path = "./echo.rs"
name = "printf"
path = "./printf.rs"

[lints]
workspace = true
4 changes: 2 additions & 2 deletions display/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn translate_str(skip_nl: bool, s: &str) -> String {
output.push('\x11');
}
'\\' => {
output.push_str("\\");
output.push('\\');
}
_ => {}
}
Expand All @@ -67,7 +67,7 @@ fn translate_str(skip_nl: bool, s: &str) -> String {
}

if nl && !skip_nl {
output.push_str("\n");
output.push('\n');
}

output
Expand Down
4 changes: 2 additions & 2 deletions display/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn tokenize_format_str(format: &str) -> Vec<Token> {
}

ParseState::Width => {
if c.is_digit(10) {
if c.is_ascii_digit() {
width.push(c);
done_with_char = true;
} else {
Expand All @@ -150,7 +150,7 @@ fn tokenize_format_str(format: &str) -> Vec<Token> {
}

ParseState::PrecisionValue => {
if c.is_digit(10) {
if c.is_ascii_digit() {
precision.push(c);
done_with_char = true;
} else {
Expand Down
3 changes: 3 additions & 0 deletions file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ path = "./file.rs"
[[bin]]
name = "find"
path = "./find.rs"

[lints]
workspace = true
18 changes: 8 additions & 10 deletions file/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,16 @@ fn apply_conversions(data: &mut Vec<u8>, config: &Config) {
}

fn copy_convert_file(config: &Config) -> Result<(), Box<dyn std::error::Error>> {
let mut ifile: Box<dyn Read>;
if config.ifile == "" {
ifile = Box::new(io::stdin().lock());
let mut ifile: Box<dyn Read> = if config.ifile.is_empty() {
Box::new(io::stdin().lock())
} else {
ifile = Box::new(fs::File::open(&config.ifile)?);
}
let mut ofile: Box<dyn Write>;
if config.ofile == "" {
ofile = Box::new(io::stdout().lock())
Box::new(fs::File::open(&config.ifile)?)
};
let mut ofile: Box<dyn Write> = if config.ofile.is_empty() {
Box::new(io::stdout().lock())
} else {
ofile = Box::new(fs::File::create(&config.ofile)?)
}
Box::new(fs::File::create(&config.ofile)?)
};

let mut ibuf = vec![0u8; config.ibs];
let obuf = vec![0u8; config.obs];
Expand Down
7 changes: 5 additions & 2 deletions file/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Value {
let re = Regex::new(r"\\([0-7]{1,3})").map_err(|_| RawMagicLineParseError::InvalidRegex)?;

let result = re
.replace_all(&input, |capture: &regex::Captures| {
.replace_all(input, |capture: &regex::Captures| {
let mat = capture.get(1).unwrap().as_str();

let v = u32::from_str_radix(mat, 8).unwrap();
Expand All @@ -169,7 +169,7 @@ impl Value {

fn parse_number(input: &mut String) -> Option<(ComparisonOperator, u64)> {
let regex = Regex::new(r"^[=<>&^x]").unwrap();
let comparision_op = match regex.find(&input) {
let comparision_op = match regex.find(input) {
Some(mat) => {
let comp = mat.as_str().chars().next().unwrap();
input.replace_range(..1, ""); // Remove the matched operator
Expand All @@ -192,6 +192,8 @@ impl Value {
}

/// Parses Hexadecimal, Octal and Unsigned Decimal
// TODO
#[allow(clippy::needless_match)]
fn parse_number(input: &mut String) -> Option<u64> {
if let Some(hex_num) = parse_hexadecimal(input) {
Some(hex_num)
Expand Down Expand Up @@ -510,6 +512,7 @@ fn parse_magic_file_and_test(
}
}
} else {
// TODO: Empty branch
}
}

Expand Down
16 changes: 8 additions & 8 deletions file/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fn parse_expression(tokens: &mut Vec<&str>) -> Vec<Expr> {
"-size" => {
tokens.pop();
if let Some(size) = tokens.pop() {
let (size, in_bytes) = if size.ends_with('c') {
(size[..size.len() - 1].parse::<u64>().unwrap_or(0), true)
let (size, in_bytes) = if let Some(st) = size.strip_suffix('c') {
(st.parse::<u64>().unwrap_or(0), true)
} else {
(size.parse::<u64>().unwrap_or(0), false)
};
Expand Down Expand Up @@ -250,15 +250,15 @@ fn evaluate_expression(
match expression {
Expr::Not(inner) => {
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
not_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
not_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
}
Expr::Or(inner) => {
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
or_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
or_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
}
Expr::And(inner) => {
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
and_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
and_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
}
_ => {}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ fn evaluate_expression(
FileType::Fifo => file_type.is_fifo(),
FileType::File => file_type.is_file(),
FileType::Socket => file_type.is_socket(),
FileType::Unknown => return Err(format!("Unknown argument to -type")),
FileType::Unknown => return Err("Unknown argument to -type".to_string()),
};
if !r {
c_files.remove(file.path());
Expand All @@ -316,15 +316,15 @@ fn evaluate_expression(
Expr::NoUser => {
if let Ok(metadata) = file.metadata() {
let uid = metadata.uid();
if !users::get_user_by_uid(uid).is_none() {
if users::get_user_by_uid(uid).is_some() {
c_files.remove(file.path());
}
}
}
Expr::NoGroup => {
if let Ok(metadata) = file.metadata() {
let gid = metadata.gid();
if !users::get_group_by_gid(gid).is_none() {
if users::get_group_by_gid(gid).is_some() {
c_files.remove(file.path());
}
}
Expand Down
Loading