Skip to content

Commit 8e9e65d

Browse files
authored
Merge pull request #54 from nightshift-micr/nightshift/lint-doctor-fix
[nightshift] lint-doctor-fix: apply clippy pedantic/nursery auto-fixes
2 parents b6832a0 + e1eedf2 commit 8e9e65d

10 files changed

Lines changed: 86 additions & 100 deletions

File tree

src/api.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ pub async fn execute_subscriber_summarize(
144144
let target_language = request
145145
.target_language
146146
.as_deref()
147-
.map(str::trim)
148-
.unwrap_or("");
147+
.map_or("", str::trim);
149148

150149
let client = build_client()?;
151150
let response = client
@@ -1822,14 +1821,12 @@ fn text_contains_news_filter_keyword(text: &str, keyword: &str) -> bool {
18221821
let start_ok = text[..index]
18231822
.chars()
18241823
.next_back()
1825-
.map(|ch| !is_news_filter_word_char(ch))
1826-
.unwrap_or(true);
1824+
.map_or(true, |ch| !is_news_filter_word_char(ch));
18271825
let end_index = index + keyword.len();
18281826
let end_ok = text[end_index..]
18291827
.chars()
18301828
.next()
1831-
.map(|ch| !is_news_filter_word_char(ch))
1832-
.unwrap_or(true);
1829+
.map_or(true, |ch| !is_news_filter_word_char(ch));
18331830

18341831
if start_ok && end_ok {
18351832
return true;
@@ -1839,7 +1836,7 @@ fn text_contains_news_filter_keyword(text: &str, keyword: &str) -> bool {
18391836
false
18401837
}
18411838

1842-
fn is_news_filter_word_char(ch: char) -> bool {
1839+
const fn is_news_filter_word_char(ch: char) -> bool {
18431840
ch.is_ascii_alphanumeric() || ch == '_'
18441841
}
18451842

@@ -1896,8 +1893,7 @@ fn resolve_news_category(
18961893
|| category.category_name.eq_ignore_ascii_case(requested)
18971894
|| metadata_map
18981895
.get(&category.category_id)
1899-
.map(|entry| entry.display_name.eq_ignore_ascii_case(requested))
1900-
.unwrap_or(false)
1896+
.is_some_and(|entry| entry.display_name.eq_ignore_ascii_case(requested))
19011897
}) {
19021898
return Ok(merge_news_category(
19031899
category.clone(),
@@ -2951,7 +2947,7 @@ fn format_client_error_suffix(body: &str) -> String {
29512947
}
29522948

29532949
if let Ok(payload) = serde_json::from_str::<Value>(trimmed) {
2954-
return format!("; {}", payload);
2950+
return format!("; {payload}");
29552951
}
29562952

29572953
format!("; {trimmed}")

src/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum CredentialKind {
1919
}
2020

2121
impl CredentialKind {
22-
pub fn as_str(self) -> &'static str {
22+
pub const fn as_str(self) -> &'static str {
2323
match self {
2424
Self::ApiToken => "api-token",
2525
Self::SessionToken => "session-token",
@@ -34,7 +34,7 @@ pub enum CredentialSource {
3434
}
3535

3636
impl CredentialSource {
37-
pub fn as_str(self) -> &'static str {
37+
pub const fn as_str(self) -> &'static str {
3838
match self {
3939
Self::Env => "env",
4040
Self::Config => "config",
@@ -59,7 +59,7 @@ impl SearchAuthPreference {
5959
}
6060
}
6161

62-
pub fn as_str(self) -> &'static str {
62+
pub const fn as_str(self) -> &'static str {
6363
match self {
6464
Self::Session => "session",
6565
Self::Api => "api",

src/auth_wizard.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::search;
1616

1717
const VALIDATION_QUERY: &str = "rust lang";
1818
const GOLD: u8 = 220;
19-
const AUTH_ASCII_ART: &str = r#" ███████ ███████ ███████ █████
19+
const AUTH_ASCII_ART: &str = r" ███████ ███████ ███████ █████
2020
███████ █████████ ███████ █████████
2121
███████ █████████ ███████ █████████
2222
███████ ███████ ███████ ███████ ███████
@@ -36,7 +36,7 @@ const AUTH_ASCII_ART: &str = r#" ███████
3636
███████████████████████
3737
███████████████████████
3838
████████ ████████
39-
███"#;
39+
███";
4040

4141
struct KagiAuthTheme;
4242

@@ -255,7 +255,7 @@ pub async fn run_auth_wizard() -> Result<(), KagiError> {
255255

256256
fn render_auth_intro() -> Result<(), KagiError> {
257257
let term = Term::stdout();
258-
let width = term.size_checked().map(|(_rows, cols)| cols).unwrap_or(0);
258+
let width = term.size_checked().map_or(0, |(_rows, cols)| cols);
259259

260260
if should_render_auth_ascii(width) {
261261
let mut stdout = io::stdout().lock();
@@ -334,7 +334,7 @@ fn build_candidate_credential(kind: CredentialKind, input: &str) -> Result<Crede
334334
})
335335
}
336336

337-
fn kind_display(kind: CredentialKind) -> &'static str {
337+
const fn kind_display(kind: CredentialKind) -> &'static str {
338338
match kind {
339339
CredentialKind::ApiToken => "API token",
340340
CredentialKind::SessionToken => "Session Link",
@@ -361,15 +361,13 @@ fn format_inventory_summary(inventory: &crate::auth::CredentialInventory) -> Str
361361
wizard_status_line(
362362
"Selected",
363363
&inventory
364-
.preferred_for_status()
365-
.map(|credential| {
364+
.preferred_for_status().map_or_else(|| "none".to_string(), |credential| {
366365
format!(
367366
"{} ({})",
368367
credential.kind.as_str(),
369368
credential.source.as_str()
370369
)
371-
})
372-
.unwrap_or_else(|| "none".to_string()),
370+
}),
373371
),
374372
wizard_status_line("Base Search", inventory.search_preference.as_str()),
375373
wizard_status_line(
@@ -390,15 +388,13 @@ fn format_saved_summary(inventory: &crate::auth::CredentialInventory) -> String
390388
wizard_status_line(
391389
"Selected",
392390
&inventory
393-
.preferred_for_status()
394-
.map(|credential| {
391+
.preferred_for_status().map_or_else(|| "none".to_string(), |credential| {
395392
format!(
396393
"{} ({})",
397394
credential.kind.as_str(),
398395
credential.source.as_str()
399396
)
400-
})
401-
.unwrap_or_else(|| "none".to_string()),
397+
}),
402398
),
403399
wizard_status_line("Base Search", inventory.search_preference.as_str()),
404400
wizard_status_line(
@@ -413,14 +409,14 @@ fn format_saved_summary(inventory: &crate::auth::CredentialInventory) -> String
413409
.join("\n")
414410
}
415411

416-
fn method_title(kind: CredentialKind) -> &'static str {
412+
const fn method_title(kind: CredentialKind) -> &'static str {
417413
match kind {
418414
CredentialKind::ApiToken => "API Token Setup",
419415
CredentialKind::SessionToken => "Session Link Setup",
420416
}
421417
}
422418

423-
fn method_prompt(kind: CredentialKind) -> &'static str {
419+
const fn method_prompt(kind: CredentialKind) -> &'static str {
424420
match kind {
425421
CredentialKind::ApiToken => "Paste your API token",
426422
CredentialKind::SessionToken => "Paste your Session Link or raw session token",
@@ -460,7 +456,7 @@ fn env_override_notice(kind: CredentialKind) -> Option<String> {
460456
env::var_os(env_var).map(|_| env_override_message(env_var))
461457
}
462458

463-
fn has_config_credential(snapshot: &ConfigAuthSnapshot, kind: CredentialKind) -> bool {
459+
const fn has_config_credential(snapshot: &ConfigAuthSnapshot, kind: CredentialKind) -> bool {
464460
match kind {
465461
CredentialKind::ApiToken => snapshot.api_token.is_some(),
466462
CredentialKind::SessionToken => snapshot.session_token.is_some(),
@@ -483,14 +479,14 @@ fn should_prompt_preference_with_other_method(
483479
other_method_configured && snapshot.search_preference != preference_for_kind(kind)
484480
}
485481

486-
fn preference_for_kind(kind: CredentialKind) -> SearchAuthPreference {
482+
const fn preference_for_kind(kind: CredentialKind) -> SearchAuthPreference {
487483
match kind {
488484
CredentialKind::ApiToken => SearchAuthPreference::Api,
489485
CredentialKind::SessionToken => SearchAuthPreference::Session,
490486
}
491487
}
492488

493-
fn other_kind(kind: CredentialKind) -> CredentialKind {
489+
const fn other_kind(kind: CredentialKind) -> CredentialKind {
494490
match kind {
495491
CredentialKind::ApiToken => CredentialKind::SessionToken,
496492
CredentialKind::SessionToken => CredentialKind::ApiToken,
@@ -501,7 +497,7 @@ fn other_method_configured(snapshot: &ConfigAuthSnapshot, kind: CredentialKind)
501497
has_config_credential(snapshot, other_kind(kind))
502498
}
503499

504-
fn env_var_name(kind: CredentialKind) -> &'static str {
500+
const fn env_var_name(kind: CredentialKind) -> &'static str {
505501
match kind {
506502
CredentialKind::ApiToken => API_TOKEN_ENV,
507503
CredentialKind::SessionToken => SESSION_TOKEN_ENV,

src/cli.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ pub enum OutputFormat {
3333
impl std::fmt::Display for OutputFormat {
3434
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3535
match self {
36-
OutputFormat::Json => write!(f, "json"),
37-
OutputFormat::Pretty => write!(f, "pretty"),
38-
OutputFormat::Compact => write!(f, "compact"),
39-
OutputFormat::Markdown => write!(f, "markdown"),
40-
OutputFormat::Csv => write!(f, "csv"),
36+
Self::Json => write!(f, "json"),
37+
Self::Pretty => write!(f, "pretty"),
38+
Self::Compact => write!(f, "compact"),
39+
Self::Markdown => write!(f, "markdown"),
40+
Self::Csv => write!(f, "csv"),
4141
}
4242
}
4343
}
@@ -57,10 +57,10 @@ pub enum QuickOutputFormat {
5757
impl std::fmt::Display for QuickOutputFormat {
5858
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5959
match self {
60-
QuickOutputFormat::Json => write!(f, "json"),
61-
QuickOutputFormat::Pretty => write!(f, "pretty"),
62-
QuickOutputFormat::Compact => write!(f, "compact"),
63-
QuickOutputFormat::Markdown => write!(f, "markdown"),
60+
Self::Json => write!(f, "json"),
61+
Self::Pretty => write!(f, "pretty"),
62+
Self::Compact => write!(f, "compact"),
63+
Self::Markdown => write!(f, "markdown"),
6464
}
6565
}
6666
}
@@ -76,10 +76,10 @@ pub enum AssistantOutputFormat {
7676
impl std::fmt::Display for AssistantOutputFormat {
7777
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7878
match self {
79-
AssistantOutputFormat::Json => write!(f, "json"),
80-
AssistantOutputFormat::Pretty => write!(f, "pretty"),
81-
AssistantOutputFormat::Compact => write!(f, "compact"),
82-
AssistantOutputFormat::Markdown => write!(f, "markdown"),
79+
Self::Json => write!(f, "json"),
80+
Self::Pretty => write!(f, "pretty"),
81+
Self::Compact => write!(f, "compact"),
82+
Self::Markdown => write!(f, "markdown"),
8383
}
8484
}
8585
}
@@ -107,7 +107,7 @@ pub enum LensTemplate {
107107
}
108108

109109
impl LensTemplate {
110-
pub fn as_form_value(&self) -> &'static str {
110+
pub const fn as_form_value(&self) -> &'static str {
111111
match self {
112112
Self::Default => "0",
113113
Self::News => "1",
@@ -122,7 +122,7 @@ pub enum NewsFilterMode {
122122
}
123123

124124
impl NewsFilterMode {
125-
pub fn as_str(&self) -> &'static str {
125+
pub const fn as_str(&self) -> &'static str {
126126
match self {
127127
Self::Hide => "hide",
128128
Self::Blur => "blur",
@@ -138,7 +138,7 @@ pub enum NewsFilterScope {
138138
}
139139

140140
impl NewsFilterScope {
141-
pub fn as_str(&self) -> &'static str {
141+
pub const fn as_str(&self) -> &'static str {
142142
match self {
143143
Self::Title => "title",
144144
Self::Summary => "summary",
@@ -199,7 +199,7 @@ pub enum Commands {
199199
AskPage(AskPageArgs),
200200
/// Translate text through Kagi Translate using session-token auth
201201
Translate(Box<TranslateArgs>),
202-
/// Answer a query with Kagi's FastGPT API
202+
/// Answer a query with Kagi's `FastGPT` API
203203
Fastgpt(FastGptArgs),
204204
/// Query Kagi's enrichment indexes
205205
Enrich(EnrichCommand),
@@ -246,13 +246,13 @@ pub struct SearchArgs {
246246
/// Scope search to a Kagi lens by numeric index (e.g., "0", "1", "2").
247247
///
248248
/// Lens indices are user-specific. Find yours by:
249-
/// 1. Visit https://kagi.com/settings/lenses to see enabled lenses
249+
/// 1. Visit <https://kagi.com/settings/lenses> to see enabled lenses
250250
/// 2. Search in Kagi web UI with a lens active
251251
/// 3. Check the URL for the "l=" parameter value
252252
#[arg(long, value_name = "INDEX")]
253253
pub lens: Option<String>,
254254

255-
/// Restrict results to a Kagi region code such as "us", "gb", or "no_region"
255+
/// Restrict results to a Kagi region code such as "us", "gb", or "`no_region`"
256256
#[arg(long, value_name = "REGION")]
257257
pub region: Option<String>,
258258

@@ -315,7 +315,7 @@ pub struct BatchSearchArgs {
315315
#[arg(long, value_name = "INDEX")]
316316
pub lens: Option<String>,
317317

318-
/// Restrict results to a Kagi region code such as "us", "gb", or "no_region"
318+
/// Restrict results to a Kagi region code such as "us", "gb", or "`no_region`"
319319
#[arg(long, value_name = "REGION")]
320320
pub region: Option<String>,
321321

@@ -505,7 +505,7 @@ impl NewsArgs {
505505
Ok(())
506506
}
507507

508-
pub fn has_filter_inputs(&self) -> bool {
508+
pub const fn has_filter_inputs(&self) -> bool {
509509
!self.filter_preset.is_empty() || !self.filter_keyword.is_empty()
510510
}
511511
}
@@ -799,7 +799,7 @@ pub struct TranslateArgs {
799799
#[arg(long)]
800800
pub preserve_formatting: Option<bool>,
801801

802-
/// Raw JSON array passed through as context_memory
802+
/// Raw JSON array passed through as `context_memory`
803803
#[arg(long, value_name = "JSON")]
804804
pub context_memory_json: Option<String>,
805805

@@ -849,7 +849,7 @@ pub struct EnrichCommand {
849849
pub enum EnrichSubcommand {
850850
/// Query Kagi's Teclis web enrichment index
851851
Web(EnrichArgs),
852-
/// Query Kagi's TinyGem news enrichment index
852+
/// Query Kagi's `TinyGem` news enrichment index
853853
News(EnrichArgs),
854854
}
855855

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ pub enum KagiError {
2020

2121
impl From<serde_json::Error> for KagiError {
2222
fn from(err: serde_json::Error) -> Self {
23-
KagiError::Parse(format!("JSON serialization error: {}", err))
23+
Self::Parse(format!("JSON serialization error: {err}"))
2424
}
2525
}

0 commit comments

Comments
 (0)