aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-11 19:45:17 +0900
committernsfisis <nsfisis@gmail.com>2026-05-11 19:45:17 +0900
commit24cc697a9cd0dcac854359d65b8265f02f483b72 (patch)
treec9693dbf3136d840157609161a3a5695828e853b /crates/mozart-core
parent2aceeb116150b6d6e6d3f371c2af509902ceafea (diff)
downloadphp-mozart-24cc697a9cd0dcac854359d65b8265f02f483b72.tar.gz
php-mozart-24cc697a9cd0dcac854359d65b8265f02f483b72.tar.zst
php-mozart-24cc697a9cd0dcac854359d65b8265f02f483b72.zip
chore(lint): add Ruby linter scripts and apply rules
Adds scripts/lint with linters for mod.rs naming, contiguous use blocks, use-as aliasing, sorted Cargo dependencies, std::collections maps, and workspace dependency requirements. Renames mod.rs files, reorders use statements, drops unnecessary import aliases, and sorts Cargo.toml entries to satisfy the new rules.
Diffstat (limited to 'crates/mozart-core')
-rw-r--r--crates/mozart-core/src/config.rs3
-rw-r--r--crates/mozart-core/src/config_source.rs3
-rw-r--r--crates/mozart-core/src/config_validator.rs16
-rw-r--r--crates/mozart-core/src/installer.rs (renamed from crates/mozart-core/src/installer/mod.rs)0
-rw-r--r--crates/mozart-core/src/package/archiver/archive_manager.rs3
-rw-r--r--crates/mozart-core/src/repository/downloader.rs2
-rw-r--r--crates/mozart-core/src/repository/installer_executor.rs (renamed from crates/mozart-core/src/repository/installer_executor/mod.rs)3
-rw-r--r--crates/mozart-core/src/repository/installer_executor/trace_recorder.rs3
-rw-r--r--crates/mozart-core/src/repository/path_repository.rs13
-rw-r--r--crates/mozart-core/src/repository/repository.rs (renamed from crates/mozart-core/src/repository/repository/mod.rs)3
-rw-r--r--crates/mozart-core/src/vcs/process.rs3
-rw-r--r--crates/mozart-core/src/vcs/util.rs (renamed from crates/mozart-core/src/vcs/util/mod.rs)0
12 files changed, 21 insertions, 31 deletions
diff --git a/crates/mozart-core/src/config.rs b/crates/mozart-core/src/config.rs
index 58d1d17..1fbbb41 100644
--- a/crates/mozart-core/src/config.rs
+++ b/crates/mozart-core/src/config.rs
@@ -5,12 +5,11 @@
//! known properties. Unknown properties are captured in the `extra` map so
//! that round-tripping through serde is lossless.
+use crate::composer::composer_home;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
-use crate::composer::composer_home;
-
/// Parse a size string like "300MiB", "1GB", "512k", or a plain integer string
/// into a byte count. Mirrors Composer's `Config::get('cache-files-maxsize')`.
fn parse_size_bytes(s: &str) -> Option<u64> {
diff --git a/crates/mozart-core/src/config_source.rs b/crates/mozart-core/src/config_source.rs
index 984007a..42d2d6f 100644
--- a/crates/mozart-core/src/config_source.rs
+++ b/crates/mozart-core/src/config_source.rs
@@ -1,6 +1,5 @@
-use std::path::{Path, PathBuf};
-
use anyhow::anyhow;
+use std::path::{Path, PathBuf};
pub struct JsonConfigSource {
path: PathBuf,
diff --git a/crates/mozart-core/src/config_validator.rs b/crates/mozart-core/src/config_validator.rs
index dbed651..85cc538 100644
--- a/crates/mozart-core/src/config_validator.rs
+++ b/crates/mozart-core/src/config_validator.rs
@@ -5,13 +5,11 @@
//! Composer's: `ValidateCommand` and `DiagnoseCommand` each `new
//! ConfigValidator(...)`; neither depends on the other.
+use crate::validation;
+use regex::Regex;
use std::collections::HashSet;
use std::sync::LazyLock;
-use regex::Regex;
-
-use crate::validation as v;
-
static DEPRECATED_GPL_OR_LATER_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?i)^[AL]?GPL-[123](\.[01])?\+$").unwrap());
@@ -113,7 +111,7 @@ fn check_name(obj: &serde_json::Map<String, serde_json::Value>, result: &mut Val
if name.chars().any(|c| c.is_ascii_uppercase()) {
let suggested = name
.split('/')
- .map(v::sanitize_package_name_component)
+ .map(validation::sanitize_package_name_component)
.collect::<Vec<_>>()
.join("/");
result.publish_errors.push(format!(
@@ -122,7 +120,7 @@ fn check_name(obj: &serde_json::Map<String, serde_json::Value>, result: &mut Val
));
}
- if !name.is_empty() && !v::validate_package_name(name) && !name.contains('/') {
+ if !name.is_empty() && !validation::validate_package_name(name) && !name.contains('/') {
result.errors.push(format!(
"The name \"{name}\" is invalid, it should be in the format \"vendor/package\"."
));
@@ -224,11 +222,11 @@ fn check_license(obj: &serde_json::Map<String, serde_json::Value>, result: &mut
continue;
}
let to_validate = license.replace("proprietary", "MIT");
- if v::validate_license(&to_validate) {
+ if validation::validate_license(&to_validate) {
continue;
}
let quoted = serde_json::to_string(license).unwrap_or_else(|_| format!("\"{license}\""));
- if v::validate_license(to_validate.trim()) {
+ if validation::validate_license(to_validate.trim()) {
result.warnings.push(format!(
"License {quoted} must not contain extra spaces, make sure to trim it."
));
@@ -461,7 +459,7 @@ fn check_minimum_stability(
result: &mut ValidationResult,
) {
if let Some(stability) = obj.get("minimum-stability").and_then(|v| v.as_str())
- && !v::validate_stability(stability)
+ && !validation::validate_stability(stability)
{
result.errors.push(format!(
"The minimum-stability \"{stability}\" is invalid. \
diff --git a/crates/mozart-core/src/installer/mod.rs b/crates/mozart-core/src/installer.rs
index 8572627..8572627 100644
--- a/crates/mozart-core/src/installer/mod.rs
+++ b/crates/mozart-core/src/installer.rs
diff --git a/crates/mozart-core/src/package/archiver/archive_manager.rs b/crates/mozart-core/src/package/archiver/archive_manager.rs
index b4f8e27..14497b2 100644
--- a/crates/mozart-core/src/package/archiver/archive_manager.rs
+++ b/crates/mozart-core/src/package/archiver/archive_manager.rs
@@ -1,9 +1,8 @@
-use crate::downloader::DownloadManager;
-
use super::{
ArchiveFormat, collect_archivable_files, create_archive, generate_archive_filename,
parse_composer_excludes, parse_gitattributes, parse_gitignore_pattern, self_exclusion_patterns,
};
+use crate::downloader::DownloadManager;
use std::path::{Path, PathBuf};
/// A package to be archived.
diff --git a/crates/mozart-core/src/repository/downloader.rs b/crates/mozart-core/src/repository/downloader.rs
index f2e33a7..711a678 100644
--- a/crates/mozart-core/src/repository/downloader.rs
+++ b/crates/mozart-core/src/repository/downloader.rs
@@ -350,7 +350,7 @@ pub async fn install_package(
#[cfg(test)]
mod tests {
use super::*;
- use std::io::Write as IoWrite;
+ use std::io::Write as _;
use tempfile::tempdir;
/// Build a minimal zip archive in memory.
diff --git a/crates/mozart-core/src/repository/installer_executor/mod.rs b/crates/mozart-core/src/repository/installer_executor.rs
index f67c612..1cb26d2 100644
--- a/crates/mozart-core/src/repository/installer_executor/mod.rs
+++ b/crates/mozart-core/src/repository/installer_executor.rs
@@ -13,10 +13,9 @@
//! Composer's `(string) $operation` byte-for-byte without the executor
//! having to also reproduce console formatting.
-use std::path::PathBuf;
-
use super::installed::InstalledPackageEntry;
use super::lockfile::{LockAlias, LockedPackage};
+use std::path::PathBuf;
pub mod filesystem;
pub mod trace_recorder;
diff --git a/crates/mozart-core/src/repository/installer_executor/trace_recorder.rs b/crates/mozart-core/src/repository/installer_executor/trace_recorder.rs
index b60a869..5dd39b0 100644
--- a/crates/mozart-core/src/repository/installer_executor/trace_recorder.rs
+++ b/crates/mozart-core/src/repository/installer_executor/trace_recorder.rs
@@ -14,12 +14,11 @@
//! - Update (downgrade direction): `Downgrading <name> (<oldVersion> => <newVersion>)`
//! - Uninstall: `Removing <name> (<version>)`
-use mozart_semver::Version;
-
use super::{
ExecuteContext, InstallerExecutor, PackageOperation, format_full_pretty_alias,
format_full_pretty_version,
};
+use mozart_semver::Version;
/// Recording-only executor. Construct with [`TraceRecorderExecutor::new`],
/// then read [`TraceRecorderExecutor::trace`] after the run completes.
diff --git a/crates/mozart-core/src/repository/path_repository.rs b/crates/mozart-core/src/repository/path_repository.rs
index 0cff012..2353809 100644
--- a/crates/mozart-core/src/repository/path_repository.rs
+++ b/crates/mozart-core/src/repository/path_repository.rs
@@ -19,11 +19,10 @@
//! consumers comparing references against Composer-produced lockfiles see
//! byte-identical values.
-use std::path::{Path, PathBuf};
-
use crate::package::RawRepository;
-use mozart_php_serialize::{Value as PhpValue, serialize as php_serialize};
+use mozart_php_serialize::{Value, serialize};
use sha1::{Digest as _, Sha1};
+use std::path::{Path, PathBuf};
/// Translate path repos in `repositories` into synthetic `type: package`
/// entries. Non-path entries are returned unchanged in original order.
@@ -123,11 +122,11 @@ fn resolve_path(url: &str, base_dir: &Path) -> PathBuf {
/// flag is the only option Composer's auto-detection populates when the user
/// supplied no `options` block.
fn compute_path_reference(json_bytes: &[u8], is_relative: bool) -> String {
- let options = PhpValue::Array(vec![(
- PhpValue::String("relative".to_string()),
- PhpValue::Bool(is_relative),
+ let options = Value::Array(vec![(
+ Value::String("relative".to_string()),
+ Value::Bool(is_relative),
)]);
- let serialized = php_serialize(&options);
+ let serialized = serialize(&options);
let mut hasher = Sha1::new();
hasher.update(json_bytes);
hasher.update(serialized.as_bytes());
diff --git a/crates/mozart-core/src/repository/repository/mod.rs b/crates/mozart-core/src/repository/repository.rs
index 4afff54..ece0c5f 100644
--- a/crates/mozart-core/src/repository/repository/mod.rs
+++ b/crates/mozart-core/src/repository/repository.rs
@@ -10,10 +10,9 @@
//! the live Packagist HTTP repo, [`inline_package_repo`] for `type: package`
//! entries embedded in `composer.json`, and [`vcs_repo`] for VCS repositories.
-use std::collections::BTreeMap;
-
use super::advisory::{MatchedAdvisory, PackageInfo};
use super::packagist::{PackagistVersion, SearchResult};
+use std::collections::BTreeMap;
pub mod inline_package_repo;
pub mod packagist_repo;
diff --git a/crates/mozart-core/src/vcs/process.rs b/crates/mozart-core/src/vcs/process.rs
index 8ccc11d..7538d55 100644
--- a/crates/mozart-core/src/vcs/process.rs
+++ b/crates/mozart-core/src/vcs/process.rs
@@ -1,10 +1,9 @@
+use anyhow::{Result, bail};
use indexmap::IndexMap;
use std::path::Path;
use std::process::Command;
use std::time::{Duration, Instant};
-use anyhow::{Result, bail};
-
/// Output from a process execution.
#[derive(Debug, Clone)]
pub struct ProcessOutput {
diff --git a/crates/mozart-core/src/vcs/util/mod.rs b/crates/mozart-core/src/vcs/util.rs
index b2c35fc..b2c35fc 100644
--- a/crates/mozart-core/src/vcs/util/mod.rs
+++ b/crates/mozart-core/src/vcs/util.rs