Skip to content

Commit

Permalink
Simplify nested imports (#10250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Dec 19, 2024
1 parent a30dac5 commit 0ef8d1c
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 92 deletions.
8 changes: 3 additions & 5 deletions src/bin/crates-admin/render_readmes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::{anyhow, Context};
use crates_io::{
db,
models::Version,
schema::{crates, readme_renderings, versions},
};
use crates_io::db;
use crates_io::models::Version;
use crates_io::schema::{crates, readme_renderings, versions};
use futures_util::{StreamExt, TryStreamExt};
use std::path::{Path, PathBuf};
use std::{future, sync::Arc};
Expand Down
8 changes: 3 additions & 5 deletions src/bin/crates-admin/transfer_crates.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::dialoguer;
use crates_io::{
db,
models::{Crate, OwnerKind, User},
schema::{crate_owners, crates, users},
};
use crates_io::db;
use crates_io::models::{Crate, OwnerKind, User};
use crates_io::schema::{crate_owners, crates, users};

use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
Expand Down
10 changes: 3 additions & 7 deletions src/tests/builders/krate.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use crate::{
models::{Category, Crate, Keyword, NewCrate},
schema::{crates, version_downloads},
util::errors::AppResult,
};
use crate::models::{update_default_version, Category, Crate, Keyword, NewCrate};
use crate::schema::{crate_downloads, crates, version_downloads};
use crate::util::errors::AppResult;

use super::VersionBuilder;
use crate::models::update_default_version;
use crate::schema::crate_downloads;
use chrono::NaiveDateTime;
use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
Expand Down
8 changes: 3 additions & 5 deletions src/tests/builders/version.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
models::{Crate, NewVersion, Version},
schema::dependencies,
util::errors::AppResult,
};
use crate::models::{Crate, NewVersion, Version};
use crate::schema::dependencies;
use crate::util::errors::AppResult;
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
Expand Down
12 changes: 5 additions & 7 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::models::{Crate, CrateOwner, NewCategory, NewTeam, NewUser, OwnerKind, Team, User};
use crate::schema::crate_owners;
use crate::tests::util::{RequestHelper, TestApp};
use crate::{
models::{Crate, CrateOwner, NewCategory, NewTeam, NewUser, OwnerKind, Team, User},
schema::crate_owners,
views::{
EncodableCategory, EncodableCategoryWithSubcategories, EncodableCrate, EncodableKeyword,
EncodableOwner, EncodableVersion, GoodCrate,
},
use crate::views::{
EncodableCategory, EncodableCategoryWithSubcategories, EncodableCrate, EncodableKeyword,
EncodableOwner, EncodableVersion, GoodCrate,
};

use crate::tests::util::github::next_gh_id;
Expand Down
18 changes: 7 additions & 11 deletions src/tests/owners.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use crate::tests::{
add_team_to_crate,
builders::{CrateBuilder, PublishBuilder},
new_team,
util::{MockAnonymousUser, MockCookieUser, MockTokenUser, RequestHelper, Response},
TestApp,
use crate::models::Crate;
use crate::tests::builders::{CrateBuilder, PublishBuilder};
use crate::tests::util::{
MockAnonymousUser, MockCookieUser, MockTokenUser, RequestHelper, Response,
};
use crate::{
models::Crate,
views::{
EncodableCrateOwnerInvitationV1, EncodableOwner, EncodablePublicUser, InvitationResponse,
},
use crate::tests::{add_team_to_crate, new_team, TestApp};
use crate::views::{
EncodableCrateOwnerInvitationV1, EncodableOwner, EncodablePublicUser, InvitationResponse,
};

use crate::schema::users;
Expand Down
13 changes: 4 additions & 9 deletions src/tests/team.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use crate::tests::{
add_team_to_crate,
builders::{CrateBuilder, PublishBuilder},
new_team, OwnerTeamsResponse, RequestHelper, TestApp,
};
use crate::{
models::{Crate, NewTeam},
schema::teams,
};
use crate::models::{Crate, NewTeam};
use crate::schema::teams;
use crate::tests::builders::{CrateBuilder, PublishBuilder};
use crate::tests::{add_team_to_crate, new_team, OwnerTeamsResponse, RequestHelper, TestApp};

use diesel::*;
use diesel_async::RunQueryDsl;
Expand Down
7 changes: 2 additions & 5 deletions src/tests/user.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::models::{ApiToken, Email, NewUser, User};
use crate::tests::{
new_user,
util::{MockCookieUser, RequestHelper},
TestApp,
};
use crate::tests::util::{MockCookieUser, RequestHelper};
use crate::tests::{new_user, TestApp};
use crate::util::token::HashedToken;
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
Expand Down
12 changes: 4 additions & 8 deletions src/tests/util/chaosproxy.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use anyhow::{anyhow, Context};
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{
tcp::{OwnedReadHalf, OwnedWriteHalf},
TcpListener, TcpStream,
},
sync::broadcast::Sender,
};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::broadcast::Sender;
use tracing::{debug, error};
use url::Url;

Expand Down
6 changes: 2 additions & 4 deletions src/tests/util/matchers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use googletest::{
description::Description,
matcher::{Matcher, MatcherBase, MatcherResult},
};
use googletest::description::Description;
use googletest::matcher::{Matcher, MatcherBase, MatcherResult};
use http::StatusCode;

pub fn is_success() -> SuccessMatcher {
Expand Down
6 changes: 2 additions & 4 deletions src/typosquat/cache.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use diesel_async::AsyncPgConnection;
use std::sync::Arc;
use thiserror::Error;
use typomania::{
checks::{Bitflips, Omitted, SwappedWords, Typos},
Harness,
};
use typomania::checks::{Bitflips, Omitted, SwappedWords, Typos};
use typomania::Harness;

use super::{checks::Affixes, config, database::TopCrates};

Expand Down
6 changes: 2 additions & 4 deletions src/typosquat/checks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use typomania::{
checks::{Check, Squat},
Corpus, Package,
};
use typomania::checks::{Check, Squat};
use typomania::{Corpus, Package};

/// A typomania check that checks if commonly used prefixes or suffixes have been added to or
/// removed from a package name.
Expand Down
14 changes: 5 additions & 9 deletions src/typosquat/database.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Types that bridge the crates.io database and typomania.
use std::{
borrow::Borrow,
collections::{BTreeMap, HashMap, HashSet},
};
use crate::models;
use crate::schema::{crate_downloads, crate_owners};

use std::borrow::Borrow;
use std::collections::{BTreeMap, HashMap, HashSet};

use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
Expand All @@ -20,11 +21,6 @@ pub struct TopCrates {
impl TopCrates {
/// Retrieves the `num` top crates from the database.
pub async fn new(conn: &mut AsyncPgConnection, num: i64) -> QueryResult<Self> {
use crate::{
models,
schema::{crate_downloads, crate_owners},
};

// We have to build up a data structure that contains the top crates, their owners in some
// form that is easily compared, and that can be indexed by the crate name.
//
Expand Down
6 changes: 2 additions & 4 deletions src/typosquat/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use diesel::prelude::*;
use diesel_async::RunQueryDsl;

use crate::models::{Crate, NewTeam, NewUser, Team, User};
use crate::schema::users;
use crate::tests::util::github::next_gh_id;
use crate::{
models::{Crate, NewTeam, NewUser, Team, User},
schema::users,
};

pub mod faker {
use super::*;
Expand Down
8 changes: 3 additions & 5 deletions src/worker/jobs/typosquat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use diesel_async::AsyncPgConnection;
use typomania::Package;

use crate::email::Email;
use crate::{
typosquat::{Cache, Crate},
worker::Environment,
Emails,
};
use crate::typosquat::{Cache, Crate};
use crate::worker::Environment;
use crate::Emails;

/// A job to check the name of a newly published crate against the most popular crates to see if
/// the new crate might be typosquatting an existing, popular crate.
Expand Down

0 comments on commit 0ef8d1c

Please sign in to comment.