Skip to content

Commit 722a712

Browse files
committed
fix(pacquet): satisfy Perfectionist dylint lints on git-resolver port
CI's `just ready` doesn't surface Perfectionist (it runs only as a dedicated dylint job on a nightly toolchain). Fixes: * Rename single-letter generics `P`/`R` → `Probe`/`Runner` on `GitResolver`, `PartialSpec::finalize`, `from_hosted_git`, and `resolve_ref`. * Rename single-letter closure / function / let-binding params (`s`/`h`/`c`/`p`/`i`/`g`/...) to descriptive names. * Replace Unicode ellipsis (`…`, U+2026) with ASCII `...` in comments. * Add trailing commas to multi-line `assert_eq!` / `assert!` invocations, and remove the stray trailing comma on a single-line one. Also fix follow-on JSR-resolver test cases that still read `result.id.{name,suffix}`: switch them to `result.name_ver.as_ref()...` to match the post-widening `ResolveResult` shape. --- Written by an agent (Claude Code, claude-opus-4-7).
1 parent bd65fc2 commit 722a712

6 files changed

Lines changed: 111 additions & 97 deletions

File tree

pacquet/crates/resolving-git-resolver/src/create_git_hosted_pkg_id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod tests {
4040
"cba04669e621b85fbdb33371604de1a2898e68e9",
4141
None,
4242
),
43-
"git+ssh://[email protected]/org/repo.git#cba04669e621b85fbdb33371604de1a2898e68e9"
43+
"git+ssh://[email protected]/org/repo.git#cba04669e621b85fbdb33371604de1a2898e68e9",
4444
);
4545
}
4646

@@ -52,7 +52,7 @@ mod tests {
5252
"0000000000000000000000000000000000000000",
5353
None,
5454
),
55-
"git+https://0000000000000000000000000000000000000000:[email protected]/foo/bar.git#0000000000000000000000000000000000000000"
55+
"git+https://0000000000000000000000000000000000000000:[email protected]/foo/bar.git#0000000000000000000000000000000000000000",
5656
);
5757
}
5858

@@ -64,7 +64,7 @@ mod tests {
6464
"988c61e11dc8d9ca0b5580cb15291951812549dc",
6565
None,
6666
),
67-
"git+file:///Users/zoltan/src/pnpm/pnpm/resolving/git-resolver#988c61e11dc8d9ca0b5580cb15291951812549dc"
67+
"git+file:///Users/zoltan/src/pnpm/pnpm/resolving/git-resolver#988c61e11dc8d9ca0b5580cb15291951812549dc",
6868
);
6969
}
7070

@@ -76,7 +76,7 @@ mod tests {
7676
"0000000000000000000000000000000000000000",
7777
None,
7878
),
79-
"git+https://github.com/foo/bar.git#0000000000000000000000000000000000000000"
79+
"git+https://github.com/foo/bar.git#0000000000000000000000000000000000000000",
8080
);
8181
}
8282

@@ -88,7 +88,7 @@ mod tests {
8888
"0000000000000000000000000000000000000000",
8989
Some("/packages/sub"),
9090
),
91-
"git+https://github.com/foo/bar.git#0000000000000000000000000000000000000000&path:/packages/sub"
91+
"git+https://github.com/foo/bar.git#0000000000000000000000000000000000000000&path:/packages/sub",
9292
);
9393
}
9494
}

pacquet/crates/resolving-git-resolver/src/git_resolver.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ use crate::{
2727
/// `Arc` so the resolver can be cloned into the default-resolver
2828
/// chain without forcing the runners (whose ownership lives on the
2929
/// install dispatcher) into a single owner.
30-
pub struct GitResolver<P: GitProbe + 'static, R: GitCommandRunner + 'static> {
31-
probe: Arc<P>,
32-
runner: Arc<R>,
30+
pub struct GitResolver<Probe: GitProbe + 'static, Runner: GitCommandRunner + 'static> {
31+
probe: Arc<Probe>,
32+
runner: Arc<Runner>,
3333
}
3434

35-
impl<P: GitProbe + 'static, R: GitCommandRunner + 'static> GitResolver<P, R> {
36-
pub fn new(probe: Arc<P>, runner: Arc<R>) -> Self {
35+
impl<Probe: GitProbe + 'static, Runner: GitCommandRunner + 'static> GitResolver<Probe, Runner> {
36+
pub fn new(probe: Arc<Probe>, runner: Arc<Runner>) -> Self {
3737
Self { probe, runner }
3838
}
3939
}
4040

41-
impl<P: GitProbe + 'static, R: GitCommandRunner + 'static> Resolver for GitResolver<P, R> {
41+
impl<Probe: GitProbe + 'static, Runner: GitCommandRunner + 'static> Resolver
42+
for GitResolver<Probe, Runner>
43+
{
4244
fn resolve<'a>(
4345
&'a self,
4446
wanted_dependency: &'a WantedDependency,
@@ -56,7 +58,7 @@ impl<P: GitProbe + 'static, R: GitCommandRunner + 'static> Resolver for GitResol
5658
}
5759
}
5860

59-
impl<P: GitProbe + 'static, R: GitCommandRunner + 'static> GitResolver<P, R> {
61+
impl<Probe: GitProbe + 'static, Runner: GitCommandRunner + 'static> GitResolver<Probe, Runner> {
6062
async fn resolve_impl(
6163
&self,
6264
wanted_dependency: &WantedDependency,
@@ -93,13 +95,13 @@ impl<P: GitProbe + 'static, R: GitCommandRunner + 'static> GitResolver<P, R> {
9395
}
9496
}
9597

96-
async fn build_resolve_result<R: GitCommandRunner + ?Sized>(
98+
async fn build_resolve_result<Runner: GitCommandRunner + ?Sized>(
9799
spec: HostedPackageSpec,
98-
runner: &R,
100+
runner: &Runner,
99101
alias: Option<&str>,
100102
) -> Result<ResolveResult, ResolveError> {
101103
let ref_for_ls_remote = match spec.git_committish.as_deref() {
102-
Some(c) if !c.is_empty() => c,
104+
Some(committish) if !committish.is_empty() => committish,
103105
_ => "HEAD",
104106
};
105107
let commit =
@@ -249,7 +251,7 @@ mod tests {
249251
LockfileResolution::Tarball(t) => {
250252
assert_eq!(
251253
t.tarball,
252-
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99"
254+
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99",
253255
);
254256
assert_eq!(t.git_hosted, Some(true));
255257
assert!(t.path.is_none());
@@ -258,11 +260,11 @@ mod tests {
258260
}
259261
assert_eq!(
260262
result.id.as_str(),
261-
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99"
263+
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99",
262264
);
263265
assert_eq!(
264266
result.normalized_bare_specifier.as_deref(),
265-
Some("github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99")
267+
Some("github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99"),
266268
);
267269
}
268270

pacquet/crates/resolving-git-resolver/src/hosted_git.rs

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl HostedGit {
169169
};
170170

171171
let parsed = parse_git_url(normalised)?;
172-
// Look up host: shortcut first (so `github://` wins over the
172+
// Look up host: shortcut first (so `github://...` wins over the
173173
// host's full URL parsing), then by domain.
174174
let shortcut_type = HostedGitType::from_shortcut(&parsed.scheme);
175175
let domain_type = parsed.host.as_deref().and_then(HostedGitType::from_domain);
@@ -211,8 +211,8 @@ impl HostedGit {
211211
let committish = parsed
212212
.hash
213213
.as_ref()
214-
.map(|h| percent_decode(h.strip_prefix('#').unwrap_or(h)))
215-
.filter(|c| !c.is_empty());
214+
.map(|hash| percent_decode(hash.strip_prefix('#').unwrap_or(hash)))
215+
.filter(|committish| !committish.is_empty());
216216
let user = user.unwrap_or_default();
217217
(user, project, committish, Representation::Shortcut)
218218
} else {
@@ -222,8 +222,10 @@ impl HostedGit {
222222
let segments = extract_for_host(host_type, &parsed)?;
223223
let user = percent_decode(&segments.user);
224224
let project = percent_decode(&segments.project);
225-
let committish =
226-
segments.committish.map(|c| percent_decode(&c)).filter(|c| !c.is_empty());
225+
let committish = segments
226+
.committish
227+
.map(|raw| percent_decode(&raw))
228+
.filter(|decoded| !decoded.is_empty());
227229
let representation = protocol_to_representation(&parsed.scheme);
228230
(user, project, committish, representation)
229231
};
@@ -386,8 +388,8 @@ fn protocol_to_representation(protocol: &str) -> Representation {
386388
}
387389
}
388390

389-
fn strip_dot_git(s: &str) -> String {
390-
s.strip_suffix(".git").unwrap_or(s).to_string()
391+
fn strip_dot_git(project: &str) -> String {
392+
project.strip_suffix(".git").unwrap_or(project).to_string()
391393
}
392394

393395
struct ParsedUrl {
@@ -505,9 +507,10 @@ fn is_github_shorthand(arg: &str) -> bool {
505507
}
506508
let first_hash = arg.find('#');
507509
let first_slash = arg.find('/');
508-
let second_slash = first_slash.and_then(|s| arg[s + 1..].find('/').map(|p| s + 1 + p));
510+
let second_slash =
511+
first_slash.and_then(|first| arg[first + 1..].find('/').map(|rest| first + 1 + rest));
509512
let first_colon = arg.find(':');
510-
let first_space = arg.find(|c: char| c.is_whitespace());
513+
let first_space = arg.find(|ch: char| ch.is_whitespace());
511514
let first_at = arg.find('@');
512515

513516
let space_only_after_hash = first_space.is_none()
@@ -518,9 +521,9 @@ fn is_github_shorthand(arg: &str) -> bool {
518521
|| (first_hash.is_some() && first_colon.unwrap() > first_hash.unwrap());
519522
let second_slash_only_after_hash = second_slash.is_none()
520523
|| (first_hash.is_some() && second_slash.unwrap() > first_hash.unwrap());
521-
let has_slash = first_slash.is_some_and(|s| s > 0);
524+
let has_slash = first_slash.is_some_and(|first| first > 0);
522525
let does_not_end_with_slash = match first_hash {
523-
Some(h) if h > 0 => arg.as_bytes()[h - 1] != b'/',
526+
Some(hash) if hash > 0 => arg.as_bytes()[hash - 1] != b'/',
524527
_ => !arg.ends_with('/'),
525528
};
526529
let does_not_start_with_dot = !arg.starts_with('.');
@@ -564,7 +567,8 @@ fn extract_github(parsed: &ParsedUrl) -> Option<Segments> {
564567
}
565568

566569
if r#type.is_none() {
567-
committish = parsed.hash.as_deref().map(|h| h.strip_prefix('#').unwrap_or(h).to_string());
570+
committish =
571+
parsed.hash.as_deref().map(|hash| hash.strip_prefix('#').unwrap_or(hash).to_string());
568572
}
569573

570574
if project.ends_with(".git") {
@@ -598,8 +602,8 @@ fn extract_bitbucket(parsed: &ParsedUrl) -> Option<Segments> {
598602
let committish = parsed
599603
.hash
600604
.as_deref()
601-
.map(|h| h.strip_prefix('#').unwrap_or(h).to_string())
602-
.filter(|s| !s.is_empty());
605+
.map(|hash| hash.strip_prefix('#').unwrap_or(hash).to_string())
606+
.filter(|committish| !committish.is_empty());
603607
Some(Segments { user, project, committish })
604608
}
605609

@@ -621,8 +625,8 @@ fn extract_gitlab(parsed: &ParsedUrl) -> Option<Segments> {
621625
let committish = parsed
622626
.hash
623627
.as_deref()
624-
.map(|h| h.strip_prefix('#').unwrap_or(h).to_string())
625-
.filter(|s| !s.is_empty());
628+
.map(|hash| hash.strip_prefix('#').unwrap_or(hash).to_string())
629+
.filter(|committish| !committish.is_empty());
626630
Some(Segments { user, project, committish })
627631
}
628632

@@ -632,32 +636,32 @@ fn extract_gitlab(parsed: &ParsedUrl) -> Option<Segments> {
632636
/// returning `None` at the call site). Pacquet keeps the input as-is on
633637
/// malformed input — the affected URLs are caught elsewhere when the
634638
/// downstream parse fails.
635-
fn percent_decode(s: &str) -> String {
636-
let mut out = String::with_capacity(s.len());
637-
let bytes = s.as_bytes();
638-
let mut i = 0;
639-
while i < bytes.len() {
640-
if bytes[i] == b'%'
641-
&& i + 2 < bytes.len()
639+
fn percent_decode(input: &str) -> String {
640+
let mut out = String::with_capacity(input.len());
641+
let bytes = input.as_bytes();
642+
let mut idx = 0;
643+
while idx < bytes.len() {
644+
if bytes[idx] == b'%'
645+
&& idx + 2 < bytes.len()
642646
&& let (Some(hi), Some(lo)) =
643-
((bytes[i + 1] as char).to_digit(16), (bytes[i + 2] as char).to_digit(16))
647+
((bytes[idx + 1] as char).to_digit(16), (bytes[idx + 2] as char).to_digit(16))
644648
{
645649
out.push((hi * 16 + lo) as u8 as char);
646-
i += 3;
650+
idx += 3;
647651
continue;
648652
}
649-
out.push(bytes[i] as char);
650-
i += 1;
653+
out.push(bytes[idx] as char);
654+
idx += 1;
651655
}
652656
out
653657
}
654658

655659
/// Match Node's `encodeURIComponent`. Percent-encode every byte
656660
/// outside the safe ASCII set Node keeps unencoded:
657661
/// `A-Z a-z 0-9 - _ . ! ~ * ' ( )`.
658-
fn encode_uri_component(s: &str) -> String {
659-
let mut out = String::with_capacity(s.len());
660-
for byte in s.bytes() {
662+
fn encode_uri_component(input: &str) -> String {
663+
let mut out = String::with_capacity(input.len());
664+
for byte in input.bytes() {
661665
let safe = byte.is_ascii_alphanumeric()
662666
|| matches!(byte, b'-' | b'_' | b'.' | b'!' | b'~' | b'*' | b'\'' | b'(' | b')');
663667
if safe {
@@ -745,7 +749,7 @@ mod tests {
745749
fn rejects_non_hosted() {
746750
// Gitea / generic .git URLs are not recognised by hosted-git-info.
747751
assert!(
748-
HostedGit::from_url("https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git").is_none()
752+
HostedGit::from_url("https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git").is_none(),
749753
);
750754
}
751755

@@ -767,7 +771,7 @@ mod tests {
767771
.expect("ok");
768772
assert_eq!(
769773
h.shortcut(HostedOpts::default()),
770-
"github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99"
774+
"github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99",
771775
);
772776
assert_eq!(h.shortcut(HostedGit::no_committish()), "github:zkochan/is-negative");
773777
}
@@ -777,11 +781,11 @@ mod tests {
777781
let h = HostedGit::from_url("zkochan/is-negative").expect("ok");
778782
assert_eq!(
779783
h.https(HostedOpts::default()).unwrap(),
780-
"git+https://github.com/zkochan/is-negative.git"
784+
"git+https://github.com/zkochan/is-negative.git",
781785
);
782786
assert_eq!(
783787
h.https(HostedGit::no_committish_no_git_plus()).unwrap(),
784-
"https://github.com/zkochan/is-negative.git"
788+
"https://github.com/zkochan/is-negative.git",
785789
);
786790
}
787791

@@ -791,11 +795,11 @@ mod tests {
791795
assert_eq!(h.ssh(HostedOpts::default()).unwrap(), "[email protected]:foo/bar.git");
792796
assert_eq!(
793797
h.sshurl(HostedOpts::default()).unwrap(),
794-
"git+ssh://[email protected]/foo/bar.git"
798+
"git+ssh://[email protected]/foo/bar.git",
795799
);
796800
assert_eq!(
797801
h.sshurl(HostedGit::no_committish()).unwrap(),
798-
"git+ssh://[email protected]/foo/bar.git"
802+
"git+ssh://[email protected]/foo/bar.git",
799803
);
800804
}
801805

@@ -805,7 +809,7 @@ mod tests {
805809
h.committish = Some("163360a8d3ae6bee9524541043197ff356f8ed99".to_string());
806810
assert_eq!(
807811
h.tarball(HostedOpts::default()).unwrap(),
808-
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99"
812+
"https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99",
809813
);
810814
}
811815

@@ -815,7 +819,7 @@ mod tests {
815819
h.committish = Some("abc123".to_string());
816820
assert_eq!(
817821
h.tarball(HostedOpts::default()).unwrap(),
818-
"https://bitbucket.org/foo/bar/get/abc123.tar.gz"
822+
"https://bitbucket.org/foo/bar/get/abc123.tar.gz",
819823
);
820824
}
821825

@@ -830,7 +834,7 @@ mod tests {
830834
assert!(!tarball.contains("%2F"), "tarball must not contain `%2F`: {tarball}");
831835
assert_eq!(
832836
tarball,
833-
"https://gitlab.com/pnpmjs/git-resolver/-/archive/988c61e11dc8d9ca0b5580cb15291951812549dc/git-resolver-988c61e11dc8d9ca0b5580cb15291951812549dc.tar.gz"
837+
"https://gitlab.com/pnpmjs/git-resolver/-/archive/988c61e11dc8d9ca0b5580cb15291951812549dc/git-resolver-988c61e11dc8d9ca0b5580cb15291951812549dc.tar.gz",
834838
);
835839
}
836840

@@ -845,7 +849,7 @@ mod tests {
845849
let h = HostedGit::from_url("git+https://0000000000000000000000000000000000000000:[email protected]/foo/bar.git").expect("ok");
846850
assert_eq!(
847851
h.https(HostedGit::no_committish_no_git_plus()).unwrap(),
848-
"https://0000000000000000000000000000000000000000:[email protected]/foo/bar.git"
852+
"https://0000000000000000000000000000000000000000:[email protected]/foo/bar.git",
849853
);
850854
assert!(h.auth.is_some());
851855
}

0 commit comments

Comments
 (0)