Merge pull request #651 from vbrandl/fix-pedantic-lints

Enable clippy::pedantic lints
This commit is contained in:
Valentin Brandl 2023-07-27 10:47:40 +02:00 committed by GitHub
commit 88a3b3611b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 32 deletions

View File

@ -42,13 +42,9 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Clippy Linting - name: Clippy Linting
run: cargo clippy --all-features -- -Dclippy::all run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
# TODO
# run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
- name: Clippy Test Linting - name: Clippy Test Linting
run: cargo clippy --tests -- -Dclippy::all run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
# TODO
# run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
test: test:

View File

@ -41,17 +41,14 @@ impl ResponseError for Error {
fn error_response(&self) -> HttpResponse { fn error_response(&self) -> HttpResponse {
let mut buf = Vec::new(); let mut buf = Vec::new();
match self { if let Error::BranchNotFound = self {
Error::BranchNotFound => { templates::p404_no_master_html(&mut buf, VERSION_INFO, 0).unwrap();
templates::p404_no_master_html(&mut buf, VERSION_INFO, 0).unwrap(); HttpResponse::NotFound().content_type("text/html").body(buf)
HttpResponse::NotFound().content_type("text/html").body(buf) } else {
} templates::p500_html(&mut buf, VERSION_INFO, 0).unwrap();
_ => { HttpResponse::InternalServerError()
templates::p500_html(&mut buf, VERSION_INFO, 0).unwrap(); .content_type("text/html")
HttpResponse::InternalServerError() .body(buf)
.content_type("text/html")
.body(buf)
}
} }
} }
} }

View File

@ -282,6 +282,7 @@ where
} }
pull(&path)?; pull(&path)?;
let (hoc, head, commits) = hoc(&service_url, &state.repos(), &state.cache(), branch)?; let (hoc, head, commits) = hoc(&service_url, &state.repos(), &state.cache(), branch)?;
#[allow(clippy::cast_precision_loss)]
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) { let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
NumberPrefix::Standalone(hoc) => hoc.to_string(), NumberPrefix::Standalone(hoc) => hoc.to_string(),
NumberPrefix::Prefixed(prefix, hoc) => format!("{hoc:.1}{prefix}"), NumberPrefix::Prefixed(prefix, hoc) => format!("{hoc:.1}{prefix}"),

View File

@ -6,7 +6,7 @@ fn init() {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
openssl_probe::init_ssl_cert_env_vars(); openssl_probe::init_ssl_cert_env_vars();
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info")) telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"));
} }
#[actix_rt::main] #[actix_rt::main]

View File

@ -5,14 +5,14 @@ use tempfile::TempDir;
#[test] #[test]
fn no_repos() { fn no_repos() {
let repos = TempDir::new().unwrap(); let repos = TempDir::new().unwrap();
assert_eq!(0, count_repositories(&repos).unwrap()) assert_eq!(0, count_repositories(&repos).unwrap());
} }
#[test] #[test]
fn no_repos_for_provider() { fn no_repos_for_provider() {
let repos = TempDir::new().unwrap(); let repos = TempDir::new().unwrap();
let _provider = TempDir::new_in(&repos).unwrap(); let _provider = TempDir::new_in(&repos).unwrap();
assert_eq!(0, count_repositories(&repos).unwrap()) assert_eq!(0, count_repositories(&repos).unwrap());
} }
#[test] #[test]
@ -20,7 +20,7 @@ fn no_repos_for_owner() {
let repos = TempDir::new().unwrap(); let repos = TempDir::new().unwrap();
let provider = TempDir::new_in(&repos).unwrap(); let provider = TempDir::new_in(&repos).unwrap();
let _owner = TempDir::new_in(&provider).unwrap(); let _owner = TempDir::new_in(&provider).unwrap();
assert_eq!(0, count_repositories(&repos).unwrap()) assert_eq!(0, count_repositories(&repos).unwrap());
} }
#[test] #[test]
@ -29,7 +29,7 @@ fn one_repo_for_owner() {
let provider = TempDir::new_in(&repos).unwrap(); let provider = TempDir::new_in(&repos).unwrap();
let owner = TempDir::new_in(&provider).unwrap(); let owner = TempDir::new_in(&provider).unwrap();
let _repo = TempDir::new_in(&owner).unwrap(); let _repo = TempDir::new_in(&owner).unwrap();
assert_eq!(1, count_repositories(&repos).unwrap()) assert_eq!(1, count_repositories(&repos).unwrap());
} }
#[test] #[test]
@ -39,7 +39,7 @@ fn two_repos_for_owner() {
let owner = TempDir::new_in(&provider).unwrap(); let owner = TempDir::new_in(&provider).unwrap();
let _repo1 = TempDir::new_in(&owner).unwrap(); let _repo1 = TempDir::new_in(&owner).unwrap();
let _repo2 = TempDir::new_in(&owner).unwrap(); let _repo2 = TempDir::new_in(&owner).unwrap();
assert_eq!(2, count_repositories(&repos).unwrap()) assert_eq!(2, count_repositories(&repos).unwrap());
} }
#[test] #[test]
@ -51,7 +51,7 @@ fn two_repos_for_two_providers() {
let provider2 = TempDir::new_in(&repos).unwrap(); let provider2 = TempDir::new_in(&repos).unwrap();
let owner2 = TempDir::new_in(&provider2).unwrap(); let owner2 = TempDir::new_in(&provider2).unwrap();
let _repo2 = TempDir::new_in(&owner2).unwrap(); let _repo2 = TempDir::new_in(&owner2).unwrap();
assert_eq!(2, count_repositories(&repos).unwrap()) assert_eq!(2, count_repositories(&repos).unwrap());
} }
#[test] #[test]
@ -62,5 +62,5 @@ fn two_subdirs_in_one_repo() {
let repo = TempDir::new_in(&owner).unwrap(); let repo = TempDir::new_in(&owner).unwrap();
let _subdir1 = TempDir::new_in(&repo).unwrap(); let _subdir1 = TempDir::new_in(&repo).unwrap();
let _subdir2 = TempDir::new_in(&repo).unwrap(); let _subdir2 = TempDir::new_in(&repo).unwrap();
assert_eq!(1, count_repositories(&repos).unwrap()) assert_eq!(1, count_repositories(&repos).unwrap());
} }

View File

@ -25,14 +25,14 @@ pub async fn spawn_app() -> TestApp {
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port"); let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
let port = listener.local_addr().unwrap().port(); let port = listener.local_addr().unwrap().port();
let address = format!("http://127.0.0.1:{}", port); let address = format!("http://127.0.0.1:{port}");
let _repo_dir = tempdir().expect("Cannot create repo_dir"); let repo_dir = tempdir().expect("Cannot create repo_dir");
let _cache_dir = tempdir().expect("Cannot create cache_dir"); let cache_dir = tempdir().expect("Cannot create cache_dir");
let mut settings = Settings::load().expect("Failed to read configuration."); let mut settings = Settings::load().expect("Failed to read configuration.");
settings.repodir = _repo_dir.path().to_path_buf(); settings.repodir = repo_dir.path().to_path_buf();
settings.cachedir = _cache_dir.path().to_path_buf(); settings.cachedir = cache_dir.path().to_path_buf();
let server = hoc::run(listener, settings) let server = hoc::run(listener, settings)
.await .await
@ -44,7 +44,7 @@ pub async fn spawn_app() -> TestApp {
TestApp { TestApp {
address, address,
_repo_dir, _repo_dir: repo_dir,
_cache_dir, _cache_dir: cache_dir,
} }
} }