Skip to content

Commit 2e8cea3

Browse files
committed
fix: clean up code and improve clippy lints and formatting consistency
1 parent 29d68a0 commit 2e8cea3

File tree

20 files changed

+79
-73
lines changed

20 files changed

+79
-73
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"rust-analyzer.cargo.features": "all"
2+
"rust-analyzer.cargo.features": []
33
}

src/bin/cargo_uv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() -> Result<()> {
1010
setup_tracing(&cli_args)?;
1111

1212
let packages = Packages::from(cli_args.get_metadata()?);
13-
let mut tasks = Tasks::generate_tasks(&mut cli_args, packages)?;
13+
let mut tasks = Tasks::generate_tasks(&cli_args, packages)?;
1414

1515
tasks = tasks.run_all(&cli_args)?.join_all()?;
1616
tracing::info!("Completed run, starting cleanup");

src/cli/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod action;
2+
#[allow(clippy::module_inception)]
23
mod cli;
34
mod git_ops;
45
mod manifest;

src/cli/workspace.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::HashSet;
55

66
use tracing::{instrument, trace};
77

8-
use crate::{Package, PackageName, Packages, ReadToml, Result, cli::WORKSPACE_HEADER};
8+
use crate::{Package, PackageName, Packages, ReadToml, Result, SplitVec, cli::WORKSPACE_HEADER};
99

1010
/// Cargo flags for selecting crates in a workspace.
1111
#[derive(Default, Clone, Debug, PartialEq, Eq, clap::Args)]
@@ -43,7 +43,7 @@ impl Workspace {
4343
pub fn partition_packages<'m>(
4444
&self,
4545
packages: &'m Packages,
46-
) -> Result<(Vec<&'m Package<ReadToml>>, Vec<&'m Package<ReadToml>>)> {
46+
) -> Result<SplitVec<&'m Package<ReadToml>>> {
4747
let selection = PackagesCli::from_flags(
4848
self.workspace,
4949
self.default_members,
@@ -74,7 +74,7 @@ impl Workspace {
7474
pub fn partition_packages_owned(
7575
&self,
7676
packages: &Packages,
77-
) -> Result<(Vec<Package<ReadToml>>, Vec<Package<ReadToml>>)> {
77+
) -> Result<SplitVec<Package<ReadToml>>> {
7878
self.partition_packages(packages).map(|(i, e)| {
7979
(
8080
i.into_iter().cloned().collect(),
@@ -86,10 +86,7 @@ impl Workspace {
8686
pub fn partition_packages_mut<'m>(
8787
&self,
8888
packages: &'m mut Packages,
89-
) -> Result<(
90-
Vec<&'m mut Package<ReadToml>>,
91-
Vec<&'m mut Package<ReadToml>>,
92-
)> {
89+
) -> Result<SplitVec<&'m mut Package<ReadToml>>> {
9390
let packages_clone = packages.clone();
9491
let selection = PackagesCli::from_flags(
9592
self.workspace,

src/git/branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Display for Branch {
5858
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5959
let text = match self {
6060
Branch::Current => ".",
61-
Branch::Named { local, .. } => &local,
61+
Branch::Named { local, .. } => local,
6262
};
6363

6464
write!(f, "{text}")

src/git/git.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::{
66
};
77

88
use indexmap::IndexSet;
9-
use miette::{Context, bail};
9+
use miette::bail;
1010
use semver::Version;
1111
use tracing::{debug, info, instrument, warn};
1212

13+
#[cfg(feature = "unstable")]
14+
use miette::Context;
15+
1316
use crate::{
14-
Branch, Process, ProcessOutput, Result, Task,
15-
cli::{Cli, Suppress},
16-
current_span,
17-
git::git_file::GitFiles,
17+
Branch, Process, ProcessOutput, Result, cli::Suppress, current_span, git::git_file::GitFiles,
1818
process::OutputExt,
1919
};
2020

@@ -172,7 +172,7 @@ impl Git<PathBuf> {
172172
git.arg("--dry-run");
173173
}
174174

175-
git.args(["--message", &message]);
175+
git.args(["--message", message]);
176176
let cmd = Process::display_command(&git);
177177
let run = Process::Output.run(git)?;
178178
let output = run.as_output().unwrap();

src/git/git_file.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{path::PathBuf, str::FromStr, vec::IntoIter};
22

33
use tracing::instrument;
44

5-
#[allow(dead_code)]
65
#[derive(Debug, Clone)]
76
pub struct GitFile {
87
pub mode: String,

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use tracing_subscriber::util::SubscriberInitExt;
3232
/// Footer for the [miette::MietteHandler]
3333
pub static FOOTER: &str = "If the bug continues, raise an issue on github: https://github.com/Ozy-Viking/cargo_update_version/issues";
3434

35+
pub type SplitVec<T> = (Vec<T>, Vec<T>);
36+
3537
pub fn setup_tracing(args: &Cli) -> miette::Result<()> {
3638
let app_level = match args.tracing_level() {
3739
Some(l) => l,

src/manifest/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl Display for CargoFileError {
3030
}
3131
}
3232

33-
// #[allow(dead_code)]
3433
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
3534
pub enum CargoFileErrorKind {
3635
#[error("No root package")]

src/manifest/toml_file.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,43 +110,46 @@ impl CargoFile<ReadToml> {
110110
}
111111
#[instrument(skip_all)]
112112
pub fn get_package_version(&self) -> Option<Version> {
113-
VersionLocation::Package.get_version(&self).ok()
113+
VersionLocation::Package.get_version(self).ok()
114114
}
115115
#[instrument(skip_all)]
116116
pub fn get_workspace_version(&self) -> Option<Version> {
117-
VersionLocation::WorkspacePackage.get_version(&self).ok()
117+
VersionLocation::WorkspacePackage.get_version(self).ok()
118118
}
119119

120120
#[track_caller]
121121
#[instrument(skip(self))]
122+
#[allow(clippy::result_large_err)]
122123
pub fn set_package_version(
123124
&mut self,
124125
new_version: &Version,
125126
) -> miette::Result<(), CargoFileError> {
126127
VersionLocation::Package
127128
.set_version(self, new_version)
128129
.map_err(|e: VersionlocationError| {
129-
let path = (&e).path().to_path_buf();
130+
let path = e.path().to_path_buf();
130131
CargoFileErrorKind::LocationError(e).to_error(path)
131132
})
132133
}
133134

134135
#[track_caller]
135136
#[instrument(skip(self))]
137+
#[allow(clippy::result_large_err)]
136138
pub fn set_workspace_version(
137139
&mut self,
138140
new_version: &Version,
139141
) -> miette::Result<(), CargoFileError> {
140142
VersionLocation::WorkspacePackage
141143
.set_version(self, new_version)
142144
.map_err(|e: VersionlocationError| {
143-
let path = (&e).path().to_path_buf();
145+
let path = e.path().to_path_buf();
144146
CargoFileErrorKind::LocationError(e).to_error(path)
145147
})
146148
}
147149

148150
#[track_caller]
149151
#[instrument(skip(self))]
152+
#[allow(clippy::result_large_err)]
150153
pub fn set_version(&mut self, new_version: Version) -> miette::Result<(), CargoFileError> {
151154
tracing::warn!("set version start");
152155
let cargo_path = self.path().to_path_buf();

0 commit comments

Comments
 (0)