Skip to content

Commit

Permalink
refactor: apply latest cargo +nightly fmt (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Oct 22, 2024
1 parent 30b1632 commit 0bdeb3b
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 193 deletions.
7 changes: 7 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ use_small_heuristics = "Max"

# Use field initialize shorthand if possible
use_field_init_shorthand = true

# For `cargo +nightly fmt`
# unstable_features = true
# style_edition = '2024'
# reorder_impl_items = true
# group_imports = "StdExternalCrate"
# imports_granularity = "Crate"
2 changes: 1 addition & 1 deletion napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub struct ResolveTask {

#[napi]
impl Task for ResolveTask {
type Output = ResolveResult;
type JsValue = ResolveResult;
type Output = ResolveResult;

fn compute(&mut self) -> napi::Result<Self::Output> {
Ok(resolve(&self.resolver, &self.directory, &self.request))
Expand Down
3 changes: 1 addition & 2 deletions napi/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};

use napi::Either;
use napi_derive::napi;
use std::collections::HashMap;

/// Module Resolution Options
///
Expand Down
6 changes: 3 additions & 3 deletions napi/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::OnceLock;

use tracing_subscriber::filter::Targets;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{
filter::Targets, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt,
};

/// To debug `oxc_resolver`:
/// `OXC_LOG=DEBUG your program`
Expand Down
4 changes: 3 additions & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use once_cell::sync::OnceCell as OnceLock;
use std::{
borrow::{Borrow, Cow},
convert::AsRef,
Expand All @@ -10,6 +9,7 @@ use std::{
};

use dashmap::{DashMap, DashSet};
use once_cell::sync::OnceCell as OnceLock;
use rustc_hash::FxHasher;

use crate::{
Expand Down Expand Up @@ -345,9 +345,11 @@ impl Hasher for IdentityHasher {
fn write(&mut self, _: &[u8]) {
unreachable!("Invalid use of IdentityHasher")
}

fn write_u64(&mut self, n: u64) {
self.0 = n;
}

fn finish(&self) -> u64 {
self.0
}
Expand Down
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{io, path::PathBuf, sync::Arc};

use thiserror::Error;

/// All resolution errors
Expand Down
2 changes: 1 addition & 1 deletion src/file_system.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cfg_if::cfg_if;
use std::{
fs, io,
path::{Path, PathBuf},
};

use cfg_if::cfg_if;
#[cfg(feature = "yarn_pnp")]
use pnp::fs::{LruZipCache, VPath, VPathInfo, ZipCache};

Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ use crate::{
package_json::JSONMap,
path::{PathUtil, SLASH_START},
specifier::Specifier,
tsconfig::ExtendsField,
tsconfig::{ProjectReference, TsConfig},
tsconfig::{ExtendsField, ProjectReference, TsConfig},
};

type ResolveResult = Result<Option<CachedPath>, ResolveError>;
Expand Down Expand Up @@ -624,7 +623,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
}
}
Restriction::RegExp(_) => {
return Err(ResolveError::Unimplemented("Restriction with regex"))
return Err(ResolveError::Unimplemented("Restriction with regex"));
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use std::{fmt, path::PathBuf};
use std::{
fmt,
path::{Path, PathBuf},
};

/// Module Resolution Options
///
Expand Down Expand Up @@ -275,6 +277,7 @@ impl ResolveOptions {
self.fully_specified = fully_specified;
self
}

/// Sets the value for [ResolveOptions::prefer_relative]
///
/// ## Examples
Expand All @@ -291,6 +294,7 @@ impl ResolveOptions {
self.prefer_relative = flag;
self
}

/// Sets the value for [ResolveOptions::prefer_absolute]
///
/// ## Examples
Expand Down Expand Up @@ -556,11 +560,12 @@ impl fmt::Display for ResolveOptions {

#[cfg(test)]
mod test {
use std::path::PathBuf;

use super::{
AliasValue, EnforceExtension, ResolveOptions, Restriction, TsconfigOptions,
TsconfigReferences,
};
use std::path::PathBuf;

#[test]
fn enforce_extension() {
Expand Down
3 changes: 2 additions & 1 deletion src/resolution.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::package_json::PackageJson;
use std::{
fmt,
path::{Path, PathBuf},
sync::Arc,
};

use crate::package_json::PackageJson;

/// The final path resolution with optional `?query` and `#fragment`
#[derive(Clone)]
pub struct Resolution {
Expand Down
3 changes: 2 additions & 1 deletion src/specifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::SpecifierError;
use std::borrow::Cow;

use crate::error::SpecifierError;

#[derive(Debug)]
pub struct Specifier<'a> {
path: Cow<'a, str>,
Expand Down
6 changes: 4 additions & 2 deletions src/tests/alias.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/alias.test.js>

use normalize_path::NormalizePath;
use std::path::Path;

use normalize_path::NormalizePath;

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

#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
fn alias() {
use std::path::{Path, PathBuf};

use super::memory_fs::MemoryFS;
use crate::ResolverGeneric;
use std::path::{Path, PathBuf};

let f = Path::new("/");

Expand Down
4 changes: 2 additions & 2 deletions src/tests/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
mod windows {
use rustc_hash::FxHashSet;
use std::path::PathBuf;

use crate::{ResolveContext, ResolveOptions, ResolverGeneric};
use rustc_hash::FxHashSet;

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

fn file_system() -> MemoryFS {
MemoryFS::new(&[
Expand Down
6 changes: 4 additions & 2 deletions src/tests/exports_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//!
//! The huge exports field test cases are at the bottom of this file.

use crate::{Ctx, PathUtil, ResolveError, ResolveOptions, Resolver};
use serde_json::json;
use std::path::Path;

use serde_json::json;

use crate::{Ctx, PathUtil, ResolveError, ResolveOptions, Resolver};

#[test]
fn test_simple() {
let f = super::fixture().join("exports-field");
Expand Down
3 changes: 2 additions & 1 deletion src/tests/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! <https://github.com/webpack/enhanced-resolve/blob/main/test/extensions.test.js>

use crate::{EnforceExtension, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver};
use rustc_hash::FxHashSet;

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

#[test]
fn extensions() {
let f = super::fixture().join("extensions");
Expand Down
3 changes: 2 additions & 1 deletion src/tests/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#[test]
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
fn fallback() {
use std::path::{Path, PathBuf};

use super::memory_fs::MemoryFS;
use crate::{AliasValue, ResolveError, ResolveOptions, ResolverGeneric};
use std::path::{Path, PathBuf};

let f = Path::new("/");

Expand Down
3 changes: 1 addition & 2 deletions src/tests/full_specified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
mod windows {
use std::path::PathBuf;

use crate::{AliasValue, ResolveOptions, ResolverGeneric};

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

fn file_system() -> MemoryFS {
MemoryFS::new(&[
Expand Down
3 changes: 2 additions & 1 deletion src/tests/imports_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//!
//! The huge imports field test cases are at the bottom of this file.

use std::path::Path;

use serde_json::json;

use crate::{Ctx, JSONMap, PathUtil, ResolveError, ResolveOptions, Resolver};
use std::path::Path;

#[test]
fn test_simple() {
Expand Down
3 changes: 2 additions & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ mod symlink;
mod tsconfig_paths;
mod tsconfig_project_references;

use crate::Resolver;
use std::{env, path::PathBuf, sync::Arc, thread};

use crate::Resolver;

pub fn fixture_root() -> PathBuf {
env::current_dir().unwrap().join("fixtures")
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ fn dashed_name() {
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
mod windows {
use super::super::memory_fs::MemoryFS;

use crate::ResolveOptions;

#[test]
fn no_package() {
use crate::ResolverGeneric;
use std::path::Path;

use crate::ResolverGeneric;
let f = Path::new("/");
let file_system = MemoryFS::new(&[]);
let resolver = ResolverGeneric::<MemoryFS>::new_with_file_system(
Expand Down
Loading

0 comments on commit 0bdeb3b

Please sign in to comment.