Skip to content

Commit

Permalink
Fixed lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Feb 7, 2023
1 parent 57da7a2 commit 23c3d34
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 38 deletions.
9 changes: 3 additions & 6 deletions src/cli/command/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ fn to_stdout(app: &App) -> Result<()> {
match app.db.collect_decrypted() {
Ok(rs) => {
for r in rs {
println!("{:?}", r)
println!("{r:?}")
}
}
Err(e) => {
log::error!("{:?}", e)
log::error!("{e:?}")
}
}
Ok(())
Expand Down Expand Up @@ -76,8 +76,5 @@ fn to_firefox_csv(app: &App, csv_path: String) -> Result<(), anyhow::Error> {

fn print_report(count: usize, total: usize) {
println!();
println!(
"Exported {} records (total records in DB: {})",
count, total
)
println!("Exported {count} records (total records in DB: {total})")
}
9 changes: 3 additions & 6 deletions src/cli/command/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn new(matches: &ArgMatches, app: &App) -> Result<()> {
}

fn from_chrome_csv(db: &DB, csv_path: String) -> Result<(), anyhow::Error> {
println!("Importing data from {}:", csv_path);
println!("Importing data from {csv_path}:");
let mut rdr = csv::reader::from_path(csv_path)?;
let mut count = 0;
for result in rdr.deserialize() {
Expand All @@ -33,7 +33,7 @@ fn from_chrome_csv(db: &DB, csv_path: String) -> Result<(), anyhow::Error> {
}

fn from_firefox_csv(db: &DB, csv_path: String) -> Result<(), anyhow::Error> {
println!("Importing data from {}:", csv_path);
println!("Importing data from {csv_path}:");
let mut rdr = csv::reader::from_path(csv_path)?;
let mut count: usize = 0;
for result in rdr.deserialize() {
Expand All @@ -47,8 +47,5 @@ fn from_firefox_csv(db: &DB, csv_path: String) -> Result<(), anyhow::Error> {
}

fn print_report(count: usize, total: usize) {
println!(
"\nImported {} records (total records in DB: {})",
count, total
)
println!("\nImported {count} records (total records in DB: {total})")
}
22 changes: 6 additions & 16 deletions src/cli/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn print_results(sorted: &Vec<ListResult>, decrypted: Option<&bool>) {
}

fn print_report(count: usize, total: usize) {
println!("\n{} records (of {} total)\n", count, total)
println!("\n{count} records (of {total} total)\n")
}

fn print_password_group(
Expand Down Expand Up @@ -212,10 +212,7 @@ fn print_user_group(
}

fn print_group_report(count: i32, records: usize, total: usize) {
println!(
"\n{} groups (with {} records out of {} total)\n",
count, records, total
)
println!("\n{count} groups (with {records} records out of {total} total)\n")
}

const URL_HEADER: &str = "URL";
Expand All @@ -226,8 +223,7 @@ const COUNT_HEADER: &str = "Access Count";

fn decrypted_header() {
println!(
"\n{: <40} | {: <30} | {: <20} | {: <15} | {}",
URL_HEADER, USER_HEADER, PWD_HEADER, SCORE_HEADER, COUNT_HEADER
"\n{URL_HEADER: <40} | {USER_HEADER: <30} | {PWD_HEADER: <20} | {SCORE_HEADER: <15} | {COUNT_HEADER}"
);
println!(
"{: <40}-+-{: <30}-+-{: <20}-+-{: <15}-+-{}",
Expand All @@ -240,10 +236,7 @@ fn decrypted_header() {
}

fn decrypted_no_user_header() {
println!(
"\n{: <40} | {: <20} | {}",
URL_HEADER, PWD_HEADER, SCORE_HEADER
);
println!("\n{URL_HEADER: <40} | {PWD_HEADER: <20} | {SCORE_HEADER}");
println!(
"{: <40}-+-{: <20}-+-{}",
"-".repeat(40),
Expand All @@ -253,10 +246,7 @@ fn decrypted_no_user_header() {
}

fn encrypted_header() {
println!(
"\n{: <40} | {: <30} | {}",
URL_HEADER, USER_HEADER, COUNT_HEADER
);
println!("\n{URL_HEADER: <40} | {USER_HEADER: <30} | {COUNT_HEADER}");
println!(
"{:40}-+-{:30}-+-{}",
"-".repeat(40),
Expand All @@ -266,7 +256,7 @@ fn encrypted_header() {
}

fn encrypted_no_user_header() {
println!("\n{: <40} | {}", URL_HEADER, COUNT_HEADER);
println!("\n{URL_HEADER: <40} | {COUNT_HEADER}");
println!("{:40}-+-{}", "-".repeat(40), "-".repeat(12))
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/command/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn record_by_key(app_db: &db::DB, key: String) -> Result<DecryptedRecord> {
match app_db.get(key.clone()) {
Some(dr) => Ok(dr),
None => {
let msg = format!("no secret record for given key '{}'", key);
let msg = format!("no secret record for given key '{key}'");
log::error!("{}", msg);
Err(anyhow!(msg))
}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn display_scored(mut pwd: String, encode: Option<&bool>) -> Result<()> {
}
let analyzed = analyzer::analyze(pwd.clone());
let score = scorer::score(&analyzed);
let msg = format!("\nNew password: {}\nPassword score: {:.2}\n", pwd, score);
let msg = format!("\nNew password: {pwd}\nPassword score: {score:.2}\n");
util::display(&msg)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DESC: &str = env!("CARGO_PKG_DESCRIPTION");

fn cli() -> Command {
Command::new(NAME)
.about(format!("{}: {}", NAME, DESC))
.about(format!("{NAME}: {DESC}"))
.arg_required_else_help(true)
.allow_external_subcommands(true)
.arg(
Expand Down Expand Up @@ -261,7 +261,7 @@ fn main() -> Result<()> {
match twyg::setup_logger(&cfg.logging) {
Ok(_) => {}
Err(error) => {
panic!("Could not setup logger: {:?}", error)
panic!("Could not setup logger: {error:?}")
}
}
log::debug!("Config setup complete.");
Expand Down
2 changes: 1 addition & 1 deletion src/store/db/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl EncryptedDB {
Ok(())
}
Err(e) => {
let msg = format!("Could not decrypt data: {:?}", e);
let msg = format!("Could not decrypt data: {e:?}");
Err(anyhow!("{}", msg))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl DB {
match bincode::encode_to_vec(data, util::bincode_cfg()) {
Ok(encoded) => Ok(encoded),
Err(e) => {
let msg = format!("couldn't encode DB hashmap ({:?})", e);
let msg = format!("couldn't encode DB hashmap ({e:?})");
Err(anyhow!("{}", msg))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/store/db/versioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn from_encoded(bytes: Vec<u8>) -> Result<VersionedDB> {
Ok(versioned)
}
Err(e) => {
let msg = format!("couldn't deserialise versioned database file: {:?}", e);
let msg = format!("couldn't deserialise versioned database file: {e:?}");
Err(anyhow!(msg))
}
}
Expand All @@ -45,7 +45,7 @@ impl VersionedDB {
match bincode::encode_to_vec(self, util::bincode_cfg()) {
Ok(bytes) => Ok(bytes),
Err(e) => {
let msg = format!("couldn't serialise versioned database ({})", e);
let msg = format!("couldn't serialise versioned database ({e})");
Err(anyhow!("{}", msg))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl EncryptedRecord {
// Utility functions

pub fn key(user: &str, url: &str) -> String {
format!("{}:{}", user, url)
format!("{user}:{url}")
}

// Tests
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use versions::Versioning;
const SPECIALS: &[u8] = b"!@#%&*?=+:";

pub fn display(text: &str) -> Result<()> {
println!("{}", text);
println!("{text}");
Ok(())
}

Expand Down

0 comments on commit 23c3d34

Please sign in to comment.