Skip to content

Commit

Permalink
Enable clippy::nursery lints for all crates
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKasmy committed Apr 28, 2023
1 parent 9f368db commit 7d6877b
Show file tree
Hide file tree
Showing 35 changed files with 86 additions and 18 deletions.
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Action {
}

impl Field {
#[must_use]
pub fn parse(self) -> CField {
match self {
Field::Title => CField::Title,
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/decode_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct DecodeHtml {
}

impl DecodeHtml {
#[must_use]
pub fn parse(self) -> Vec<CAction> {
self.r#in
.into_iter()
Expand Down
3 changes: 3 additions & 0 deletions fetcher-config/src/jobs/action/html/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct HtmlQueryRegex {
}

impl ElementKind {
#[must_use]
pub fn parse(self) -> c_query::ElementKind {
use ElementKind::{Attr, Class, Tag};

Expand All @@ -75,6 +76,7 @@ impl ElementKind {
}

impl DataLocation {
#[must_use]
pub fn parse(self) -> c_query::DataLocation {
use DataLocation::{Attr, Text};

Expand All @@ -86,6 +88,7 @@ impl DataLocation {
}

impl ElementQuery {
#[must_use]
pub fn parse(self) -> c_query::ElementQuery {
c_query::ElementQuery {
kind: self.kind.parse(),
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Json {
}

impl Key {
#[must_use]
pub fn parse(self) -> c_json::Key {
match self {
Key::String(s) => c_json::Key::String(s),
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use serde_with::{serde_as, OneOrMany};
pub struct Set(pub HashMap<Field, Option<Values>>);

impl Set {
#[must_use]
pub fn parse(self) -> Vec<CAction> {
self.0
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/shorten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::collections::HashMap;
pub struct Shorten(pub HashMap<Field, usize>);

impl Shorten {
#[must_use]
pub fn parse(self) -> Vec<CAction> {
self.0
.into_iter()
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/jobs/action/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum TakeWhich {
}

impl Take {
#[must_use]
pub fn parse(self) -> CTake {
CTake {
from: self.0.which.parse(),
Expand All @@ -35,6 +36,7 @@ impl Take {
}

impl TakeWhich {
#[must_use]
pub fn parse(self) -> CTakeFrom {
match self {
TakeWhich::FromNewest => CTakeFrom::Beginning,
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Trim {
}

impl Trim {
#[must_use]
pub fn parse(self) -> impl CTransform {
CTransformFieldWrapper {
field: self.field.parse(),
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/action/use_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct As {
}

impl Use {
#[must_use]
pub fn parse(self) -> Vec<CAction> {
self.0
.into_iter()
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/jobs/external_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ impl<T, E> From<Result<T, E>> for ExternalDataResult<T, E> {
}

impl ExternalDataError {
#[must_use]
pub fn new_io_with_path(io_err: io::Error, path: &Path) -> Self {
Self::Io {
source: io_err,
payload: Some(Box::new(format!("path: {}", path.to_string_lossy()))),
}
}

#[must_use]
pub fn new_rf_incompat_with_path(
expected: ReadFilterKind,
found: ReadFilterKind,
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/named/job_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
pub struct JobName(pub Arc<str>);

impl JobName {
#[must_use]
pub fn as_str(&self) -> &str {
self
}
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/named/task_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct TaskName(pub String);
pub type TaskNameMap = HashMap<usize, TaskName>;

impl TaskName {
#[must_use]
pub fn as_str(&self) -> &str {
self
}
Expand Down
9 changes: 8 additions & 1 deletion fetcher-config/src/jobs/read_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum ReadFilter {
NotPresentInReadList(NotPresent),
}

#[derive(Deserialize, Serialize, Clone, Copy, PartialEq, Debug)]
#[derive(Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Debug)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub enum Kind {
NewerThanRead,
Expand All @@ -49,10 +49,12 @@ pub struct NotPresent {
}

impl EntryId {
#[must_use]
pub fn parse(self) -> CEntryId {
CEntryId(self.0)
}

#[must_use]
pub fn unparse(other: CEntryId) -> Self {
Self(other.0)
}
Expand Down Expand Up @@ -92,6 +94,7 @@ impl ReadFilter {
None
}

#[must_use]
pub fn to_kind(&self) -> Kind {
match self {
ReadFilter::NewerThanRead(_) => Kind::NewerThanRead,
Expand Down Expand Up @@ -119,12 +122,14 @@ impl Kind {
}

impl Newer {
#[must_use]
pub fn parse(self) -> CNewer {
CNewer {
last_read_id: Some(self.last_read_id.parse()),
}
}

#[must_use]
pub fn unparse(read_filter: &CNewer) -> Option<Self> {
read_filter.last_read_id.as_ref().map(|last_read_id| Self {
last_read_id: EntryId::unparse(last_read_id.clone()),
Expand All @@ -133,13 +138,15 @@ impl Newer {
}

impl NotPresent {
#[must_use]
pub fn parse(self) -> CNotPresent {
self.read_list
.into_iter()
.map(|(id, time)| (id.parse(), time))
.collect()
}

#[must_use]
pub fn unparse(read_filter: &CNotPresent) -> Option<Self> {
if read_filter.is_empty() {
None
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl Source {
})
}

#[must_use]
pub fn supports_replies(&self) -> bool {
// Source::Email will support replies in the future
#[allow(clippy::match_like_matches_macro)]
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/source/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Exec {
}

impl Exec {
#[must_use]
pub fn parse(self) -> Vec<CExec> {
self.cmd.into_iter().map(|cmd| CExec { cmd }).collect()
}
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/source/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::path::PathBuf;
pub struct File(#[serde_as(deserialize_as = "OneOrMany<_>")] pub Vec<PathBuf>);

impl File {
#[must_use]
pub fn parse(self) -> Vec<CFile> {
self.0.into_iter().map(|path| CFile { path }).collect()
}
Expand Down
3 changes: 3 additions & 0 deletions fetcher-config/src/jobs/source/reddit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum TimePeriod {
}

impl Reddit {
#[must_use]
pub fn parse(self) -> Vec<CReddit> {
self.0
.into_iter()
Expand All @@ -50,12 +51,14 @@ impl Reddit {
}

impl Inner {
#[must_use]
pub fn parse(self, subreddit: &str) -> CReddit {
CReddit::new(subreddit, self.sort.parse(), self.score_threshold)
}
}

impl Sort {
#[must_use]
pub fn parse(self) -> CSort {
match self {
Sort::Latest | Sort::New => CSort::Latest,
Expand Down
1 change: 1 addition & 0 deletions fetcher-config/src/jobs/source/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde_with::{serde_as, OneOrMany};
pub struct StringSource(#[serde_as(deserialize_as = "OneOrMany<_>")] pub Vec<String>);

impl StringSource {
#[must_use]
pub fn parse(self) -> Vec<String> {
self.0.into_iter().collect()
}
Expand Down
6 changes: 6 additions & 0 deletions fetcher-config/src/jobs/task/entry_to_msg_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,39 @@ pub struct MessageId(pub i64);
pub struct EntryToMsgMap(pub HashMap<EntryId, MessageId>);

impl EntryId {
#[must_use]
pub fn parse(self) -> CEntryId {
self.0.into()
}

#[must_use]
pub fn unparse(eid: CEntryId) -> Self {
Self(eid.0)
}
}

impl MessageId {
#[must_use]
pub fn parse(self) -> CMessageId {
self.0.into()
}

#[must_use]
pub fn unparse(msgid: CMessageId) -> Self {
Self(msgid.0)
}
}

impl EntryToMsgMap {
#[must_use]
pub fn parse(self) -> HashMap<CEntryId, CMessageId> {
self.0
.into_iter()
.map(|(eid, msgid)| (eid.parse(), msgid.parse()))
.collect()
}

#[must_use]
pub fn unparse(map: HashMap<CEntryId, CMessageId>) -> Self {
Self(
map.into_iter()
Expand Down
13 changes: 9 additions & 4 deletions fetcher-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
// TODO: mb rename .parse() into .into() or something of that sort? .into() is already used by From/Into traits though. Naming is hard, man... UPD: into_conf() and from_conf() are way better!

#![doc = include_str!("../README.md")]
#![warn(clippy::unwrap_used)]
// Additional Lints
#![warn(clippy::pedantic)]
// some types are more descriptive with modules name in the name, especially if this type is often used out of the context of this module
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::must_use_candidate)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::nursery)]
#![allow(clippy::option_if_let_else)] // "harder to read, false branch before true branch"
#![allow(clippy::use_self)] // may be hard to understand what Self even is deep into a function's body
#![allow(clippy::equatable_if_let)] // matches!() adds too much noise for little benefit
#![allow(clippy::missing_const_for_fn)] // most of methods take self and self destructor can't be const, so this is pretty much iseless
#![allow(clippy::missing_errors_doc)] // TODO: add more docs

pub mod error;
pub mod jobs;
Expand Down
7 changes: 4 additions & 3 deletions fetcher-config/src/serde_extentions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

pub(crate) mod tuple {
pub mod tuple {
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
use std::{fmt, marker::PhantomData};

pub(crate) fn serialize<'a, S, V, First, Second>(
#[allow(clippy::extra_unused_type_parameters)] // they are used in the where clause and in the function body
pub fn serialize<'a, S, V, First, Second>(
tuple: &'a V,
serializer: S,
) -> Result<S::Ok, S::Error>
Expand All @@ -24,7 +25,7 @@ pub(crate) mod tuple {
map.end()
}

pub(crate) fn deserialize<'de, D, V, First, Second>(deserializer: D) -> Result<V, D::Error>
pub fn deserialize<'de, D, V, First, Second>(deserializer: D) -> Result<V, D::Error>
where
D: Deserializer<'de>,
V: From<(First, Second)>,
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/settings/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ pub struct Discord {
}

impl Discord {
#[must_use]
pub fn parse(self) -> String {
let Self { token } = self;

token
}

#[must_use]
pub fn unparse(token: String) -> Self {
Self { token }
}
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/settings/email_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ pub struct EmailPassword {
}

impl EmailPassword {
#[must_use]
pub fn parse(self) -> String {
let Self { password } = self;

password
}

#[must_use]
pub fn unparse(password: String) -> Self {
Self { password }
}
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/settings/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ pub struct Google {
}

impl Google {
#[must_use]
pub fn parse(self) -> CoreGoogleAuth {
CoreGoogleAuth::new(self.client_id, self.client_secret, self.refresh_token)
}

#[must_use]
pub fn unparse(auth: CoreGoogleAuth) -> Self {
let CoreGoogleAuth {
client_id,
Expand Down
2 changes: 2 additions & 0 deletions fetcher-config/src/settings/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ pub struct Telegram {
}

impl Telegram {
#[must_use]
pub fn parse(self) -> String {
let Self { token } = self;

token
}

#[must_use]
pub fn unparse(token: String) -> Self {
Self { token }
}
Expand Down

0 comments on commit 7d6877b

Please sign in to comment.