Skip to content

Commit

Permalink
Make clippy lints stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jan 23, 2024
1 parent b93c2b3 commit dc1809a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ windows-sys = { version = "0.52.0", features = ["Win32_System_Console", "Win32_F
[features]
docs = []

[lints.rust]
missing_debug_implementations = "warn"
missing_docs = "warn"

[lints.clippy]
unimplemented = "warn"
undocumented_unsafe_blocks = "deny"
dbg_macro = "warn"
exhaustive_enums = "warn"
exhaustive_structs = "warn"
unwrap_used = "deny"
use_debug = "warn"

[package.metadata.docs.rs]
features = ["docs", "rgb"]
rustdoc-args = ["--cfg", "docsrs"]
10 changes: 7 additions & 3 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/// An RGB color with 16 bits per channel.
#[derive(Debug, Clone, Default, Eq, PartialEq)]
#[allow(clippy::exhaustive_structs)]
pub struct Color {
/// Red
pub r: u16,
/// Green
pub g: u16,
/// Blue
pub b: u16,
}

Expand Down Expand Up @@ -89,9 +93,9 @@ fn srgb_to_lin(channel: f64) -> f64 {

// Luminance (Y)
fn luminance(color: &Color) -> f64 {
let r = color.r as f64 / u16::MAX as f64;
let g = color.g as f64 / u16::MAX as f64;
let b = color.b as f64 / u16::MAX as f64;
let r = f64::from(color.r) / f64::from(u16::MAX);
let g = f64::from(color.g) / f64::from(u16::MAX);
let b = f64::from(color.b) / f64::from(u16::MAX);
0.2126 * srgb_to_lin(r) + 0.7152 * srgb_to_lin(g) + 0.0722 * srgb_to_lin(b)
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![deny(clippy::undocumented_unsafe_blocks)]

//! Determines the background and foreground color of the terminal
//! using the `OSC 10` and `OSC 11` terminal sequence.
Expand Down Expand Up @@ -112,7 +111,9 @@ pub use color::*;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ColorScheme {
/// The foreground color of the terminal.
pub foreground: Color,
/// The background color of the terminal.
pub background: Color,
}

Expand Down Expand Up @@ -156,6 +157,7 @@ pub enum Error {
/// The terminal is known to be unsupported.
#[error("unsupported terminal")]
UnsupportedTerminal,
/// A precondition configured in [`QueryOptions::preconditions`] was not met.
#[error("precondition not met: {0}")]
UnmetPrecondition(String),
}
Expand Down

0 comments on commit dc1809a

Please sign in to comment.