chore(pacquet/lint): more clippy (#11839)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Khải
2026-05-22 13:48:50 +07:00
committed by GitHub
parent 815e507d67
commit d4136eb6f6
10 changed files with 22 additions and 38 deletions

View File

@@ -146,6 +146,11 @@ allow_branch = "main"
[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(dylint_lib, values("perfectionist"))'] }
[workspace.lints.clippy]
clone_on_ref_ptr = "warn"
if_then_some_else_none = "warn"
unnecessary_lazy_evaluations = "warn"
[profile.release]
opt-level = 3
lto = "fat"

View File

@@ -40,17 +40,11 @@ ignore = [
"params",
]
# Enforce a single canonical ordering inside every `#[derive(...)]`
# attribute. The codebase has ~270 derive sites in 79 distinct
# orderings before this rule; the prefix below encodes the
# conventions that already dominate (Debug first, error-chain
# `Display→Error→Diagnostic` together, supertraits before subtraits,
# serde at the end) and alphabetises everything past the long tail.
# Trait matching is on the final path segment, so `derive_more::Display`
# / `miette::Diagnostic` / `clap::Parser` match `Display` / `Diagnostic`
# / `Parser` respectively.
[perfectionist]
enable = ["derive_ordering"]
disable = [
{ name = "arc_rc_clone", reason = "`arc_rc_clone` is enforced by `clippy::clone_on_ref_ptr` instead" },
]
["perfectionist::derive_ordering"]
style = "prefix_then_alphabetical"

View File

@@ -502,7 +502,7 @@ Do not flatten the tests into a sibling file such as `src/foo_tests.rs`, and do
### Cloning `Arc` and `Rc`
Prefer `Arc::clone(&x)` / `Rc::clone(&x)` over `x.clone()` for reference-counted types. The qualified form makes the O(1) refcount bump visible at the call site and fails to compile if a refactor changes the binding's type to something whose `Clone` is an arbitrarily expensive deep copy. Enforced by [`perfectionist::arc_rc_clone`](https://github.com/KSXGitHub/perfectionist/blob/0.0.0-rc.15/rules/arc_rc_clone.md).
Prefer `Arc::clone(&x)` / `Rc::clone(&x)` over `x.clone()` for reference-counted types. The qualified form makes the O(1) refcount bump visible at the call site and fails to compile if a refactor changes the binding's type to something whose `Clone` is an arbitrarily expensive deep copy. Enforced by [`clippy::clone_on_ref_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr), wired into `[workspace.lints.clippy]` in the root `Cargo.toml`.
### Reading process state

View File

@@ -453,15 +453,13 @@ where
// themselves still get computed inside the `cfg!(windows)` branch
// below — moving the `generate_*` calls there keeps Unix builds
// off the `relative_target_windows` allocation path entirely.
let windows_shims = if cfg!(windows) {
let windows_shims = cfg!(windows).then(|| {
let cmd_path = with_extension_appended(shim_path, "cmd");
let ps1_path = with_extension_appended(shim_path, "ps1");
let cmd_body = generate_cmd_shim(target_path, &cmd_path, runtime.as_ref());
let ps1_body = generate_pwsh_shim(target_path, &ps1_path, runtime.as_ref());
Some((cmd_path, cmd_body, ps1_path, ps1_body))
} else {
None
};
(cmd_path, cmd_body, ps1_path, ps1_body)
});
// Idempotent skip fires only when every flavor that *should* be
// present is present and pointing at the right target. The `.sh`

View File

@@ -294,11 +294,7 @@ async fn read_node_assets_from_mirror(
error: Arc::new(error),
}) as ResolveError
})?;
let prefix = if matches!(archive, BinaryArchive::Zip) {
Some(address.basename.clone())
} else {
None
};
let prefix = matches!(archive, BinaryArchive::Zip).then(|| address.basename.clone());
let binary = BinaryResolution {
url,
integrity,

View File

@@ -164,11 +164,8 @@ pub fn run_postinstall_hooks<Reporter: self::Reporter>(
}
let install_script = get_script("install").map(String::from).or_else(|| {
if get_script("preinstall").is_none() && opts.pkg_root.join("binding.gyp").exists() {
Some("node-gyp rebuild".to_string())
} else {
None
}
(get_script("preinstall").is_none() && opts.pkg_root.join("binding.gyp").exists())
.then(|| "node-gyp rebuild".to_string())
});
if let Some(script) = &install_script
&& script != "npx only-allow pnpm"

View File

@@ -624,16 +624,14 @@ impl<'a> CreateVirtualStore<'a> {
// need to reason across the two branches. Cold-batch
// entries are appended at the bottom of the function once
// the cold-batch fetch finishes.
let mut cas_paths_by_pkg_id: Option<CasPathsByPkgId> = if is_hoisted {
let mut cas_paths_by_pkg_id: Option<CasPathsByPkgId> = is_hoisted.then(|| {
let mut map = CasPathsByPkgId::with_capacity(warm.len());
for (snapshot_key, _snapshot, cas_paths) in &warm {
let pkg_id = PkgIdWithPatchHash::from(snapshot_key.to_string());
map.entry(pkg_id).or_insert_with(|| (***cas_paths).clone());
}
Some(map)
} else {
None
};
map
});
let import_method = config.package_import_method;
if !is_hoisted {

View File

@@ -152,7 +152,7 @@ where
Ok(Some(value))
}
fn visit_bool<Err: de::Error>(self, value: bool) -> Result<Self::Value, Err> {
Ok(if value { Some(String::new()) } else { None })
Ok(value.then(String::new))
}
fn visit_none<Err: de::Error>(self) -> Result<Self::Value, Err> {
Ok(None)

View File

@@ -335,7 +335,7 @@ impl<'tree> Walker<'tree> {
let parent_ref = ParentRef {
version: child_version,
node_id: Some(child_node_id.clone()),
alias: if alias != &child_real_name { Some(alias.clone()) } else { None },
alias: (alias != &child_real_name).then(|| alias.clone()),
};
if alias_relevant {
child_parent_refs.insert(alias.clone(), parent_ref.clone());
@@ -610,7 +610,7 @@ fn insert_parent_ref(
let parent_ref = ParentRef {
version: version.clone(),
node_id: Some(direct.node_id.clone()),
alias: if direct.alias != real_name { Some(direct.alias.clone()) } else { None },
alias: (direct.alias != real_name).then(|| direct.alias.clone()),
};
if alias_relevant {
refs.insert(direct.alias.clone(), parent_ref.clone());

View File

@@ -221,11 +221,7 @@ fn pick_matching_local_version_or_null(
resolve_workspace_range("*", &raw)
}
RegistryPackageSpecType::Version => {
if versions.contains_key(&spec.fetch_spec) {
Some(spec.fetch_spec.clone())
} else {
None
}
versions.contains_key(&spec.fetch_spec).then(|| spec.fetch_spec.clone())
}
RegistryPackageSpecType::Range => {
let raw: Vec<String> = versions.keys().cloned().collect();