Skip to content

Commit f518970

Browse files
authored
Fix clippy pedantic warnings across workspace (#94)
1 parent 8a3aa0b commit f518970

15 files changed

Lines changed: 374 additions & 175 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
changeset-operations: major
3+
---
4+
AddOperation::execute() now takes &AddInput instead of owned AddInput.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
changeset-project: none
3+
cargo-changeset: none
4+
---
5+
Internal refactoring to resolve clippy pedantic warnings with no user-visible changes.

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ authors = ["Lukas Wagner <appdev.lukaswagner@gmail.com>"]
1212

1313
[workspace.lints.clippy]
1414
pedantic = { level = "warn", priority = -1 }
15-
needless_pass_by_value = "allow" # needed for Bevy systems
16-
type_complexity = "allow" # Some bevy types are just complex. We do not care about that. Clippy's type complexity metric is too strict
17-
struct_excessive_bools = "allow" # CLI input structs map directly to command-line flags
1815
unwrap_used = "deny"
1916

2017
[workspace.metadata]

crates/cargo-changeset/src/commands/add.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ pub(super) fn run(args: AddArgs, start_path: &Path) -> Result<()> {
3434
let result = if is_interactive() {
3535
let interaction_provider = TerminalInteractionProvider::new(args.editor);
3636
let operation = AddOperation::new(project_provider, changeset_writer, interaction_provider);
37-
operation.execute(start_path, input)?
37+
operation.execute(start_path, &input)?
3838
} else {
3939
let interaction_provider = NonInteractiveProvider;
4040
let operation = AddOperation::new(project_provider, changeset_writer, interaction_provider);
41-
operation.execute(start_path, input)?
41+
operation.execute(start_path, &input)?
4242
};
4343

4444
match result {

crates/changeset-operations/src/mocks.rs

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl DependencyGraphProvider for MockProjectProvider {
170170
.map(|p| p.name().clone())
171171
.collect();
172172
Ok(WorkspaceDependencyGraph::from_edges(
173-
member_names,
173+
&member_names,
174174
&self.dependency_edges,
175175
))
176176
}
@@ -414,18 +414,28 @@ impl ChangesetWriter for MockChangesetWriter {
414414
}
415415
}
416416

417+
#[derive(Clone, Copy)]
418+
enum TagFailMode {
419+
Never,
420+
Always,
421+
OnNth(usize),
422+
}
423+
424+
struct MockFailureFlags {
425+
commit: bool,
426+
stage_files: bool,
427+
is_clean: bool,
428+
create_tag: TagFailMode,
429+
}
430+
417431
struct MockGitState {
418432
staged_files: Vec<PathBuf>,
419433
commits: Vec<String>,
420434
tags_created: Vec<(String, String)>,
421435
deleted_files: Vec<PathBuf>,
422436
deleted_tags: Vec<String>,
423437
reset_count: usize,
424-
fail_on_commit: bool,
425-
fail_on_create_tag: bool,
426-
fail_on_create_tag_nth: Option<usize>,
427-
fail_on_stage_files: bool,
428-
fail_on_is_clean: bool,
438+
failure_flags: MockFailureFlags,
429439
}
430440

431441
pub struct MockGitProvider {
@@ -453,11 +463,12 @@ impl MockGitProvider {
453463
deleted_files: Vec::new(),
454464
deleted_tags: Vec::new(),
455465
reset_count: 0,
456-
fail_on_commit: false,
457-
fail_on_create_tag: false,
458-
fail_on_create_tag_nth: None,
459-
fail_on_stage_files: false,
460-
fail_on_is_clean: false,
466+
failure_flags: MockFailureFlags {
467+
commit: false,
468+
stage_files: false,
469+
is_clean: false,
470+
create_tag: TagFailMode::Never,
471+
},
461472
}),
462473
}
463474
}
@@ -539,29 +550,47 @@ impl MockGitProvider {
539550
}
540551

541552
pub fn set_fail_on_commit(&self, fail: bool) {
542-
self.state.lock().expect("lock poisoned").fail_on_commit = fail;
553+
self.state
554+
.lock()
555+
.expect("lock poisoned")
556+
.failure_flags
557+
.commit = fail;
543558
}
544559

545560
pub fn set_fail_on_create_tag(&self, fail: bool) {
546-
self.state.lock().expect("lock poisoned").fail_on_create_tag = fail;
561+
self.state
562+
.lock()
563+
.expect("lock poisoned")
564+
.failure_flags
565+
.create_tag = if fail {
566+
TagFailMode::Always
567+
} else {
568+
TagFailMode::Never
569+
};
547570
}
548571

549572
pub fn set_fail_on_create_tag_nth(&self, n: usize) {
550573
self.state
551574
.lock()
552575
.expect("lock poisoned")
553-
.fail_on_create_tag_nth = Some(n);
576+
.failure_flags
577+
.create_tag = TagFailMode::OnNth(n);
554578
}
555579

556580
pub fn set_fail_on_stage_files(&self, fail: bool) {
557581
self.state
558582
.lock()
559583
.expect("lock poisoned")
560-
.fail_on_stage_files = fail;
584+
.failure_flags
585+
.stage_files = fail;
561586
}
562587

563588
pub fn set_fail_on_is_clean(&self, fail: bool) {
564-
self.state.lock().expect("lock poisoned").fail_on_is_clean = fail;
589+
self.state
590+
.lock()
591+
.expect("lock poisoned")
592+
.failure_flags
593+
.is_clean = fail;
565594
}
566595
}
567596

@@ -590,7 +619,13 @@ impl GitWorkdirDiffProvider for MockGitProvider {
590619

591620
impl GitStatusProvider for MockGitProvider {
592621
fn is_working_tree_clean(&self, _project_root: &Path) -> Result<bool> {
593-
if self.state.lock().expect("lock poisoned").fail_on_is_clean {
622+
if self
623+
.state
624+
.lock()
625+
.expect("lock poisoned")
626+
.failure_flags
627+
.is_clean
628+
{
594629
return Err(crate::OperationError::Io(std::io::Error::other(
595630
"mock is_working_tree_clean failure",
596631
)));
@@ -610,7 +645,7 @@ impl GitStatusProvider for MockGitProvider {
610645
impl GitStagingProvider for MockGitProvider {
611646
fn stage_files(&self, _project_root: &Path, paths: &[&Path]) -> Result<()> {
612647
let mut state = self.state.lock().expect("lock poisoned");
613-
if state.fail_on_stage_files {
648+
if state.failure_flags.stage_files {
614649
return Err(crate::OperationError::Io(std::io::Error::other(
615650
"mock stage files failure",
616651
)));
@@ -634,7 +669,7 @@ impl GitStagingProvider for MockGitProvider {
634669
impl GitCommitProvider for MockGitProvider {
635670
fn commit(&self, _project_root: &Path, message: &str) -> Result<CommitInfo> {
636671
let mut state = self.state.lock().expect("lock poisoned");
637-
if state.fail_on_commit {
672+
if state.failure_flags.commit {
638673
return Err(crate::OperationError::Io(std::io::Error::other(
639674
"mock commit failure",
640675
)));
@@ -655,21 +690,16 @@ impl GitCommitProvider for MockGitProvider {
655690
impl GitTagProvider for MockGitProvider {
656691
fn create_tag(&self, _project_root: &Path, tag_name: &str, message: &str) -> Result<TagInfo> {
657692
let mut state = self.state.lock().expect("lock poisoned");
658-
if state.fail_on_create_tag {
693+
let should_fail = match state.failure_flags.create_tag {
694+
TagFailMode::Never => false,
695+
TagFailMode::Always => true,
696+
TagFailMode::OnNth(n) => state.tags_created.len() == n,
697+
};
698+
if should_fail {
659699
return Err(crate::OperationError::Io(std::io::Error::other(
660700
"mock create tag failure",
661701
)));
662702
}
663-
664-
let current_count = state.tags_created.len();
665-
if let Some(n) = state.fail_on_create_tag_nth {
666-
if current_count == n {
667-
return Err(crate::OperationError::Io(std::io::Error::other(
668-
"mock create tag failure (nth)",
669-
)));
670-
}
671-
}
672-
673703
state
674704
.tags_created
675705
.push((tag_name.to_string(), message.to_string()));

crates/changeset-operations/src/operations/add.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
///
6969
/// Returns an error if the project cannot be discovered, has no packages, or
7070
/// if the changeset cannot be written.
71-
pub fn execute(&self, start_path: &Path, input: AddInput) -> Result<AddResult> {
71+
pub fn execute(&self, start_path: &Path, input: &AddInput) -> Result<AddResult> {
7272
let project = self.project_provider.discover_project(start_path)?;
7373

7474
if project.packages().is_empty() {
@@ -104,7 +104,7 @@ where
104104
});
105105

106106
let packages =
107-
match self.select_packages(project.packages(), &input, display_labels.as_deref())? {
107+
match self.select_packages(project.packages(), input, display_labels.as_deref())? {
108108
Some(packages) if packages.is_empty() => return Ok(AddResult::NoPackages),
109109
Some(packages) => packages,
110110
None => return Ok(AddResult::Cancelled),
@@ -120,15 +120,15 @@ where
120120
Vec::new()
121121
};
122122

123-
let Some(releases) = self.collect_releases(&packages, &input)? else {
123+
let Some(releases) = self.collect_releases(&packages, input)? else {
124124
return Ok(AddResult::Cancelled);
125125
};
126126

127-
let Some(category) = self.select_category(&input)? else {
127+
let Some(category) = self.select_category(input)? else {
128128
return Ok(AddResult::Cancelled);
129129
};
130130

131-
let Some(desc) = self.get_description(&input)? else {
131+
let Some(desc) = self.get_description(input)? else {
132132
return Ok(AddResult::Cancelled);
133133
};
134134

@@ -354,7 +354,7 @@ mod tests {
354354
};
355355

356356
let result = operation
357-
.execute(Path::new("/any"), input)
357+
.execute(Path::new("/any"), &input)
358358
.expect("AddOperation failed with valid single-package input");
359359

360360
match result {
@@ -393,7 +393,7 @@ mod tests {
393393
};
394394

395395
let result = operation
396-
.execute(Path::new("/any"), input)
396+
.execute(Path::new("/any"), &input)
397397
.expect("AddOperation failed with valid multi-package input");
398398

399399
match result {
@@ -420,7 +420,7 @@ mod tests {
420420
let operation = AddOperation::new(project_provider, writer, interaction);
421421

422422
let result = operation
423-
.execute(Path::new("/any"), AddInput::default())
423+
.execute(Path::new("/any"), &AddInput::default())
424424
.expect("AddOperation should not fail when interaction is cancelled");
425425

426426
assert!(matches!(result, AddResult::Cancelled));
@@ -441,7 +441,7 @@ mod tests {
441441
let operation = AddOperation::new(project_provider, writer, interaction);
442442

443443
let result = operation
444-
.execute(Path::new("/any"), AddInput::default())
444+
.execute(Path::new("/any"), &AddInput::default())
445445
.expect("AddOperation should not fail when bump selection is cancelled");
446446

447447
assert!(matches!(result, AddResult::Cancelled));
@@ -462,7 +462,7 @@ mod tests {
462462
..Default::default()
463463
};
464464

465-
let result = operation.execute(Path::new("/any"), input);
465+
let result = operation.execute(Path::new("/any"), &input);
466466

467467
assert!(result.is_err());
468468
let err = result.expect_err("AddOperation should fail for unknown package");
@@ -484,7 +484,7 @@ mod tests {
484484
..Default::default()
485485
};
486486

487-
let result = operation.execute(Path::new("/any"), input);
487+
let result = operation.execute(Path::new("/any"), &input);
488488

489489
assert!(result.is_err());
490490
let err = result.expect_err("AddOperation should fail for empty description");
@@ -507,7 +507,7 @@ mod tests {
507507
let operation = AddOperation::new(project_provider, writer, interaction);
508508

509509
let result = operation
510-
.execute(Path::new("/any"), AddInput::default())
510+
.execute(Path::new("/any"), &AddInput::default())
511511
.expect("AddOperation failed with interactive workspace selection");
512512

513513
match result {
@@ -538,7 +538,7 @@ mod tests {
538538
};
539539

540540
let result = operation
541-
.execute(Path::new("/any"), input)
541+
.execute(Path::new("/any"), &input)
542542
.expect("AddOperation failed for single-package auto-selection");
543543

544544
match result {
@@ -568,7 +568,7 @@ mod tests {
568568
};
569569

570570
let result = operation
571-
.execute(Path::new("/any"), input)
571+
.execute(Path::new("/any"), &input)
572572
.expect("AddOperation failed with explicit category");
573573

574574
match result {
@@ -595,7 +595,7 @@ mod tests {
595595
};
596596

597597
let result = operation
598-
.execute(Path::new("/any"), input)
598+
.execute(Path::new("/any"), &input)
599599
.expect("AddOperation failed to create changeset file");
600600

601601
match result {
@@ -621,7 +621,7 @@ mod tests {
621621
..Default::default()
622622
};
623623

624-
let result = operation.execute(Path::new("/any"), input);
624+
let result = operation.execute(Path::new("/any"), &input);
625625

626626
assert!(result.is_err());
627627
let err = result.expect_err("AddOperation should fail for none bump without description");
@@ -644,7 +644,7 @@ mod tests {
644644
};
645645

646646
let result = operation
647-
.execute(Path::new("/any"), input)
647+
.execute(Path::new("/any"), &input)
648648
.expect("AddOperation should succeed for none bump with description");
649649

650650
match result {
@@ -677,7 +677,7 @@ mod tests {
677677
};
678678

679679
let result = operation
680-
.execute(Path::new("/any"), input)
680+
.execute(Path::new("/any"), &input)
681681
.expect("AddOperation should succeed with interactive description for none bump");
682682

683683
match result {
@@ -710,7 +710,7 @@ mod tests {
710710
};
711711

712712
let result = operation
713-
.execute(Path::new("/any"), input)
713+
.execute(Path::new("/any"), &input)
714714
.expect("AddOperation should succeed for mixed none/patch bumps with description");
715715

716716
match result {
@@ -756,7 +756,7 @@ mod tests {
756756
};
757757

758758
let result = operation
759-
.execute(Path::new("/any"), input)
759+
.execute(Path::new("/any"), &input)
760760
.expect("AddOperation should succeed with exclude_dependents");
761761

762762
match result {
@@ -791,7 +791,7 @@ mod tests {
791791
};
792792

793793
let result = operation
794-
.execute(Path::new("/any"), input)
794+
.execute(Path::new("/any"), &input)
795795
.expect("AddOperation should succeed and report uncovered dependents");
796796

797797
match result {
@@ -823,7 +823,7 @@ mod tests {
823823
};
824824

825825
let result = operation
826-
.execute(Path::new("/any"), input)
826+
.execute(Path::new("/any"), &input)
827827
.expect("AddOperation should succeed for single-package project");
828828

829829
match result {

0 commit comments

Comments
 (0)