Skip to content

Commit

Permalink
refactor: run clippy with --all-targets (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Dec 11, 2024
1 parent 8844add commit b00b2b8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- uses: Boshen/setup-rust@main
with:
components: clippy
- run: cargo clippy --all-features -- -D warnings
- run: cargo clippy --all-features --all-targets -- -D warnings

doc:
name: Doc
Expand Down
2 changes: 1 addition & 1 deletion benches/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn data() -> Vec<(PathBuf, &'static str)> {
(cwd.clone(), "@napi-rs/wasm-runtime"),
(cwd.clone(), "ava"),
(cwd.clone(), "emnapi"),
(cwd.clone(), "typescript"),
(cwd, "typescript"),
// relative path
(f1.clone(), "./"),
(f1.clone(), "./lib/index"),
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test:

# Lint the whole project
lint:
cargo clippy --all-features -- --deny warnings
cargo clippy --all-features --all-targets -- --deny warnings

# Generate doc
doc:
Expand Down
1 change: 1 addition & 0 deletions src/tests/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use normalize_path::NormalizePath;

use crate::{AliasValue, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver};

#[allow(clippy::too_many_lines)]
#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
fn alias() {
Expand Down
12 changes: 4 additions & 8 deletions src/tests/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
mod windows {
use std::path::PathBuf;

use rustc_hash::FxHashSet;

use super::super::memory_fs::MemoryFS;
use crate::{ResolveContext, ResolveOptions, ResolverGeneric};

Expand Down Expand Up @@ -96,13 +94,11 @@ mod windows {
for (name, context, request, result, file_dependencies, missing_dependencies) in data {
let mut ctx = ResolveContext::default();
let path = PathBuf::from(context);
let resolved =
let resolved_path =
resolver.resolve_with_context(path, request, &mut ctx).map(|r| r.full_path());
assert_eq!(resolved, Ok(PathBuf::from(result)));
let file_dependencies =
FxHashSet::from_iter(file_dependencies.iter().map(PathBuf::from));
let missing_dependencies =
FxHashSet::from_iter(missing_dependencies.iter().map(PathBuf::from));
assert_eq!(resolved_path, Ok(PathBuf::from(result)));
let file_dependencies = file_dependencies.iter().map(PathBuf::from).collect();
let missing_dependencies = missing_dependencies.iter().map(PathBuf::from).collect();
assert_eq!(ctx.file_dependencies, file_dependencies, "{name}");
assert_eq!(ctx.missing_dependencies, missing_dependencies, "{name}");
}
Expand Down
15 changes: 10 additions & 5 deletions src/tests/exports_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ fn test_cases() {
..ResolveOptions::default()
});
let cached_path = resolver.cache.value(Path::new(""));
let resolved = resolver
let resolved_path = resolver
.package_exports_resolve(
&cached_path,
case.request,
Expand All @@ -2533,18 +2533,23 @@ fn test_cases() {
if let Some(expect) = case.expect {
if expect.is_empty() {
assert!(
matches!(resolved, Err(ResolveError::PackagePathNotExported(_, _))),
matches!(resolved_path, Err(ResolveError::PackagePathNotExported(_, _))),
"{} {:?}",
&case.name,
&resolved
&resolved_path
);
} else {
for expect in expect {
assert_eq!(resolved, Ok(Some(Path::new(expect).normalize())), "{}", &case.name);
assert_eq!(
resolved_path,
Ok(Some(Path::new(expect).normalize())),
"{}",
&case.name
);
}
}
} else {
assert!(resolved.is_err(), "{} {resolved:?}", &case.name);
assert!(resolved_path.is_err(), "{} {resolved_path:?}", &case.name);
}
}
}
14 changes: 10 additions & 4 deletions src/tests/imports_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn imports_field(value: serde_json::Value) -> JSONMap {
serde_json::from_str(&s).unwrap()
}

#[allow(clippy::too_many_lines)]
#[test]
fn test_cases() {
let test_cases = [
Expand Down Expand Up @@ -1298,7 +1299,7 @@ fn test_cases() {
for case in test_cases {
let resolver = Resolver::default();
let cached_path = resolver.cache.value(Path::new(""));
let resolved = resolver
let resolved_path = resolver
.package_imports_exports_resolve(
case.request,
&case.imports_field,
Expand All @@ -1310,14 +1311,19 @@ fn test_cases() {
.map(|p| p.map(|p| p.to_path_buf()));
if let Some(expect) = case.expect {
if expect.is_empty() {
assert!(matches!(resolved, Ok(None)), "{} {:?}", &case.name, &resolved);
assert!(matches!(resolved_path, Ok(None)), "{} {:?}", &case.name, &resolved_path);
} else {
for expect in expect {
assert_eq!(resolved, Ok(Some(Path::new(expect).normalize())), "{}", &case.name);
assert_eq!(
resolved_path,
Ok(Some(Path::new(expect).normalize())),
"{}",
&case.name
);
}
}
} else {
assert!(resolved.is_err(), "{} {resolved:?}", &case.name);
assert!(resolved_path.is_err(), "{} {resolved_path:?}", &case.name);
}
}
}

0 comments on commit b00b2b8

Please sign in to comment.