Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Oct 31, 2023
1 parent 941600c commit 39d36b4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/autofix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ impl AutoFixer {
Ok(())
}

pub fn lift_dependency(&mut self, dname: &str, default_feats: Option<bool>) -> Result<(), String> {
pub fn lift_dependency(
&mut self,
dname: &str,
default_feats: Option<bool>,
) -> Result<(), String> {
let doc: &mut Document = self.doc.as_mut().unwrap();

for kind in &["dependencies", "dev-dependencies", "build-dependencies"] {
Expand All @@ -471,13 +475,13 @@ impl AutoFixer {
if let Some(as_str) = dep.as_str() {
cargo_metadata::semver::VersionReq::parse(as_str).expect("Is semver");
let mut table = InlineTable::new();
table.remove("default-features");// We also remove it to get the order right.
table.remove("default-features"); // We also remove it to get the order right.

table.insert("workspace", Value::Boolean(Formatted::new(true)));
if let Some(default_feats) = default_feats {
table.insert("default-features", Value::Boolean(Formatted::new(default_feats)));
}

table.set_dotted(false);

*dep = Item::Value(Value::InlineTable(table));
Expand All @@ -486,7 +490,7 @@ impl AutoFixer {
return Err("'git' or 'path' dependency are currently not supported".into())
}
as_table.remove("version");
as_table.remove("default-features");// We also remove it to get the order right.
as_table.remove("default-features"); // We also remove it to get the order right.

as_table.insert("workspace", Value::Boolean(Formatted::new(true)));
if let Some(default_feats) = default_feats {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl DebugCmd {
g.warn_unstable();
let meta = self.cargo_args.load_metadata().expect("Loads metadata");
let dag = build_feature_dag(&meta, &meta.packages);

if !self.no_root {
println!("Root: {}", meta.workspace_root.to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl RunCmd {
if let Some(help) = config.fmt_help() {
println!("\n{}", help);
}

std::process::exit(1);
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/cmd/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{autofix::*, grammar::*, log};

use cargo_metadata::{Dependency as Dep, Package};
use itertools::Itertools;
use semver::{Version, VersionReq, Op};
use semver::{Op, Version, VersionReq};
use std::{
collections::{BTreeMap as Map, HashMap},
fs::canonicalize,
Expand Down Expand Up @@ -99,7 +99,9 @@ impl LiftToWorkspaceCmd {
let str_width = versions.iter().map(|v| v.to_string().len()).max().unwrap();
let mut err = String::new();
// iter by descending frequence
for (version, pkgs) in by_version.iter().sorted_by_key(|(v, pkgs)| (pkgs.len(), v.to_string())).rev() {
for (version, pkgs) in
by_version.iter().sorted_by_key(|(v, pkgs)| (pkgs.len(), v.to_string())).rev()
{
let ddd = if pkgs.len() > 3 { ", …" } else { "" };
let s = plural_or(pkgs.len(), " ");
// TODO plural s
Expand Down Expand Up @@ -163,8 +165,7 @@ impl LiftToWorkspaceCmd {

// Now create fixer for the root package
let root_manifest_path = meta.workspace_root.join("Cargo.toml");
let mut fixer =
AutoFixer::from_manifest(&root_manifest_path.into_std_path_buf()).unwrap();
let mut fixer = AutoFixer::from_manifest(&root_manifest_path.into_std_path_buf()).unwrap();
let dep = by_version.values().next().unwrap().first().unwrap().1.clone();
fixer.add_workspace_dep(&dep, false).unwrap();
fixer.save().unwrap();
Expand All @@ -177,14 +178,14 @@ fn try_find_latest<'a, I: Iterator<Item = &'a VersionReq>>(reqs: I) -> Result<Ve
// Try to convert each to a version. This is done as best-effort:
for req in reqs {
if req.comparators.len() != 1 {
return Err(format!("Invalid version requirement: '{}'", req));
return Err(format!("Invalid version requirement: '{}'", req))
}
let comp = req.comparators.first().unwrap();
if comp.op != Op::Caret {
return Err(format!("Only caret is supported, but got: '{}'", req));
return Err(format!("Only caret is supported, but got: '{}'", req))
}
if !comp.pre.is_empty() {
return Err(format!("Pre-release versions are not supported: '{}'", req));
return Err(format!("Pre-release versions are not supported: '{}'", req))
}

versions.push(Version {
Expand Down
16 changes: 12 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ fn integration() {

if config.default_args() {
let toml_path = workspace.as_path().join("Cargo.toml");
cmd.args(["--manifest-path", toml_path.as_path().to_str().unwrap(), "--log", "warn"]);
cmd.args([
"--manifest-path",
toml_path.as_path().to_str().unwrap(),
"--log",
"warn",
]);
if i > 0 {
cmd.arg("--offline");
}
Expand Down Expand Up @@ -94,15 +99,15 @@ fn integration() {
colour::yellow!("OVERWRITE");
colour::white!(" ");
cerr_overwrites.insert(i, String::from_utf8_lossy(&res.stderr).to_string());

failed += 1;
},
(false, _) => {
colour::white!("cout:");
colour::yellow!("OVERWRITE");
colour::white!(" ");
cout_overwrites.insert(i, String::from_utf8_lossy(&res.stdout).to_string());

failed += 1;
},
}
Expand Down Expand Up @@ -140,7 +145,10 @@ fn integration() {
}

if std::env::var("OVERWRITE").is_ok() {
if cout_overwrites.is_empty() && cerr_overwrites.is_empty() && diff_overwrites.is_empty() {
if cout_overwrites.is_empty() &&
cerr_overwrites.is_empty() &&
diff_overwrites.is_empty()
{
continue
}

Expand Down

0 comments on commit 39d36b4

Please sign in to comment.