Skip to content

Commit

Permalink
Add linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed Jun 12, 2024
1 parent 0d0195e commit 01d2cfb
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ lto = true
# improve debug backtrace performance with color-eyre
[profile.dev.package.backtrace]
opt-level = 3

[workspace.lints.clippy]
explicit_iter_loop = "warn"
question_mark = "warn"
redundant_closure_for_method_calls = "warn"
semicolon_if_nothing_returned = "warn"
3 changes: 3 additions & 0 deletions gravel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ thiserror.workspace = true

[dev-dependencies]
rstest.workspace = true

[lints]
workspace = true
8 changes: 2 additions & 6 deletions gravel-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ impl QueryEngine {
/// If one is found, the keyword is stripped from the query and the
/// resulting new query is run against that provider only.
fn try_keyword_query(&self, query: &str) -> Option<QueryResult> {
let Some(first_word) = query.split(' ').next() else {
return None;
};
let first_word = query.split(' ').next()?;

let Some(provider) = self.check_keywords(first_word) else {
return None;
};
let provider = self.check_keywords(first_word)?;

// remove the keyword from the query
let new_query = &query[first_word.len()..query.len()].trim_start();
Expand Down
2 changes: 1 addition & 1 deletion gravel-core/src/hotkeys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn init_hotkeys<T: 'static + Clone + Debug>(sender: &Sender<T>, hotkeys: Vec<Hot
fn convert_modifiers(modifiers: BitFlags<Modifier>) -> u32 {
let mut result = 0;

for modifier in modifiers.iter() {
for modifier in modifiers {
result |= convert_modifier(modifier);
}

Expand Down
3 changes: 3 additions & 0 deletions gravel-frontend-fltk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ serde.workspace = true

[target.'cfg(windows)'.dependencies]
winapi.workspace = true

[lints]
workspace = true
4 changes: 2 additions & 2 deletions gravel-frontend-fltk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const DEFAULT_CONFIG: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR")

/// Reads the [`DeserializedLayoutConfig`] from the adapter and transforms
/// it to the final [`Config`].
pub fn get_config(adapter: &PluginConfigAdapter) -> Config {
pub fn get(adapter: &PluginConfigAdapter) -> Config {
let config = adapter.get::<Config>(DEFAULT_CONFIG);

if config.behaviour.start_hidden && config.behaviour.exit_on_hide {
Expand Down Expand Up @@ -87,7 +87,7 @@ pub mod deserialize {
}

pub fn colors<'de, D: Deserializer<'de>>(de: D) -> Result<super::DetailedColors, D::Error> {
ColorVariants::deserialize(de).map(|v| v.into())
ColorVariants::deserialize(de).map(Into::into)
}

#[derive(Deserialize, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions gravel-frontend-fltk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! gravel's default frontend, based on fltk.
use crate::config::get_config;
use gravel_core::{config::PluginConfigAdapter, plugin::*, *};
use implementation::FltkFrontend;

Expand All @@ -22,5 +21,5 @@ pub fn register_plugins(registry: &mut PluginRegistry) {
}

fn get_frontend(engine: QueryEngine, config: &PluginConfigAdapter) -> Box<dyn Frontend> {
Box::new(FltkFrontend::new(engine, get_config(config)))
Box::new(FltkFrontend::new(engine, config::get(config)))
}
3 changes: 3 additions & 0 deletions gravel-provider-calculator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ serde.workspace = true

[dev-dependencies]
rstest.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion gravel-provider-calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Provider for CalculatorProvider {
let clipboard = self.get_clipboard();

let hit = SimpleHit::new(result, self.config.subtitle.clone(), move |h, s| {
do_copy(clipboard.clone(), h, s)
do_copy(clipboard.clone(), h, s);
})
.with_score(MAX_SCORE);

Expand Down
3 changes: 3 additions & 0 deletions gravel-provider-exec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ serde.workspace = true

[target.'cfg(windows)'.dependencies]
winapi = { workspace = true, features = ["shellapi"] }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions gravel-provider-kill/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ winapi.workspace = true
[target.'cfg(unix)'.dependencies]
nix = { workspace = true, features = ["process", "signal"] }
procfs.workspace = true

[lints]
workspace = true
3 changes: 3 additions & 0 deletions gravel-provider-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ shellexpand.workspace = true

[target.'cfg(unix)'.dependencies]
freedesktop_entry_parser.workspace = true

[lints]
workspace = true
3 changes: 2 additions & 1 deletion gravel-provider-program/src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::Config;
use gravel_core::*;
use std::borrow::Cow;
use std::path::Path;
use std::process::Command;
use std::sync::mpsc::Sender;
Expand All @@ -10,7 +11,7 @@ pub(crate) fn get_program_paths(config: &Config) -> Vec<String> {

fn expand_path(path: &String) -> Option<String> {
shellexpand::env(path)
.map(|p| p.into_owned())
.map(Cow::into_owned)
.map_err(|err| log::error!("couldn't expand shortcut_path '{path}': {err}"))
.ok()
}
Expand Down
3 changes: 3 additions & 0 deletions gravel-provider-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ serde.workspace = true
[target.'cfg(windows)'.dependencies]
winapi = { workspace = true, features = ["powrprof"] }
system_shutdown.workspace = true

[lints]
workspace = true
3 changes: 3 additions & 0 deletions gravel-provider-websearch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ log.workspace = true
open.workspace = true
serde.workspace = true
urlencoding.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion gravel-provider-websearch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn do_search(url_pattern: &str, hit: &SimpleHit, sender: &Sender<FrontendMessage

log::debug!("opening URL '{url}'");
if let Err(err) = open::that(url) {
log::error!("unable to open URL: {err}")
log::error!("unable to open URL: {err}");
}

sender.send(FrontendMessage::Hide).ok();
Expand Down
3 changes: 3 additions & 0 deletions gravel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ winapi = { workspace = true, features = ["wincon"] }

[target.'cfg(unix)'.dependencies]
exec.workspace = true

[lints]
workspace = true
4 changes: 1 addition & 3 deletions gravel/src/init/single_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use single_instance::SingleInstance;
/// Checks for duplicate instances with the given name.
/// If `name` is [`None`], does nothing.
pub fn single_instance(name: Option<&str>) -> Option<SingleInstance> {
let Some(name) = name else {
return None;
};
let name = name?;

log::debug!("initializing single-instance with key {name}");

Expand Down

0 comments on commit 01d2cfb

Please sign in to comment.