Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and Improvements #43

Merged
merged 13 commits into from
Jan 12, 2025
Next Next commit
fix: Cleanup eprintln calls by changing to trace! calls. Fix clippy w…
…arnings
plucia-mitre committed Dec 23, 2024
commit aa7a450a23f997ededbd849a7b109463ea113909
2 changes: 1 addition & 1 deletion src/comments/mod.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ pub trait Comment {
mod tests {
use super::*;

const EX_TEXT: &'static str = "There once was a man
const EX_TEXT: &str = "There once was a man
with a very nice cat
the cat wore a top hat
it looked super dapper
5 changes: 1 addition & 4 deletions src/config/comment.rs
Original file line number Diff line number Diff line change
@@ -23,10 +23,7 @@ fn def_trailing_lines() -> usize {

pub fn get_filetype(filename: &str) -> &str {
let iter = filename.split('.');
match iter.last() {
Some(s) => s,
None => "",
}
iter.last().unwrap_or_default()
}

#[derive(Clone, Deserialize, Debug)]
8 changes: 6 additions & 2 deletions src/licensure.rs
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ impl Licensure {
continue;
}

trace!("Working on file: {}", &file);

let mut content = String::new();
{
let mut f = File::open(file)?;
@@ -106,14 +108,16 @@ impl Licensure {
header: &str,
) -> Option<String> {
let outdated_re = templ.outdated_license_pattern(commenter);
println!("{}", content);
println!("{:?}", outdated_re);
// trace!("Content: {}", content);
// trace!("Outdated Regex: {:?}", outdated_re);
// trace!("Header: {:?}", header);
if outdated_re.is_match(content) {
return Some(outdated_re.replace(content, header).to_string());
}

// Account for possible whitespace changes
let trimmed_outdated_re = templ.outdated_license_trimmed_pattern(commenter);
// trace!("trimmed_outdated_re Regex: {:?}", trimmed_outdated_re);
if trimmed_outdated_re.is_match(content) {
Some(trimmed_outdated_re.replace(content, header).to_string())
} else {
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -132,7 +132,9 @@ More information is available at: {}",
match matches.occurrences_of("verbose") {
0 => (),
x => simplelog::SimpleLogger::init(
if x > 2 {
if x > 3 {
simplelog::LevelFilter::Trace
} else if x > 2 {
simplelog::LevelFilter::Debug
} else {
simplelog::LevelFilter::Info
@@ -233,6 +235,6 @@ mod test {

#[test]
fn test_get_project_files() {
assert!(get_project_files().len() != 0)
assert!(!get_project_files().is_empty())
}
}
8 changes: 4 additions & 4 deletions src/template.rs
Original file line number Diff line number Diff line change
@@ -329,7 +329,7 @@ mod tests {
);
let commenter: Box<dyn Comment> = Box::new(LineComment::new("#", Option::Some(1000)));
let re = template.outdated_license_pattern(commenter.as_ref());
assert_eq!(true, re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software.\n"))
assert!(re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software.\n"))
}

#[test]
@@ -351,11 +351,11 @@ mod tests {
let commenter: Box<dyn Comment> =
Box::new(LineComment::new("#", Option::Some(1000)).set_trailing_lines(2));
let re = template.outdated_license_pattern(commenter.as_ref());
assert_eq!(true, re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software.\n\n\n"));
assert_eq!(false, re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software."));
assert!(re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software.\n\n\n"));
assert!(!re.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software."));

let trimmed = template.outdated_license_trimmed_pattern(commenter.as_ref());
assert_eq!(true, trimmed.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software."))
assert!(trimmed.is_match("# Copyright (C) 2020 Mathew Robinson <[email protected]> This program is free software."))
}

#[test]
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -39,6 +39,6 @@ So is this.";

let expected = "some wrapped text to unwrap.\n\nThe line above \
is an intentional line break.\n\nSo is this.";
assert_eq!(expected, remove_column_wrapping(&content))
assert_eq!(expected, remove_column_wrapping(content))
}
}