Skip to content

Commit

Permalink
Prefer expect instead of allow & fix some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjentix committed Nov 4, 2024
1 parent 0bd2d5b commit ed1f34d
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 103 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ mockall = { version = "0.13.0", features = ["nightly"] }
mockall_double = "0.3.1"
base64 = "0.22.1"

[workspace.lints.rust]
warnings = "deny"

[workspace.lints]
clippy.all = { level = "deny", priority = -1 }
clippy.pedantic = { level = "deny", priority = -1 }
Expand All @@ -45,7 +48,6 @@ clippy.perf = { level = "deny", priority = -1 }
clippy.suspicious = { level = "deny", priority = -1 }
clippy.style = { level = "deny", priority = -1 }

clippy.allow_attributes = "allow"
clippy.cfg_not_test = "allow"
clippy.blanket-clippy-restriction-lints = "allow"
clippy.implicit-return = "allow"
Expand Down
2 changes: 1 addition & 1 deletion crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ workspace = true
aes-gcm = { version = "0.10.3", optional = true }
pbkdf2 = { version = "0.12.2", features = ["std", "parallel", "hmac"], optional = true }
sha2 = { version = "0.10.8", optional = true }
serde.workspace = true
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
6 changes: 2 additions & 4 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Crate for passwords encryption and decryption used in Telepass.
#![allow(clippy::assertions_on_constants, reason = "health checks")]

use std::string::FromUtf8Error;

#[cfg(feature = "impls")]
Expand Down Expand Up @@ -126,7 +124,7 @@ fn derive_key(password: &str) -> Key<Aes256Gcm> {
#[cfg(test)]
#[cfg(feature = "impls")]
mod tests {
#![allow(clippy::expect_used, reason = "it's ok in tests")]
#![expect(clippy::expect_used, reason = "it's ok in tests")]

use super::*;

Expand Down Expand Up @@ -183,7 +181,7 @@ mod tests {
}

#[test]
#[allow(clippy::indexing_slicing, reason = "it's ok in tests")]
#[expect(clippy::indexing_slicing, reason = "it's ok in tests")]
fn decrypt_with_wrong_payload_fails() {
let payload = "payload";
let password = "password";
Expand Down
10 changes: 6 additions & 4 deletions password_storage/src/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//! Module with generated `gRPC` code.
#![allow(
#![expect(
clippy::empty_structs_with_brackets,
clippy::similar_names,
clippy::default_trait_access,
clippy::too_many_lines,
clippy::clone_on_ref_ptr,
clippy::shadow_unrelated,
clippy::unwrap_used,
clippy::missing_const_for_fn,
clippy::missing_docs_in_private_items,
clippy::allow_attributes_without_reason,
clippy::as_conversions,
clippy::derive_partial_eq_without_eq,
clippy::allow_attributes,
reason = "generated code"
)]
#![allow(
clippy::missing_docs_in_private_items,
reason = "allow because it's false positive unfulfilled-lint-expectations if in expect"
)]

tonic::include_proto!("password_storage");

Expand Down
2 changes: 1 addition & 1 deletion password_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
pub mod grpc;
pub mod models;
/// Module with database schema generated by `diesel`
#[allow(clippy::single_char_lifetime_names, reason = "generated code")]
#[expect(clippy::single_char_lifetime_names, reason = "generated code")]
pub mod schema;
pub mod service;
6 changes: 3 additions & 3 deletions password_storage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<()> {
let password_storage =
PasswordStorageServer::new(service::PasswordStorage::new(&database_url, cache_size)?);

#[allow(unused_mut, reason = "used in conditional compilation")]
#[expect(unused_mut, reason = "used in conditional compilation")]
let mut server = Server::builder();

let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn main() -> Result<()> {
///
/// Returns a [`Receiver`](tokio::sync::oneshot::Receiver) that will
/// receive a shutdown message when program receive some kind of termination signal from OS.
#[allow(
#[expect(
clippy::panic,
clippy::expect_used,
clippy::panic_in_result_fn,
Expand All @@ -103,7 +103,7 @@ fn init_signal_handler() -> Result<tokio::sync::oneshot::Receiver<()>> {
/// Receive shutdown signal from `rx`.
///
/// Implemented as a function, because async closures are not yet supported.
#[allow(clippy::expect_used, reason = "should never happen")]
#[expect(clippy::expect_used, reason = "should never happen")]
async fn recv_shutdown(rx: tokio::sync::oneshot::Receiver<()>) {
rx.await.expect("Shutdown signal sender dropped");
}
Expand Down
4 changes: 2 additions & 2 deletions password_storage/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WithContextExt for diesel::result::Error {
}
}

#[allow(
#[expect(
clippy::wildcard_enum_match_arm,
reason = "only exact variants are needed"
)]
Expand Down Expand Up @@ -187,7 +187,7 @@ impl grpc::password_storage_server::PasswordStorage for PasswordStorage {
}

#[instrument(skip(self))]
#[allow(clippy::panic, reason = "should never happen")]
#[expect(clippy::panic, reason = "should never happen")]
async fn delete(
&self,
request: Request<grpc::Resource>,
Expand Down
4 changes: 2 additions & 2 deletions password_storage/src/service/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Cache {
/// Creates new [`Cache`] instance with max size `size` and pre-loaded `records`.
///
/// All records after `size - 1` index will be ignored.
#[allow(clippy::expect_used, reason = "u32 to usize conversion is safe")]
#[expect(clippy::expect_used, reason = "u32 to usize conversion is safe")]
pub fn load(size: u32, records: impl IntoIterator<Item = Record>) -> Self {
let size = size
.try_into()
Expand Down Expand Up @@ -164,7 +164,7 @@ impl Cache {
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::panic, reason = "it's ok in tests")]
#[expect(clippy::unwrap_used, clippy::panic, reason = "it's ok in tests")]
mod tests {
use std::convert::Infallible;

Expand Down
2 changes: 1 addition & 1 deletion password_storage/src/service/cache/rated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Module with [`Set`] that stores only specified number of records, replacing the least popular
//! one on insertion.
#![allow(
#![expect(
clippy::expect_used,
clippy::unwrap_in_result,
reason = "used to indicate programmer errors"
Expand Down
2 changes: 1 addition & 1 deletion telegram_gate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> Result<()> {
.build_client(true)
.client_mod_attribute(
"password_storage",
"#[allow(clippy::missing_docs_in_private_items)]",
"#[expect(clippy::missing_docs_in_private_items)]",
)
.compile_protos(&["../proto/password_storage.proto"], &["../proto"])
.map_err(Into::into)
Expand Down
19 changes: 11 additions & 8 deletions telegram_gate/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//!
//! Button means inline button attached to a message.
#![allow(clippy::non_ascii_literal, reason = "emojis are allowed")]

use derive_more::From;
use parse_display::{Display, FromStr};

Expand All @@ -24,7 +22,7 @@ impl ButtonBox {
/// # Errors
///
/// Fails if `data` does not correspond to any valid button [`kind`].
#[allow(clippy::map_err_ignore, reason = "not interested in exact parse error")]
#[expect(clippy::map_err_ignore, reason = "not interested in exact parse error")]
pub fn new(
message: TelegramMessage,
data: &str,
Expand All @@ -39,9 +37,13 @@ impl ButtonBox {
}

#[cfg(test)]
#[allow(
clippy::multiple_inherent_impl,
reason = "better looking conditional compilation"
#[cfg_attr(test, allow(clippy::allow_attributes, reason = "false positive"))]
#[cfg_attr(
test,
allow(
clippy::multiple_inherent_impl,
reason = "better looking conditional compilation"
)
)]
impl ButtonBox {
#[must_use]
Expand Down Expand Up @@ -128,11 +130,12 @@ pub mod kind {

#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, reason = "it's ok in tests")]
#![expect(clippy::unwrap_used, reason = "it's ok in tests")]
#![expect(clippy::non_ascii_literal, reason = "emojis are allowed")]

use super::*;

#[allow(
#[expect(
dead_code,
unreachable_code,
unused_variables,
Expand Down
4 changes: 2 additions & 2 deletions telegram_gate/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ blank_from_str!(Help, Start, Cancel);

#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, reason = "it's ok in tests")]
#![expect(clippy::unwrap_used, reason = "it's ok in tests")]

use super::*;

#[allow(
#[expect(
dead_code,
unreachable_code,
unused_variables,
Expand Down
5 changes: 5 additions & 0 deletions telegram_gate/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Module with [`Context`] structure to pass values and dependencies between different states.
#![allow(
clippy::allow_attributes,
reason = "mockall is really bad at placing expects in the right place"
)]

#[cfg(test)]
use mockall::automock;
use url::Url;
Expand Down
14 changes: 6 additions & 8 deletions telegram_gate/src/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
//! Module with `gRPC` client for `password_storage` service
#![allow(
#![expect(
clippy::empty_structs_with_brackets,
clippy::similar_names,
clippy::default_trait_access,
clippy::too_many_lines,
clippy::clone_on_ref_ptr,
clippy::shadow_unrelated,
clippy::unwrap_used,
clippy::missing_errors_doc,
clippy::future_not_send,
clippy::allow_attributes_without_reason,
clippy::mixed_attributes_style,
clippy::derive_partial_eq_without_eq,
reason = "generated code"
)]
#![allow(
clippy::missing_docs_in_private_items,
unfulfilled_lint_expectations,
reason = "allow because it's false positive unfulfilled-lint-expectations if in expect"
)]

tonic::include_proto!("password_storage");

Expand Down
3 changes: 1 addition & 2 deletions telegram_gate/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Telegram Gate controls the bot using Telegram API.
#![cfg(feature = "executable")]
#![allow(clippy::panic, reason = "indicates programmer error")]

use std::{str::FromStr as _, sync::Arc};

Expand Down Expand Up @@ -130,7 +129,7 @@ async fn message_handler(
}

#[instrument(skip(bot, state_storage, storage_client))]
#[allow(clippy::significant_drop_tightening, reason = "false positive")]
#[expect(clippy::significant_drop_tightening, reason = "false positive")]
async fn button_callback_handler(
bot: Bot,
query: CallbackQuery,
Expand Down
18 changes: 10 additions & 8 deletions telegram_gate/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! This module contains strongly-typed messages user can send.
#![allow(clippy::non_ascii_literal, reason = "emojis are allowed")]

use std::str::FromStr;

use derive_more::From;
Expand Down Expand Up @@ -29,7 +27,7 @@ impl MessageBox {
///
/// Returns [`None`] if message is of unsupported kind.
#[must_use]
#[allow(
#[expect(
clippy::wildcard_enum_match_arm,
reason = "only exact variants are needed"
)]
Expand Down Expand Up @@ -61,9 +59,13 @@ impl MessageBox {
}

#[cfg(test)]
#[allow(
clippy::multiple_inherent_impl,
reason = "better looking conditional compilation"
#[cfg_attr(test, allow(clippy::allow_attributes, reason = "false positive"))]
#[cfg_attr(
test,
allow(
clippy::multiple_inherent_impl,
reason = "better looking conditional compilation"
)
)]
impl MessageBox {
#[must_use]
Expand Down Expand Up @@ -141,11 +143,11 @@ pub mod kind {

#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, reason = "it's ok in tests")]
#![expect(clippy::non_ascii_literal, reason = "emojis are allowed")]

use super::*;

#[allow(
#[expect(
dead_code,
unreachable_code,
unused_variables,
Expand Down
11 changes: 3 additions & 8 deletions telegram_gate/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains strongly-typed states of the [`Dialogue`](super::Dialogue).
#![allow(clippy::non_ascii_literal, reason = "messages may contain emojis")]
#![expect(clippy::non_ascii_literal, reason = "messages may contain emojis")]

#[cfg(test)]
use std::sync::Arc;
Expand Down Expand Up @@ -379,16 +379,11 @@ impl<T: Into<State> + Send> TryFromTransition<Self, command::Help> for T {

#[cfg(test)]
mod tests {
#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
reason = "it's ok in tests"
)]
#![expect(clippy::panic, reason = "it's ok in tests")]

use super::*;

#[allow(
#[expect(
dead_code,
unreachable_code,
unused_variables,
Expand Down
7 changes: 1 addition & 6 deletions telegram_gate/src/state/delete_confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,7 @@ impl TryFromTransition<ResourceActions, Button<button::kind::Delete>> for Delete

#[cfg(test)]
pub mod tests {
#![allow(
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
reason = "it's ok in tests"
)]
#![expect(clippy::panic, clippy::unwrap_used, reason = "it's ok in tests")]

pub mod command {
use tokio::test;
Expand Down
4 changes: 2 additions & 2 deletions telegram_gate/src/state/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl MainMenu {
}

/// [`setup()`](Self::setup) and [`setup_destroying()`](Self::setup_destroying) implementation.
#[allow(clippy::expect_used, reason = "indicates programmer error")]
#[expect(clippy::expect_used, reason = "indicates programmer error")]
async fn setup_impl(context: &Context) -> Result<Self, TransitionFailureReason> {
let buttons = [
[KeyboardButton::new(message::kind::List.to_string())],
Expand Down Expand Up @@ -196,7 +196,7 @@ impl TryFromTransition<DeleteConfirmation, Button<button::kind::Yes>> for MainMe

#[cfg(test)]
pub mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used, reason = "it's ok in tests")]
#![expect(clippy::unwrap_used, clippy::expect_used, reason = "it's ok in tests")]

pub mod command {
use teloxide::types::{KeyboardButton, KeyboardMarkup};
Expand Down
Loading

0 comments on commit ed1f34d

Please sign in to comment.