Skip to content

Commit

Permalink
chore(lint): impl Display for ModuleID
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Feb 13, 2025
1 parent c02f99f commit 211b94c
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions crates/compiler/src/generate/resource_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub fn get_resource_cache_key(
for module_id in resource_pot.modules() {
let module = module_graph
.module(module_id)
.unwrap_or_else(|| panic!("module not found: {:?}", module_id.to_string()));
.unwrap_or_else(|| panic!("module not found: {:?}", module_id));

// make sure cache is correct when tree shaking is enabled
code.push_str(&module.content_hash);

if context.cache_manager.module_cache.cache_outdated(module_id) {
code.push_str(&format!("[cache_outdated+{}]", module.id.to_string()));
code.push_str(&format!("[cache_outdated+{}]", module.id));
}

// if tree shaking is not enabled, we don't need to cache used_exports
Expand Down
8 changes: 1 addition & 7 deletions crates/core/src/cache/module_cache/mutable_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ impl MutableModulesMemoryStore {
module.last_update_timestamp
};
let hash_key = sha256(
format!(
"{}{}{}",
module.content_hash,
module.id.to_string(),
timestamp
)
.as_bytes(),
format!("{}{}{}", module.content_hash, module.id, timestamp).as_bytes(),
32,
);
CacheStoreKey {
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{hash::Hash, path::Path, sync::Arc};
use std::{fmt::Display, hash::Hash, path::Path, sync::Arc};

use crate::HashSet;
use blake2::{
Expand Down Expand Up @@ -361,9 +361,9 @@ impl From<String> for ModuleId {
}
}

impl ToString for ModuleId {
fn to_string(&self) -> String {
self.relative_path.to_string() + self.query_string.as_str()
impl Display for ModuleId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{}", self.relative_path, self.query_string)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/module/module_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub struct ModuleGroupId(String);

impl ModuleGroupId {
pub fn new(id: &ModuleId, ty: &ModuleGroupType) -> Self {
Self(format!("{}_{:?}", id.to_string(), ty))
Self(format!("{}_{:?}", id, ty))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/module/watch_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ impl WatchGraph {
let from_index = self.id_index_map.get(from).ok_or_else(|| {
CompilationError::GenericError(format!(
r#"from node "{}" does not exist in the module graph when add edge"#,
from.to_string()
from
))
})?;

let to_index = self.id_index_map.get(to).ok_or_else(|| {
CompilationError::GenericError(format!(
r#"to node "{}" does not exist in the module graph when add edge"#,
to.to_string()
to
))
})?;
// a h c
Expand Down
2 changes: 1 addition & 1 deletion crates/plugin_css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl Plugin for FarmPluginCss {
{}
export default {{{}}}
"#,
css_modules_module_id.to_string(),
css_modules_module_id,
dynamic_import_of_composes
.into_iter()
.fold(Vec::new(), |mut acc, (from, name)| {
Expand Down
3 changes: 1 addition & 2 deletions crates/plugin_css/src/transform_css_to_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ pub fn transform_css_to_script_modules(
key: sha256(
format!(
"transform_css_to_script_modules_{}_{}",
content_hash,
module_id.to_string()
content_hash, module_id
)
.as_bytes(),
32,
Expand Down
7 changes: 3 additions & 4 deletions crates/plugin_progress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ impl Plugin for FarmPluginProgress {
self.increment_module_count();
let count = self.get_module_count();
let module = &module.id;
self.progress_bar.set_message(format!(
"load cached module({count}) {}",
module.to_string()
));
self
.progress_bar
.set_message(format!("load cached module({count}) {}", module));
self.progress_bar.inc(1);

Ok(None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ impl SourceReplacer<'_> {
} else {
panic!(
"cannot found {} of DynamicImport from {}",
source,
self.module_id.to_string()
source, self.module_id
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ fn expand_module_exports_dfs(
// TODO: warning
println!(
"[Farm Warning] export {} of module {} not found",
local.sym,
source_module_id.to_string()
local.sym, source_module_id
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/toolkit/src/sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn trace_module_sourcemap(

let module = module_graph
.module(&module_id)
.unwrap_or_else(|| panic!("module {} not found in module graph", module_id.to_string()));
.unwrap_or_else(|| panic!("module {} not found in module graph", module_id));

if module.source_map_chain.is_empty() {
add_token(&token, &token, &sourcemap);
Expand Down

0 comments on commit 211b94c

Please sign in to comment.