Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Rustfmt + clippy #202

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ rust:
- stable
matrix:
include:
- rust: nightly-2017-12-20
- rust: "1.24.0"
before_script:
- rustup component add rustfmt-preview --toolchain nightly-2017-12-20
- cargo install clippy --vers 0.0.176
- rustup component add rustfmt-preview --toolchain 1.24.0
script:
- cargo clippy -- -D warnings
- rustfmt -V
- cargo fmt -- --write-mode diff
- rust: nightly-2018-02-14
before_script:
- cargo install clippy --vers 0.0.186
script:
- cargo clippy -- -D warnings
allow_failures:
- rust: nightly
before_script:
Expand Down
1 change: 0 additions & 1 deletion src/bin/add/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl Args {
]);
}


let dependency = if !crate_name_is_url_or_path(&self.arg_crate) {
let dependency = Dependency::new(&self.arg_crate);

Expand Down
2 changes: 1 addition & 1 deletion src/bin/rm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces,
unused_qualifications)]

extern crate atty;
extern crate docopt;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate serde_derive;
extern crate termcolor;
extern crate atty;

use std::process;
use std::io::Write;
Expand Down
16 changes: 5 additions & 11 deletions src/bin/upgrade/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ where
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)).set_bold(true))
.chain_err(|| "Failed to set output colour")?;
write!(&mut buffer, "Starting dry run. ")
.chain_err(|| "Failed to write dry run message")?;
write!(&mut buffer, "Starting dry run. ").chain_err(|| "Failed to write dry run message")?;
buffer
.set_color(&ColorSpec::new())
.chain_err(|| "Failed to clear output colour")?;
Expand Down Expand Up @@ -154,12 +153,9 @@ fn upgrade_manifest_from_cache(
new_deps: &HashMap<String, Dependency>,
dry_run: bool,
) -> Result<()> {
upgrade_manifest_using_dependencies(
manifest_path,
only_update,
dry_run,
|name| Ok(new_deps[name].clone()),
)
upgrade_manifest_using_dependencies(manifest_path, only_update, dry_run, |name| {
Ok(new_deps[name].clone())
})
}

/// Get a list of the paths of all the (non-virtual) manifests in the workspace.
Expand Down Expand Up @@ -188,9 +184,7 @@ fn get_new_workspace_deps(
.packages
.iter()
.flat_map(|package| package.dependencies.to_owned())
.filter(|dependency| {
only_update.is_empty() || only_update.contains(&dependency.name)
})
.filter(|dependency| only_update.is_empty() || only_update.contains(&dependency.name))
.map(|dependency| {
if !new_deps.contains_key(&dependency.name) {
new_deps.insert(
Expand Down
28 changes: 5 additions & 23 deletions tests/cargo-add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const BOGUS_CRATE_NAME: &str = "tests-will-break-if-there-is-ever-a-real-package

/// Check 'failure' deps are not present
fn no_manifest_failures(manifest: &toml_edit::Item) -> bool {
let no_failure_key_in = |section| {
manifest[section][BOGUS_CRATE_NAME].is_none()
};
let no_failure_key_in = |section| manifest[section][BOGUS_CRATE_NAME].is_none();
no_failure_key_in("dependencies") && no_failure_key_in("dev-dependencies")
&& no_failure_key_in("build-dependencies")
}
Expand Down Expand Up @@ -211,12 +209,7 @@ fn adds_specified_version() {

// cannot run with both --dev and --build at the same time
let call = process::Command::new("target/debug/cargo-add")
.args(&[
"add",
BOGUS_CRATE_NAME,
"--vers",
"invalid version string",
])
.args(&["add", BOGUS_CRATE_NAME, "--vers", "invalid version string"])
.arg(format!("--manifest-path={}", &manifest))
.output()
.unwrap();
Expand Down Expand Up @@ -321,10 +314,7 @@ fn adds_git_source_using_flag() {

let toml = get_toml(&manifest);
let val = &toml["dev-dependencies"]["git-dev-pkg"];
assert_eq!(
val["git"].as_str(),
Some("http://site/gp.git")
);
assert_eq!(val["git"].as_str(), Some("http://site/gp.git"));
}

#[test]
Expand All @@ -339,10 +329,7 @@ fn adds_local_source_using_flag() {

let toml = get_toml(&manifest);
let val = &toml["dependencies"]["local"];
assert_eq!(
val["path"].as_str(),
Some("/path/to/pkg")
);
assert_eq!(val["path"].as_str(), Some("/path/to/pkg"));

// check this works with other flags (e.g. --dev) as well
let toml = get_toml(&manifest);
Expand All @@ -355,10 +342,7 @@ fn adds_local_source_using_flag() {

let toml = get_toml(&manifest);
let val = &toml["dev-dependencies"]["local-dev"];
assert_eq!(
val["path"].as_str(),
Some("/path/to/pkg-dev")
);
assert_eq!(val["path"].as_str(), Some("/path/to/pkg-dev"));
}

#[test]
Expand Down Expand Up @@ -552,7 +536,6 @@ fn adds_dependency_with_custom_target() {
assert_eq!(val.as_str(), Some("my-package1--CURRENT_VERSION_TEST"));
}


#[test]
#[cfg(feature = "test-external-apis")]
fn adds_dependency_normalized_name() {
Expand All @@ -576,7 +559,6 @@ fn adds_dependency_normalized_name() {
assert!(!toml["dependencies"]["linked-hash-map"].is_none());
}


#[test]
#[should_panic]
fn fails_to_add_dependency_with_empty_target() {
Expand Down
5 changes: 1 addition & 4 deletions tests/cargo-upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ fn upgrade_specified_only() {
dependencies["versioned-package"].as_str(),
Some("versioned-package--CURRENT_VERSION_TEST")
);
assert_eq!(
dependencies["versioned-package-2"].as_str(),
Some("0.1.1")
);
assert_eq!(dependencies["versioned-package-2"].as_str(), Some("0.1.1"));
}

#[test]
Expand Down