From 1b44a6f9124e55387c4e3f71ffb4c64c96d76f74 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sat, 3 Feb 2024 19:38:30 -0500 Subject: [PATCH] chore(config): apply clippy fixes --- cli/config/src/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 83b85358..b490fb8f 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -39,7 +39,7 @@ impl Config { } let legacy_path = dirs::home_dir() - .ok_or(anyhow!("Cannot determine home directory"))? + .ok_or_else(|| anyhow!("Cannot determine home directory"))? .join(".tree-sitter") .join("config.json"); if legacy_path.is_file() { @@ -51,7 +51,7 @@ impl Config { fn xdg_config_file() -> Result { let xdg_path = dirs::config_dir() - .ok_or(anyhow!("Cannot determine config directory"))? + .ok_or_else(|| anyhow!("Cannot determine config directory"))? .join("tree-sitter") .join("config.json"); Ok(xdg_path) @@ -65,16 +65,15 @@ impl Config { /// by [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html) /// - `$HOME/.tree-sitter/config.json` as a fallback from where tree-sitter _used_ to store /// its configuration - pub fn load() -> Result { - let location = match Self::find_config_file()? { - Some(location) => location, - None => return Config::initial(), + pub fn load() -> Result { + let Some(location) = Self::find_config_file()? else { + return Self::initial(); }; let content = fs::read_to_string(&location) .with_context(|| format!("Failed to read {}", &location.to_string_lossy()))?; let config = serde_json::from_str(&content) .with_context(|| format!("Bad JSON config {}", &location.to_string_lossy()))?; - Ok(Config { location, config }) + Ok(Self { location, config }) } /// Creates an empty initial configuration file. You can then use the [`Config::add`][] method @@ -83,7 +82,7 @@ impl Config { /// disk. /// /// (Note that this is typically only done by the `tree-sitter init-config` command.) - pub fn initial() -> Result { + pub fn initial() -> Result { let location = if let Ok(path) = env::var("TREE_SITTER_DIR") { let mut path = PathBuf::from(path); path.push("config.json"); @@ -92,7 +91,7 @@ impl Config { Self::xdg_config_file()? }; let config = serde_json::json!({}); - Ok(Config { location, config }) + Ok(Self { location, config }) } /// Saves this configuration to the file that it was originally loaded from.