Skip to content

Commit

Permalink
chore: solve cargo clippy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wre232114 committed May 6, 2024
1 parent 04c3b80 commit 417da17
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 138 deletions.
8 changes: 4 additions & 4 deletions crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ impl Compiler {
};
self
.build()
.and_then(|v| {
.map(|v| {
write_module_cache();
Ok(v)
v
})
.or_else(|err| {
.map_err(|err| {
write_module_cache();
Err(err)
err
})?;
}

Expand Down
1 change: 0 additions & 1 deletion crates/compiler/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use farmfe_core::{
error::CompilationError,
module::{
module_graph::ModuleGraphEdgeDataItem, module_group::ModuleGroupId, Module, ModuleId,
ModuleType,
},
plugin::{PluginResolveHookParam, ResolveKind, UpdateResult, UpdateType},
resource::ResourceType,
Expand Down
8 changes: 4 additions & 4 deletions crates/plugin_css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Plugin for FarmPluginCssResolve {
};
// fix #1230
let css_suffix = ".css";
let extensions = if matches!(param.kind, ResolveKind::CssAtImport) && !source.contains(".") {
let extensions = if matches!(param.kind, ResolveKind::CssAtImport) && !source.contains('.') {
vec![css_suffix, ""]
} else {
vec![""]
Expand Down Expand Up @@ -354,7 +354,7 @@ impl Plugin for FarmPluginCss {
);

// collapse sourcemap chain
if param.source_map_chain.len() > 0 {
if !param.source_map_chain.is_empty() {
let source_map_chain = param
.source_map_chain
.iter()
Expand Down Expand Up @@ -521,7 +521,7 @@ impl Plugin for FarmPluginCss {
.config
.minify
.clone()
.map(|val| MinifyOptions::from(val))
.map(MinifyOptions::from)
.unwrap_or_default();
let filter = PathFilter::new(&minify_options.include, &minify_options.exclude);
let source_map_enabled = context.config.sourcemap.enabled(resource_pot.immutable);
Expand Down Expand Up @@ -587,7 +587,7 @@ impl Plugin for FarmPluginCss {
rendered_length: css_code.len(),
original_length: module.size,
rendered_content: Arc::new(css_code),
rendered_map: src_map.map(|s| Arc::new(s)),
rendered_map: src_map.map(Arc::new),
});

Ok::<(), CompilationError>(())
Expand Down
2 changes: 1 addition & 1 deletion crates/plugin_runtime/src/render_resource_pot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn resource_pot_to_runtime_object(
}
}

let is_async_module = async_modules.contains(&m_id);
let is_async_module = async_modules.contains(m_id);
let RenderModuleResult {
rendered_module,
external_modules,
Expand Down
6 changes: 1 addition & 5 deletions crates/plugin_tree_shake/src/statement_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,7 @@ impl StatementGraph {
.extend(edge_weight.used_idents.iter().cloned());

for (k, v) in edge_weight.used_idents_map {
edge
.used_idents_map
.entry(k)
.or_insert(HashSet::new())
.extend(v);
edge.used_idents_map.entry(k).or_default().extend(v);
}
} else {
self.g.add_edge(*from_node, *to_node, edge_weight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Visit for UsedIdentsVisitor<'_> {
entry
.used_idents_map
.entry(current_defined_ident.clone())
.or_insert(HashSet::new())
.or_default()
.insert(ident.clone());
found = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ impl Visit for SideEffectsAnalyzer {
return;
}

match &member_expr.prop {
farmfe_core::swc_ecma_ast::MemberProp::Computed(computed) => {
computed.expr.visit_with(self);
}
_ => {}
if let farmfe_core::swc_ecma_ast::MemberProp::Computed(computed) = &member_expr.prop {
computed.expr.visit_with(self);
}

member_expr.obj.visit_with(self);
Expand Down Expand Up @@ -158,12 +155,11 @@ impl Visit for SideEffectsAnalyzer {
| farmfe_core::swc_ecma_ast::Stmt::ForOf(_) => self
.side_effects
.merge_side_effects(StatementSideEffects::UnclassifiedSelfExecuted),
farmfe_core::swc_ecma_ast::Stmt::Decl(decl) => match decl {
farmfe_core::swc_ecma_ast::Decl::Var(var_decl) => {
farmfe_core::swc_ecma_ast::Stmt::Decl(decl) => {
if let farmfe_core::swc_ecma_ast::Decl::Var(var_decl) = decl {
var_decl.visit_with(self);
}
_ => {}
},
}
farmfe_core::swc_ecma_ast::Stmt::Expr(expr) => {
expr.visit_with(self);
}
Expand Down
13 changes: 6 additions & 7 deletions crates/plugin_tree_shake/src/tree_shake_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn tree_shake_modules(
for tree_shake_module_id in &visited_modules {
if tree_shake_modules_map.contains_key(tree_shake_module_id) {
remove_useless_stmts::remove_useless_stmts(
&tree_shake_module_id,
tree_shake_module_id,
module_graph,
tree_shake_modules_map,
);
Expand Down Expand Up @@ -174,11 +174,10 @@ fn trace_and_mark_used_statements(
let source_kind = if let Some(import_info) = &stmt.import_info {
Some((import_info.source.as_str(), ResolveKind::Import))
} else if let Some(export_info) = &stmt.export_info {
if let Some(source) = &export_info.source {
Some((source.as_str(), ResolveKind::ExportFrom))
} else {
None
}
export_info
.source
.as_ref()
.map(|source| (source.as_str(), ResolveKind::ExportFrom))
} else {
None
};
Expand Down Expand Up @@ -227,7 +226,7 @@ fn trace_and_mark_used_statements(
}

// for dependency kind other than import and export from, always trace the dependency
for (_, edge) in module_graph.dependencies(&tree_shake_module_id) {
for (_, edge) in module_graph.dependencies(tree_shake_module_id) {
for edge_item in edge.items() {
if edge_item.kind != ResolveKind::Import && edge_item.kind != ResolveKind::ExportFrom {
traced_import_stmts.push(TracedUsedImportStatement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ pub fn remove_useless_stmts(
}
_ => { /* ignore other module decl statement */ }
},
ModuleItem::Stmt(Stmt::Decl(decl)) => {
if let swc_ecma_ast::Decl::Var(var_decl) = decl {
useless_specifier_remover.visit_mut_var_decl(var_decl);
}
ModuleItem::Stmt(Stmt::Decl(swc_ecma_ast::Decl::Var(var_decl))) => {
useless_specifier_remover.visit_mut_var_decl(var_decl);
}
_ => { /* ignore other statement */ }
}
Expand Down
Loading

0 comments on commit 417da17

Please sign in to comment.