Skip to content

Bump clippy and rustfmt #1147

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

Merged
merged 2 commits into from
Nov 8, 2017
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ matrix:
allow_failures:
- rust: nightly
include:
- rust: nightly-2017-09-20
- rust: nightly-2017-11-07
env: RUSTFMT=YESPLEASE
script:
- cargo install --force rustfmt-nightly --vers 0.2.7
- cargo install --force rustfmt-nightly --vers 0.2.15
- export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
- rustfmt --version
- cargo fmt -- --write-mode=diff
Expand All @@ -51,7 +51,7 @@ matrix:
- cargo build
- cargo test
- npm test
- rust: nightly-2017-09-20
- rust: nightly-2017-11-07
env: CLIPPY=YESPLEASE
script:
- cargo check --features "lint"
Expand Down
40 changes: 24 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ diesel_full_text_search = "0.16.0"
serde_json = "1.0.0"
serde_derive = "1.0.0"
serde = "1.0.0"
clippy = { version = "=0.0.162", optional = true }
clippy = { version = "=0.0.169", optional = true }
chrono = { version = "0.4.0", features = ["serde"] }
comrak = { version = "0.2.3", default-features = false }
ammonia = { git = "https://github.com/notriddle/ammonia", rev = "3d4e4073f8cdb7c60203b9036c09f4385a2fdbbd" }
Expand Down
4 changes: 3 additions & 1 deletion src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ impl Badge {
delete(badges::table)
.filter(badges::crate_id.eq(krate.id))
.execute(conn)?;
insert_into(badges::table).values(&new_badges).execute(conn)?;
insert_into(badges::table)
.values(&new_badges)
.execute(conn)?;
Ok(invalid_badges)
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/keyword.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)] // TODO: Remove when rustc 1.23 is stable
use std::ascii::AsciiExt;

use chrono::NaiveDateTime;
Expand Down Expand Up @@ -127,7 +128,9 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
query = query.order(keywords::keyword.asc());
}

let data = query.paginate(limit, offset).load::<(Keyword, i64)>(&*conn)?;
let data = query
.paginate(limit, offset)
.load::<(Keyword, i64)>(&*conn)?;
let total = data.get(0).map(|&(_, t)| t).unwrap_or(0);
let kws = data.into_iter()
.map(|(k, _)| k.encodable())
Expand Down
4 changes: 2 additions & 2 deletions src/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn summary(req: &mut Request) -> CargoResult<Response> {
.map(|versions| Version::max(versions.into_iter().map(|v| v.num)))
.zip(krates)
.map(|(max_version, krate)| {
Ok(krate.minimal_encodable(max_version, None, false, None))
Ok(krate.minimal_encodable(&max_version, None, false, None))
})
.collect()
};
Expand Down Expand Up @@ -153,7 +153,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {
Ok(
req.json(&R {
krate: krate.clone().encodable(
max_version,
&max_version,
Some(ids),
Some(&kws),
Some(&cats),
Expand Down
7 changes: 4 additions & 3 deletions src/krate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)] // TODO: Remove when rustc 1.23 is stable
use std::ascii::AsciiExt;

use chrono::{NaiveDate, NaiveDateTime};
Expand Down Expand Up @@ -26,7 +27,7 @@ pub mod metadata;

/// Hosts in this blacklist are known to not be hosting documentation,
/// and are possibly of malicious intent e.g. ad tracking networks, etc.
const DOCUMENTATION_BLACKLIST: [&'static str; 1] = ["rust-ci.org"];
const DOCUMENTATION_BLACKLIST: [&str; 1] = ["rust-ci.org"];

#[derive(Debug, Insertable, Queryable, Identifiable, Associations, AsChangeset, Clone, Copy)]
#[belongs_to(Crate)]
Expand Down Expand Up @@ -315,7 +316,7 @@ impl Crate {

pub fn minimal_encodable(
self,
max_version: semver::Version,
max_version: &semver::Version,
badges: Option<Vec<Badge>>,
exact_match: bool,
recent_downloads: Option<i64>,
Expand All @@ -334,7 +335,7 @@ impl Crate {
#[cfg_attr(feature = "clippy", allow(too_many_arguments))]
pub fn encodable(
self,
max_version: semver::Version,
max_version: &semver::Version,
versions: Option<Vec<i32>>,
keywords: Option<&[Keyword]>,
categories: Option<&[Category]>,
Expand Down
2 changes: 1 addition & 1 deletion src/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn publish(req: &mut Request) -> CargoResult<Response> {
warnings: Warnings<'a>,
}
Ok(req.json(&R {
krate: krate.minimal_encodable(max_version, None, false, None),
krate: krate.minimal_encodable(&max_version, None, false, None),
warnings: warnings,
}))
})
Expand Down
2 changes: 1 addition & 1 deletion src/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn search(req: &mut Request) -> CargoResult<Response> {
.filter(badges::crate_id.eq(krate.id))
.load::<Badge>(&*conn)?;
Ok(krate.minimal_encodable(
max_version,
&max_version,
Some(badges),
perfect_match,
Some(recent_downloads),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This crate implements the backend server for https://crates.io/
//! This crate implements the backend server for <https://crates.io/>
//!
//! All implemented routes are defined in the [middleware](fn.middleware.html) function and
//! implemented in the [category](category/index.html), [keyword](keyword/index.html),
Expand Down
9 changes: 6 additions & 3 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ mod tests {

#[test]
fn text_with_inline_javascript() {
let text = r#"foo_readme\n\n<a href="https://crates.io/crates/cargo-registry" onclick="window.alert('Got you')">Crate page</a>"#;
let text =
r#"foo_readme\n\n<a href="https://crates.io/crates/cargo-registry" onclick="window.alert('Got you')">Crate page</a>"#;
let result = markdown_to_html(text, None).unwrap();
assert_eq!(
result,
Expand Down Expand Up @@ -345,7 +346,8 @@ mod tests {

#[test]
fn absolute_links_dont_get_resolved() {
let readme_text = "[![Crates.io](https://img.shields.io/crates/v/clap.svg)](https://crates.io/crates/clap)";
let readme_text =
"[![Crates.io](https://img.shields.io/crates/v/clap.svg)](https://crates.io/crates/clap)";
let repository = "https://github.com/kbknapp/clap-rs/";
let result = markdown_to_html(readme_text, Some(&repository)).unwrap();

Expand Down Expand Up @@ -387,7 +389,8 @@ mod tests {

#[test]
fn manual_anchor_is_sanitized() {
let text = "<h1><a href=\"#my-crate\" id=\"my-crate\"></a>My crate</h1>\n<p>Hello, world!</p>\n";
let text =
"<h1><a href=\"#my-crate\" id=\"my-crate\"></a>My crate</h1>\n<p>Hello, world!</p>\n";
let result = markdown_to_html(text, None).unwrap();
assert_eq!(
result,
Expand Down
3 changes: 2 additions & 1 deletion src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ impl<'a> CrateBuilder<'a> {
fn build(mut self, connection: &PgConnection) -> CargoResult<Crate> {
use diesel::{insert_into, update};

let mut krate = self.krate.create_or_update(connection, None, self.owner_id)?;
let mut krate = self.krate
.create_or_update(connection, None, self.owner_id)?;

// Since we are using `NewCrate`, we can't set all the
// crate properties in a single DB call.
Expand Down
18 changes: 12 additions & 6 deletions src/tests/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ fn test_github_login_does_not_overwrite_email() {
assert_eq!(r.user.email, None);
assert_eq!(r.user.login, "apricot");

let body = r#"{"user":{"email":"[email protected]","name":"Apricot Apricoto","login":"apricot","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/apricot","kind":null}}"#;
let body =
r#"{"user":{"email":"[email protected]","name":"Apricot Apricoto","login":"apricot","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/apricot","kind":null}}"#;
let mut response = ok_resp!(
middle.call(
req.with_path(&format!("/api/v1/users/{}", user.id))
Expand Down Expand Up @@ -440,7 +441,8 @@ fn test_email_get_and_put() {
assert_eq!(r.user.email, None);
assert_eq!(r.user.login, "mango");

let body = r#"{"user":{"email":"[email protected]","name":"Mango McMangoface","login":"mango","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/mango","kind":null}}"#;
let body =
r#"{"user":{"email":"[email protected]","name":"Mango McMangoface","login":"mango","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/mango","kind":null}}"#;
let mut response = ok_resp!(
middle.call(
req.with_path(&format!("/api/v1/users/{}", user.id))
Expand Down Expand Up @@ -479,7 +481,8 @@ fn test_empty_email_not_added() {
user
};

let body = r#"{"user":{"email":"","name":"Papayo Papaya","login":"papaya","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/papaya","kind":null}}"#;
let body =
r#"{"user":{"email":"","name":"Papayo Papaya","login":"papaya","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/papaya","kind":null}}"#;
let json = bad_resp!(
middle.call(
req.with_path(&format!("/api/v1/users/{}", user.id))
Expand All @@ -494,7 +497,8 @@ fn test_empty_email_not_added() {
json.errors
);

let body = r#"{"user":{"email":null,"name":"Papayo Papaya","login":"papaya","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/papaya","kind":null}}"#;
let body =
r#"{"user":{"email":null,"name":"Papayo Papaya","login":"papaya","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/papaya","kind":null}}"#;
let json = bad_resp!(
middle.call(
req.with_path(&format!("/api/v1/users/{}", user.id))
Expand Down Expand Up @@ -531,7 +535,8 @@ fn test_this_user_cannot_change_that_user_email() {
unsigned_user
};

let body = r#"{"user":{"email":"[email protected]","name":"Pine Apple","login":"pineapple","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/pineapple","kind":null}}"#;
let body =
r#"{"user":{"email":"[email protected]","name":"Pine Apple","login":"pineapple","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/pineapple","kind":null}}"#;

let json = bad_resp!(
middle.call(
Expand Down Expand Up @@ -642,7 +647,8 @@ fn test_insert_into_email_table_with_email_change() {
assert!(!r.user.email_verified);
assert!(r.user.email_verification_sent);

let body = r#"{"user":{"email":"[email protected]","name":"potato","login":"potato","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/potato","kind":null}}"#;
let body =
r#"{"user":{"email":"[email protected]","name":"potato","login":"potato","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/potato","kind":null}}"#;
let mut response = ok_resp!(
middle.call(
req.with_path(&format!("/api/v1/users/{}", user.id))
Expand Down
4 changes: 2 additions & 2 deletions src/uploaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Uploader {
}

/// Deletes an uploaded file.
fn delete(&self, app: Arc<App>, path: &str) -> CargoResult<()> {
fn delete(&self, app: &Arc<App>, path: &str) -> CargoResult<()> {
match *self {
Uploader::S3 { ref bucket, .. } => {
let mut handle = app.handle();
Expand All @@ -217,7 +217,7 @@ pub struct Bomb {
impl Drop for Bomb {
fn drop(&mut self) {
if let Some(ref path) = self.path {
if let Err(e) = self.app.config.uploader.delete(Arc::clone(&self.app), path) {
if let Err(e) = self.app.config.uploader.delete(&self.app, path) {
println!("unable to delete {}, {:?}", path, e);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl User {
/// This route will return an authorization URL for the GitHub OAuth flow including the crates.io
/// `client_id` and a randomly generated `state` secret.
///
/// see https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access
/// see <https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access>
///
/// ## Response Body Example
///
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn github_authorize(req: &mut Request) -> CargoResult<Response> {
/// to exchange the temporary `code` for an API token. The API token is returned together with
/// the corresponding user information.
///
/// see https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
/// see <https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site>
///
/// ## Query Parameters
///
Expand Down
2 changes: 1 addition & 1 deletion src/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub fn human<S: ToString + ?Sized>(error: &S) -> Box<CargoError> {

/// This is intended to be used for errors being sent back to the Ember
/// frontend, not to cargo as cargo does not handle non-200 response codes well
/// (see https://github.com/rust-lang/cargo/issues/3995), but Ember requires
/// (see <https://github.com/rust-lang/cargo/issues/3995>), but Ember requires
/// non-200 response codes for its stores to work properly.
///
/// Since this is going back to the UI these errors are treated the same as
Expand Down
6 changes: 1 addition & 5 deletions src/version/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
// Extract all ids requested.
let query = url::form_urlencoded::parse(req.query_string().unwrap_or("").as_bytes());
let ids = query
.filter_map(|(ref a, ref b)| if *a == "ids[]" {
b.parse().ok()
} else {
None
})
.filter_map(|(ref a, ref b)| if *a == "ids[]" { b.parse().ok() } else { None })
.collect::<Vec<i32>>();

let versions = versions::table
Expand Down