From 9be0f98f71fe8071ab839ac1036b4064ac3172b4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 29 Jun 2026 00:03:00 +0900 Subject: chore(lint): ban bare `use anyhow::Result` and fully qualify it Add a no_banned_use linter that forbids importing anyhow::Result, and update all call sites to reference it via its fully-qualified path so it is never confused with std::result::Result. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/package/loader/array_loader.rs | 20 ++-- crates/shirabe/src/package/loader/json_loader.rs | 3 +- crates/shirabe/src/package/locker.rs | 108 +++++++++++---------- .../shirabe/src/package/version/version_bumper.rs | 3 +- .../shirabe/src/package/version/version_guesser.rs | 27 +++--- 5 files changed, 84 insertions(+), 77 deletions(-) (limited to 'crates/shirabe/src/package') diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index 07ad11f..b85fbe6 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -15,7 +15,6 @@ use crate::package::RootPackageHandle; use crate::package::SUPPORTED_LINK_TYPES; use crate::package::loader::LoaderInterface; use crate::package::version::VersionParser; -use anyhow::Result; use chrono::Utc; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; @@ -152,7 +151,7 @@ impl LoaderInterface for ArrayLoader { &self, mut config: IndexMap, class: Option, - ) -> Result { + ) -> anyhow::Result { let class = class.unwrap_or_else(|| "Composer\\Package\\CompletePackage".to_string()); if class != "Composer\\Package\\CompletePackage" @@ -199,7 +198,7 @@ impl ArrayLoader { pub fn load_packages( &self, versions: Vec>, - ) -> Result> { + ) -> anyhow::Result> { let mut packages: Vec = vec![]; let mut link_cache: IndexMap< String, @@ -222,7 +221,7 @@ impl ArrayLoader { &self, config: &IndexMap, class: &str, - ) -> Result { + ) -> anyhow::Result { if !config.contains_key("name") { return Err(UnexpectedValueException { message: format!( @@ -312,7 +311,7 @@ impl ArrayLoader { &self, mut package: CompleteOrRootPackage, config: &mut IndexMap, - ) -> Result { + ) -> anyhow::Result { package .package_mut() .set_type(if let Some(t) = config.get("type") { @@ -704,7 +703,7 @@ impl ArrayLoader { >, package: &mut CompleteOrRootPackage, config: &IndexMap, - ) -> Result<()> { + ) -> anyhow::Result<()> { let name = package.get_name().to_string(); let pretty_version = package.get_pretty_version().to_string(); @@ -786,7 +785,7 @@ impl ArrayLoader { source_version: &str, description: &str, links: IndexMap, - ) -> Result> { + ) -> anyhow::Result> { let mut res: IndexMap = IndexMap::new(); for (target, constraint) in links { if !is_string(&constraint) { @@ -818,7 +817,7 @@ impl ArrayLoader { description: &str, target: &str, pretty_constraint: &str, - ) -> Result { + ) -> anyhow::Result { // PHP: if (!\is_string($prettyConstraint)) — always true in Rust signature, kept for parity let _ = pretty_constraint; @@ -856,7 +855,10 @@ impl ArrayLoader { /// @param mixed[] $config the entire package config /// /// @return string|null normalized version of the branch alias or null if there is none - pub fn get_branch_alias(&self, config: &IndexMap) -> Result> { + pub fn get_branch_alias( + &self, + config: &IndexMap, + ) -> anyhow::Result> { if !config.contains_key("version") || !is_scalar(config.get("version").unwrap()) { return Err(UnexpectedValueException { message: "no/invalid version defined".to_string(), diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs index d48a2fe..205028f 100644 --- a/crates/shirabe/src/package/loader/json_loader.rs +++ b/crates/shirabe/src/package/loader/json_loader.rs @@ -3,7 +3,6 @@ use crate::json::JsonFile; use crate::package::PackageInterfaceHandle; use crate::package::loader::LoaderInterface; -use anyhow::Result; use indexmap::IndexMap; use shirabe_php_shim::{PhpMixed, TypeError}; use std::path::Path; @@ -22,7 +21,7 @@ impl JsonLoader { Self { loader } } - pub fn load(&self, json: JsonLoaderInput) -> Result { + pub fn load(&self, json: JsonLoaderInput) -> anyhow::Result { let config = match json { JsonLoaderInput::File(mut json_file) => json_file.read()?, JsonLoaderInput::String(ref s) if Path::new(s).exists() => { diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index 09c2def..94f4625 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -23,7 +23,6 @@ use crate::repository::RepositoryInterfaceHandle; use crate::repository::RootPackageRepository; use crate::util::Git as GitUtil; use crate::util::ProcessExecutor; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::seld::json_lint::ParsingException; @@ -84,7 +83,7 @@ impl Locker { } /// Returns the md5 hash of the sorted content of the composer file. - pub fn get_content_hash(composer_file_contents: &str) -> Result { + pub fn get_content_hash(composer_file_contents: &str) -> anyhow::Result { let content = JsonFile::parse_json(Some(composer_file_contents), Some("composer.json"))?; let content_map: IndexMap = match &content { PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), v.clone())).collect(), @@ -151,7 +150,7 @@ impl Locker { } /// Checks whether the lock file is still up to date with the current hash - pub fn is_fresh(&mut self) -> Result { + pub fn is_fresh(&mut self) -> anyhow::Result { let lock = self.lock_file.read()?; let lock_map: IndexMap = match lock { PhpMixed::Array(m) => m.into_iter().collect(), @@ -182,7 +181,7 @@ impl Locker { pub fn get_locked_repository( &mut self, with_dev_reqs: bool, - ) -> Result { + ) -> anyhow::Result { let lock_data = self.get_lock_data()?; let packages: LockArrayRepositoryHandle = LockArrayRepositoryHandle::new(LockArrayRepository::new(vec![])?); @@ -281,7 +280,7 @@ impl Locker { } /// @return string[] Names of dependencies installed through require-dev - pub fn get_dev_package_names(&mut self) -> Result> { + pub fn get_dev_package_names(&mut self) -> anyhow::Result> { let mut names: Vec = vec![]; let lock_data = self.get_lock_data()?; if let Some(PhpMixed::List(list)) = lock_data.get("packages-dev") { @@ -298,7 +297,7 @@ impl Locker { } /// Returns the platform requirements stored in the lock file - pub fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result> { + pub fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result> { let lock_data = self.get_lock_data()?; let mut requirements: IndexMap = IndexMap::new(); @@ -341,7 +340,7 @@ impl Locker { } /// @return key-of - pub fn get_minimum_stability(&mut self) -> Result { + pub fn get_minimum_stability(&mut self) -> anyhow::Result { let lock_data = self.get_lock_data()?; Ok(lock_data @@ -352,7 +351,7 @@ impl Locker { } /// @return array - pub fn get_stability_flags(&mut self) -> Result> { + pub fn get_stability_flags(&mut self) -> anyhow::Result> { let lock_data = self.get_lock_data()?; Ok(lock_data @@ -368,7 +367,7 @@ impl Locker { .unwrap_or_default()) } - pub fn get_prefer_stable(&mut self) -> Result> { + pub fn get_prefer_stable(&mut self) -> anyhow::Result> { let lock_data = self.get_lock_data()?; // return null if not set to allow caller logic to choose the @@ -376,14 +375,14 @@ impl Locker { Ok(lock_data.get("prefer-stable").and_then(|v| v.as_bool())) } - pub fn get_prefer_lowest(&mut self) -> Result> { + pub fn get_prefer_lowest(&mut self) -> anyhow::Result> { let lock_data = self.get_lock_data()?; Ok(lock_data.get("prefer-lowest").and_then(|v| v.as_bool())) } /// @return array - pub fn get_platform_overrides(&mut self) -> Result> { + pub fn get_platform_overrides(&mut self) -> anyhow::Result> { let lock_data = self.get_lock_data()?; Ok(lock_data @@ -400,7 +399,7 @@ impl Locker { } /// @return string[][] - pub fn get_aliases(&mut self) -> Result>> { + pub fn get_aliases(&mut self) -> anyhow::Result>> { let lock_data = self.get_lock_data()?; Ok(lock_data @@ -425,7 +424,7 @@ impl Locker { .unwrap_or_default()) } - pub fn get_plugin_api(&mut self) -> Result { + pub fn get_plugin_api(&mut self) -> anyhow::Result { let lock_data = self.get_lock_data()?; Ok(lock_data @@ -436,7 +435,7 @@ impl Locker { } /// @return array - pub fn get_lock_data(&mut self) -> Result> { + pub fn get_lock_data(&mut self) -> anyhow::Result> { if let Some(cache) = self.lock_data_cache.borrow().clone() { return Ok(cache); } @@ -473,7 +472,7 @@ impl Locker { prefer_lowest: bool, platform_overrides: IndexMap, write: bool, - ) -> Result { + ) -> anyhow::Result { // keep old default branch names normalized to DEFAULT_BRANCH_ALIAS for BC as that is how Composer 1 outputs the lock file // when loading the lock file the version is anyway ignored in Composer 2, so it has no adverse effect let aliases: Vec> = array_map( @@ -635,7 +634,7 @@ impl Locker { Ok(false) } - fn is_locked_result(&mut self) -> Result { + fn is_locked_result(&mut self) -> anyhow::Result { Ok(self.is_locked()) } @@ -646,7 +645,7 @@ impl Locker { data_processor: Option< Box) -> IndexMap>, >, - ) -> Result<()> { + ) -> anyhow::Result<()> { let contents = file_get_contents(composer_json.get_path()); let contents = match contents { Some(s) => s, @@ -719,7 +718,7 @@ impl Locker { } /// @param PackageInterface[] $packages - fn lock_packages(&mut self, packages: &[PackageInterfaceHandle]) -> Result { + fn lock_packages(&mut self, packages: &[PackageInterfaceHandle]) -> anyhow::Result { let mut locked: Vec> = vec![]; for package in packages { @@ -791,7 +790,10 @@ impl Locker { } /// Returns the packages's datetime for its source reference. - fn get_package_time(&mut self, package: PackageInterfaceHandle) -> Result> { + fn get_package_time( + &mut self, + package: PackageInterfaceHandle, + ) -> anyhow::Result> { if !function_exists("proc_open") { return Ok(None); } @@ -895,7 +897,7 @@ impl Locker { &mut self, package: RootPackageInterfaceHandle, include_dev: bool, - ) -> Result> { + ) -> anyhow::Result> { let mut missing_requirement_info: Vec = vec![]; let mut missing_requirements = false; let mut sets: Vec = vec![SetEntry { @@ -1006,18 +1008,21 @@ impl Locker { pub trait LockerInterface: std::fmt::Debug { fn get_json_file(&self) -> &JsonFile; fn is_locked(&mut self) -> bool; - fn is_fresh(&mut self) -> Result; - fn get_locked_repository(&mut self, with_dev_reqs: bool) -> Result; - fn get_dev_package_names(&mut self) -> Result>; - fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result>; - fn get_minimum_stability(&mut self) -> Result; - fn get_stability_flags(&mut self) -> Result>; - fn get_prefer_stable(&mut self) -> Result>; - fn get_prefer_lowest(&mut self) -> Result>; - fn get_platform_overrides(&mut self) -> Result>; - fn get_aliases(&mut self) -> Result>>; - fn get_plugin_api(&mut self) -> Result; - fn get_lock_data(&mut self) -> Result>; + fn is_fresh(&mut self) -> anyhow::Result; + fn get_locked_repository( + &mut self, + with_dev_reqs: bool, + ) -> anyhow::Result; + fn get_dev_package_names(&mut self) -> anyhow::Result>; + fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result>; + fn get_minimum_stability(&mut self) -> anyhow::Result; + fn get_stability_flags(&mut self) -> anyhow::Result>; + fn get_prefer_stable(&mut self) -> anyhow::Result>; + fn get_prefer_lowest(&mut self) -> anyhow::Result>; + fn get_platform_overrides(&mut self) -> anyhow::Result>; + fn get_aliases(&mut self) -> anyhow::Result>>; + fn get_plugin_api(&mut self) -> anyhow::Result; + fn get_lock_data(&mut self) -> anyhow::Result>; #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")] fn set_lock_data( &mut self, @@ -1032,19 +1037,19 @@ pub trait LockerInterface: std::fmt::Debug { prefer_lowest: bool, platform_overrides: IndexMap, write: bool, - ) -> Result; + ) -> anyhow::Result; fn update_hash( &mut self, composer_json: &JsonFile, data_processor: Option< Box) -> IndexMap>, >, - ) -> Result<()>; + ) -> anyhow::Result<()>; fn get_missing_requirement_info( &mut self, package: RootPackageInterfaceHandle, include_dev: bool, - ) -> Result>; + ) -> anyhow::Result>; } impl LockerInterface for Locker { @@ -1056,51 +1061,54 @@ impl LockerInterface for Locker { self.is_locked() } - fn is_fresh(&mut self) -> Result { + fn is_fresh(&mut self) -> anyhow::Result { self.is_fresh() } - fn get_locked_repository(&mut self, with_dev_reqs: bool) -> Result { + fn get_locked_repository( + &mut self, + with_dev_reqs: bool, + ) -> anyhow::Result { self.get_locked_repository(with_dev_reqs) } - fn get_dev_package_names(&mut self) -> Result> { + fn get_dev_package_names(&mut self) -> anyhow::Result> { self.get_dev_package_names() } - fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result> { + fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result> { self.get_platform_requirements(with_dev_reqs) } - fn get_minimum_stability(&mut self) -> Result { + fn get_minimum_stability(&mut self) -> anyhow::Result { self.get_minimum_stability() } - fn get_stability_flags(&mut self) -> Result> { + fn get_stability_flags(&mut self) -> anyhow::Result> { self.get_stability_flags() } - fn get_prefer_stable(&mut self) -> Result> { + fn get_prefer_stable(&mut self) -> anyhow::Result> { self.get_prefer_stable() } - fn get_prefer_lowest(&mut self) -> Result> { + fn get_prefer_lowest(&mut self) -> anyhow::Result> { self.get_prefer_lowest() } - fn get_platform_overrides(&mut self) -> Result> { + fn get_platform_overrides(&mut self) -> anyhow::Result> { self.get_platform_overrides() } - fn get_aliases(&mut self) -> Result>> { + fn get_aliases(&mut self) -> anyhow::Result>> { self.get_aliases() } - fn get_plugin_api(&mut self) -> Result { + fn get_plugin_api(&mut self) -> anyhow::Result { self.get_plugin_api() } - fn get_lock_data(&mut self) -> Result> { + fn get_lock_data(&mut self) -> anyhow::Result> { self.get_lock_data() } @@ -1118,7 +1126,7 @@ impl LockerInterface for Locker { prefer_lowest: bool, platform_overrides: IndexMap, write: bool, - ) -> Result { + ) -> anyhow::Result { self.set_lock_data( packages, dev_packages, @@ -1140,7 +1148,7 @@ impl LockerInterface for Locker { data_processor: Option< Box) -> IndexMap>, >, - ) -> Result<()> { + ) -> anyhow::Result<()> { self.update_hash(composer_json, data_processor) } @@ -1148,7 +1156,7 @@ impl LockerInterface for Locker { &mut self, package: RootPackageInterfaceHandle, include_dev: bool, - ) -> Result> { + ) -> anyhow::Result> { self.get_missing_requirement_info(package, include_dev) } } diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs index 4deb450..4f2d324 100644 --- a/crates/shirabe/src/package/version/version_bumper.rs +++ b/crates/shirabe/src/package/version/version_bumper.rs @@ -5,7 +5,6 @@ use crate::package::dumper::ArrayDumper; use crate::package::loader::ArrayLoader; use crate::package::version::VersionParser; use crate::util::Platform; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_semver::Intervals; @@ -19,7 +18,7 @@ impl VersionBumper { &self, constraint: &AnyConstraint, package: PackageInterfaceHandle, - ) -> Result { + ) -> anyhow::Result { let parser = VersionParser::new(); let pretty_constraint = constraint.get_pretty_string(); if pretty_constraint.starts_with("dev-") { diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 6fba7c4..249646c 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -11,7 +11,6 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use crate::util::sync_executor; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ @@ -28,9 +27,9 @@ pub trait VersionGuesserInterface: std::fmt::Debug { &mut self, package_config: &IndexMap, path: &str, - ) -> Result>; + ) -> anyhow::Result>; - fn get_root_version_from_env(&self) -> Result; + fn get_root_version_from_env(&self) -> anyhow::Result; } /// Try to guess the current version number based on different VCS configuration. @@ -103,7 +102,7 @@ impl VersionGuesser { &mut self, package_config: &IndexMap, path: &str, - ) -> Result> { + ) -> anyhow::Result> { // For testing only (ref VersionGuesserMock::guessVersion returns null). if self.mock { return Ok(None); @@ -207,7 +206,7 @@ impl VersionGuesser { &mut self, package_config: &IndexMap, path: &str, - ) -> Result { + ) -> anyhow::Result { GitUtil::clean_env(&self.process); let mut commit: Option = None; let mut version: Option = None; @@ -365,7 +364,7 @@ impl VersionGuesser { } /// @return array{version: string, pretty_version: string}|null - fn version_from_git_tags(&mut self, path: &str) -> Result> { + fn version_from_git_tags(&mut self, path: &str) -> anyhow::Result> { // try to fetch current version from git tags let mut output = String::new(); if 0 == self.process.borrow_mut().execute_args( @@ -394,7 +393,7 @@ impl VersionGuesser { &mut self, package_config: &IndexMap, path: &str, - ) -> Result> { + ) -> anyhow::Result> { // try to fetch current version from hg branch let mut output = String::new(); if 0 == self.process.borrow_mut().execute_args( @@ -492,7 +491,7 @@ impl VersionGuesser { mut branches: Vec, scm_cmdline: Vec, path: &str, - ) -> Result { + ) -> anyhow::Result { let mut pretty_version: Option = version.clone(); let mut version = version; @@ -546,7 +545,7 @@ impl VersionGuesser { // PHP runs every candidate diff in parallel and cancels the siblings once a zero-length // diff is found; the single-threaded sync bridge block_on's each diff serially and stops // at the first zero-length match. - let result: Result<()> = (|| -> Result<()> { + let result: anyhow::Result<()> = (|| -> anyhow::Result<()> { let mut last_index: i64 = -1; for (index, candidate) in branches.iter().enumerate() { let index = index as i64; @@ -635,7 +634,7 @@ impl VersionGuesser { } /// @return array{version: string|null, commit: '', pretty_version: string|null} - fn guess_fossil_version(&mut self, path: &str) -> Result { + fn guess_fossil_version(&mut self, path: &str) -> anyhow::Result { let mut version: Option = None; let mut pretty_version: Option = None; @@ -687,7 +686,7 @@ impl VersionGuesser { &mut self, package_config: &IndexMap, path: &str, - ) -> Result> { + ) -> anyhow::Result> { SvnUtil::clean_env(); // try to fetch current version from svn @@ -760,7 +759,7 @@ impl VersionGuesser { Ok(None) } - pub fn get_root_version_from_env(&self) -> Result { + pub fn get_root_version_from_env(&self) -> anyhow::Result { let version = Platform::get_env("COMPOSER_ROOT_VERSION"); let version = match version { Some(v) if !v.is_empty() => v, @@ -789,11 +788,11 @@ impl VersionGuesserInterface for VersionGuesser { &mut self, package_config: &IndexMap, path: &str, - ) -> Result> { + ) -> anyhow::Result> { VersionGuesser::guess_version(self, package_config, path) } - fn get_root_version_from_env(&self) -> Result { + fn get_root_version_from_env(&self) -> anyhow::Result { VersionGuesser::get_root_version_from_env(self) } } -- cgit v1.3.1