STYLE Clippified.

After running 'cargo clippy,' a few changes were made, and then some
were reverted.  Honestly, 'x.len() > 0' is WAY more readable than
'!x.is_empty()'.  The exclamation mark gets swallowed up by the
surrounding text and is hard to see.
This commit is contained in:
Elf M. Sternberg 2020-11-12 15:02:45 -08:00
parent e3fe863235
commit 3068f18f0c
6 changed files with 27 additions and 36 deletions

View File

@ -0,0 +1 @@
cognitive-complexity-threshold = 9

View File

@ -1,4 +1,3 @@
use sqlx;
use thiserror::Error;
/// All the ways looking up objects can fail

View File

@ -50,7 +50,7 @@
//! it make sense to move this to a higher layer, and only provide the
//! hooks for it here?
//!
#![allow(clippy::len_zero)]
use crate::errors::NoteStoreError;
use crate::reference_parser::build_references;
use crate::store::private::*;
@ -109,7 +109,7 @@ impl NoteStore {
/// we also know no backreferences to it exist, so in that case you
/// get back two empty vecs.
pub async fn get_page_by_title(&self, title: &str) -> NoteResult<(Vec<Note>, Vec<Note>)> {
if title.len() == 0 {
if title.is_empty() {
return Err(NoteStoreError::NotFound);
}
@ -131,7 +131,7 @@ impl NoteStore {
let mut tx = self.0.begin().await?;
let slug = generate_slug(&mut tx, title).await?;
let page = create_page(&title, &slug);
let _ = insert_note(&mut tx, &page).await?;
insert_note(&mut tx, &page).await?;
tx.commit().await?;
Ok((vec![Note::from(page)], vec![]))
@ -157,12 +157,11 @@ impl NoteStore {
let old_note_location = old_note.location;
let old_note_kind = old_note.kind;
let _ = delete_note_to_note_relationship(&mut tx, &old_parent_id, &note_id).await?;
let _ = close_hole_for_deleted_note_relationship(&mut tx, &old_parent_id, old_note_location).await?;
delete_note_to_note_relationship(&mut tx, &old_parent_id, &note_id).await?;
close_hole_for_deleted_note_relationship(&mut tx, &old_parent_id, old_note_location).await?;
let new_location = determine_max_child_location_for_note(&mut tx, &new_parent_id, Some(new_location)).await?;
let _ = make_room_for_new_note_relationship(&mut tx, &new_parent_id, new_location).await?;
let _ =
insert_note_to_note_relationship(&mut tx, &new_parent_id, &note_id, new_location, &old_note_kind).await?;
make_room_for_new_note_relationship(&mut tx, &new_parent_id, new_location).await?;
insert_note_to_note_relationship(&mut tx, &new_parent_id, &note_id, new_location, &old_note_kind).await?;
tx.commit().await?;
Ok(())
}
@ -172,10 +171,10 @@ impl NoteStore {
pub async fn update_note_content(&self, note_id: &str, content: &str) -> NoteResult<()> {
let references = build_references(&content);
let mut tx = self.0.begin().await?;
let _ = update_note_content(&mut tx, &note_id, &content).await?;
let _ = delete_bulk_note_to_page_relationships(&mut tx, &note_id).await?;
update_note_content(&mut tx, &note_id, &content).await?;
delete_bulk_note_to_page_relationships(&mut tx, &note_id).await?;
let known_reference_ids = validate_or_generate_all_found_references(&mut tx, &references).await?;
let _ = insert_bulk_note_to_page_relationships(&mut tx, &note_id, &known_reference_ids).await?;
insert_bulk_note_to_page_relationships(&mut tx, &note_id, &known_reference_ids).await?;
tx.commit().await?;
Ok(())
}
@ -189,13 +188,13 @@ impl NoteStore {
let parent_id = note_parent_id.to_string();
if parent_id != note_id {
let _ = delete_note_to_note_relationship(&mut tx, &parent_id, &note_id);
delete_note_to_note_relationship(&mut tx, &parent_id, &note_id).await?;
}
// The big one: if zero parents report having an interest in this note, then it,
// *and any sub-relationships*, go away.
if count_existing_note_relationships(&mut tx, &note_id).await? == 0 {
let _ = delete_note_to_page_relationships(&mut tx, &note_id).await?;
let _ = delete_note(&mut tx, &note_id).await?;
delete_note_to_page_relationships(&mut tx, &note_id).await?;
delete_note(&mut tx, &note_id).await?;
}
tx.commit().await?;
Ok(())
@ -248,7 +247,7 @@ impl NoteStore {
make_room_for_new_note_relationship(&mut tx, &parent_id, location).await?;
insert_note_to_note_relationship(&mut tx, &parent_id, &note.id, location, &kind).await?;
let known_reference_ids = validate_or_generate_all_found_references(&mut tx, &references).await?;
let _ = insert_bulk_note_to_page_relationships(&mut tx, &note.id, &known_reference_ids).await?;
insert_bulk_note_to_page_relationships(&mut tx, &note.id, &known_reference_ids).await?;
tx.commit().await?;
Ok(note.id.to_string())
}

View File

@ -51,8 +51,8 @@
//! hooks for it here?
//!
mod api;
mod private;
mod store;
pub use crate::store::store::NoteResult;
pub use crate::store::store::NoteStore;
pub use crate::store::api::NoteResult;
pub use crate::store::api::NoteStore;

View File

@ -67,7 +67,7 @@ where
E: Executor<'a, Database = Sqlite>,
{
let r: Vec<RowNote> = sqlx::query_as(query).bind(field).fetch_all(executor).await?;
Ok(r.into_iter().map(|z| Note::from(z)).collect())
Ok(r.into_iter().map(Note::from).collect())
}
// Select the requested page via its id. This is fairly rare;
@ -124,7 +124,7 @@ where
"VALUES (?, ?, ?, ?, ?, ?);"
);
let _ = sqlx::query(insert_one_note_sql)
sqlx::query(insert_one_note_sql)
.bind(&note.id)
.bind(&note.content)
.bind(note.kind.to_string())
@ -243,7 +243,7 @@ where
let update_note_content_sql = "UPDATE notes SET content = ? WHERE note_id = ?";
let count = sqlx::query(update_note_content_sql)
.bind(content)
.bind(&**note_id)
.bind(note_id)
.execute(executor)
.await?
.rows_affected();
@ -303,7 +303,7 @@ where
"values (?, ?, ?, ?)"
);
let _ = sqlx::query(insert_note_to_note_relationship_sql)
sqlx::query(insert_note_to_note_relationship_sql)
.bind(parent_id)
.bind(note_id)
.bind(&location)
@ -327,7 +327,7 @@ where
"WHERE location >= ? and parent_id = ?;"
);
let _ = sqlx::query(make_room_for_new_note_sql)
sqlx::query(make_room_for_new_note_sql)
.bind(&location)
.bind(parent_id)
.execute(executor)
@ -402,7 +402,7 @@ where
E: Executor<'a, Database = Sqlite>,
{
let delete_note_to_page_relationship_sql = "DELETE FROM note_page_relationships WHERE and note_id = ?;";
let _ = sqlx::query(delete_note_to_page_relationship_sql)
sqlx::query(delete_note_to_page_relationship_sql)
.bind(note_id)
.execute(executor)
.await?;
@ -498,7 +498,7 @@ where
);
}
let _ = sqlx::query(&DELETE_NOTE_TO_PAGE_RELATIONSHIPS_SQL)
sqlx::query(&DELETE_NOTE_TO_PAGE_RELATIONSHIPS_SQL)
.bind(note_id)
.execute(executor)
.await?;
@ -540,7 +540,7 @@ where
"WHERE location > ? and parent_id = ?;"
);
let _ = sqlx::query(close_hole_for_deleted_note_sql)
sqlx::query(close_hole_for_deleted_note_sql)
.bind(&location)
.bind(parent_id)
.execute(executor)
@ -565,7 +565,7 @@ pub(crate) async fn validate_or_generate_all_found_references(
let slug = generate_slug(&mut tx, one_reference).await?;
new_page.push(create_page(&one_reference, &slug));
}
let _ = insert_bulk_notes(&mut tx, &new_page).await?;
insert_bulk_notes(&mut tx, &new_page).await?;
let mut all_reference_ids: Vec<String> = found_references.iter().map(|r| r.id.clone()).collect();
all_reference_ids.append(&mut new_page.iter().map(|r| r.id.clone()).collect());

View File

@ -1,7 +1,5 @@
use chrono::{DateTime, Utc};
use derive_builder::Builder;
use friendly_id;
use shrinkwraprs::Shrinkwrap;
use sqlx::{self, FromRow};
// Page is German for "Box," and is used both because this is
@ -50,12 +48,6 @@ macro_rules! build_conversion_enums {
};
}
#[derive(Shrinkwrap, Clone)]
pub(crate) struct NoteId(pub String);
#[derive(Shrinkwrap, Clone)]
pub(crate) struct ParentId(pub String);
// The different kinds of objects we support.
build_conversion_enums!(