Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: simplify string formatting for readability #1828

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bench/benches/compiler_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn setup_compiler() -> Compiler {
}

fn bench_compiler_compile(c: &mut Criterion) {
let mut compiler = setup_compiler();
let compiler = setup_compiler();
c.bench_function("compiler_compile", |b| {
b.iter(|| {
black_box(compiler.compile().unwrap());
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Compiler {

if !self.context.log_store.lock().warnings().is_empty() {
for warning in self.context.log_store.lock().warnings() {
println!("[warn] {}", warning);
println!("[warn] {warning}");
}
}

Expand Down
8 changes: 2 additions & 6 deletions crates/compiler/src/generate/partial_bundling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ mod tests {
let module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down Expand Up @@ -311,9 +309,7 @@ mod tests {
let module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Compiler {
.plugin_driver
.write_plugin_cache(&self.context)
.unwrap_or_else(|err| {
eprintln!("write plugin cache error: {:?}", err);
eprintln!("write plugin cache error: {err:?}");
});

if matches!(self.context.config.mode, Mode::Development) {
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/src/update/diff_and_patch_module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl DiffResult {
// added_modules: g, h

for (module_id, deps_diff_result) in &self.deps_changes {
println!("{:?} -> ", module_id);
println!("{module_id:?} -> ");

println!(
" added: {:?}",
Expand Down Expand Up @@ -372,7 +372,7 @@ fn diff_module_deps(
let mut children_added = vec![];

if module_graph.has_module(&dep) {
panic!("The module({:?}) exists in previous module graph, this should never happen and there is a internal bug inside farm. Please report it via issues", dep);
panic!("The module({dep:?}) exists in previous module graph, this should never happen and there is a internal bug inside farm. Please report it via issues");
}

for child in children {
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ impl Compiler {
&removed_modules,
&cloned_context,
) {
println!("Failed to regenerate resources: {}", e);
println!("modules to regenerate: {:?}", cloned_updated_module_ids);
println!("Failed to regenerate resources: {e}");
println!("modules to regenerate: {cloned_updated_module_ids:?}");
}

finalize_resources(&cloned_context).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/src/update/patch_module_group_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn patch_module_group_graph(
let module_group_ids = {
let module = module_graph
.module(module_id)
.unwrap_or_else(|| panic!("module {:?} not found", module_id));
.unwrap_or_else(|| panic!("module {module_id:?} not found"));
module.module_groups.clone()
};

Expand Down Expand Up @@ -95,7 +95,7 @@ pub fn patch_module_group_graph(
for module_group_id in &previous_parent_groups {
let current_module = module_graph
.module(&current_module_id)
.unwrap_or_else(|| panic!("module {:?} not found", current_module_id));
.unwrap_or_else(|| panic!("module {current_module_id:?} not found"));

if current_module.module_groups.contains(module_group_id) {
continue;
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn patch_module_group_graph(
} else {
let module = module_graph
.module(module_id)
.unwrap_or_else(|| panic!("module {:?} not found", module_id));
.unwrap_or_else(|| panic!("module {module_id:?} not found"));
module.module_groups.clone()
}
};
Expand Down
16 changes: 4 additions & 12 deletions crates/compiler/src/update/patch_module_group_graph/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ fn test_patch_module_group_graph_3() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down Expand Up @@ -214,9 +212,7 @@ fn test_patch_module_group_graph_3() {
let update_module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
wre232114 marked this conversation as resolved.
Show resolved Hide resolved
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down Expand Up @@ -297,9 +293,7 @@ fn test_patch_module_group_graph_css_modules() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand All @@ -323,9 +317,7 @@ fn test_patch_module_group_graph_css_modules() {
let update_module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn handle_enforce_resource_pots(
get_resource_pot_id_for_enforce_resources(name, module_id, &module_graph)
} else {
let module = removed_modules.get(module_id).unwrap_or_else(|| {
panic!("can not find module {:?}", module_id);
panic!("can not find module {module_id:?}");
});
get_resource_pot_id_for_enforce_resources_by_removed_module(name, module)
};
Expand Down Expand Up @@ -189,7 +189,7 @@ fn handle_enforce_resource_pots(
// remove the resource pot if it's modules are empty
for id in &affected_resource_pot_ids {
let resource_pot = resource_pot_map.resource_pot_mut(id).unwrap_or_else(|| {
panic!("resource pot not found: {:?}", id);
panic!("resource pot not found: {id:?}");
});

if resource_pot.modules().is_empty() {
Expand Down Expand Up @@ -250,8 +250,7 @@ fn diff_and_patch_resource_pot_map(
.remove_resource_pot(resource_pot)
.unwrap_or_else(|| {
panic!(
"The resource pot {:?} should be in the resource pot map",
resource_pot
"The resource pot {resource_pot:?} should be in the resource pot map"
)
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ fn test_generate_and_diff_resource_pots() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down Expand Up @@ -103,7 +101,7 @@ fn test_generate_and_diff_resource_pots() {
&context,
)
.unwrap();
println!("{:?}", resource_pot_ids);
println!("{resource_pot_ids:?}");
assert_eq!(
resource_pot_ids,
vec![String::from("test_custom(\"__farm_unknown\")")]
Expand Down Expand Up @@ -248,9 +246,7 @@ fn test_generate_and_diff_resource_pots_one_module_changed() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ fn test_handle_enforce_resource_pots() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down Expand Up @@ -173,9 +171,7 @@ fn test_handle_enforce_resource_pots_one_module_changed() {
let mut module_group_graph = module_group_graph_from_entries(
&module_graph
.entries
.clone()
.into_iter()
.map(|(entry, _)| entry)
.clone().into_keys()
.collect(),
&mut module_graph,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/update/regenerate_resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn regenerate_resources_for_affected_module_groups(
.plugin_driver
.write_plugin_cache(context)
.unwrap_or_else(|err| {
eprintln!("write plugin cache error: {:?}", err);
eprintln!("write plugin cache error: {err:?}");
});

write_cache(context.clone());
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/tests/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test(file: String, crate_path: String) {
let file_path_buf = PathBuf::from(file.clone());
let create_path_buf = PathBuf::from(crate_path);
let cwd = file_path_buf.parent().unwrap();
println!("testing test case: {:?}", cwd);
println!("testing test case: {cwd:?}");

let entry_name = "index".to_string();

Expand Down Expand Up @@ -110,7 +110,7 @@ fn test(file: String, crate_path: String) {
if config_named.is_empty() {
"".into()
} else {
format!("{}.", config_named)
format!("{config_named}.")
}
)),
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ pub fn get_compiler_result(compiler: &Compiler, config: &AssertCompilerResultCon
String::from_utf8_lossy(&resource.bytes),
),
_ => (
format!("1{}", name),
format!("//{}:\n ", name),
format!("1{name}"),
format!("//{name}:\n "),
String::from_utf8_lossy(&resource.bytes),
),
})
Expand All @@ -236,7 +236,7 @@ pub fn get_compiler_result(compiler: &Compiler, config: &AssertCompilerResultCon

let result_file_str = result
.iter()
.map(|(_, name, content)| format!("{}{}", name, content))
.map(|(_, name, content)| format!("{name}{content}"))
.collect::<Vec<String>>()
.join("\n\n");

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/tests/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::common::{assert_compiler_result, create_css_compiler};
fn css_modules() {
fixture!("tests/fixtures/css/modules/**/*.ts", |file, crate_path| {
let cwd = file.parent().unwrap();
println!("cwd: {:?}", cwd);
println!("cwd: {cwd:?}");

let entry_name = "index".to_string();

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/tests/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test(file: String, crate_path: String) {
let file_path_buf = PathBuf::from(file.clone());
let create_path_buf = PathBuf::from(crate_path);
let cwd = file_path_buf.parent().unwrap();
println!("testing test case: {:?}", cwd);
println!("testing test case: {cwd:?}");

let entry_name = "index".to_string();
let normolized_file = file.replace('\\', "/");
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/tests/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn minify_script_test() {
"tests/fixtures/minify/script/**/index.ts",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing minify: {:?}", cwd);
println!("testing minify: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand All @@ -34,7 +34,7 @@ fn minify_css_test() {
"tests/fixtures/minify/css/**/index.ts",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing minify: {:?}", cwd);
println!("testing minify: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand All @@ -56,7 +56,7 @@ fn minify_html_test() {
"tests/fixtures/minify/html/**/index.html",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing minify: {:?}", cwd);
println!("testing minify: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/tests/partial_bundling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn partial_bundling_test() {
"tests/fixtures/partial_bundling/**/index.ts",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing tree shake: {:?}", cwd);
println!("testing tree shake: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/tests/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test(file: String, crate_path: String) {
let file_path_buf = PathBuf::from(file.clone());
let create_path_buf = PathBuf::from(crate_path);
let cwd = file_path_buf.parent().unwrap();
println!("testing test case: {:?}", cwd);
println!("testing test case: {cwd:?}");

let entry_name = "index".to_string();

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/tests/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn script_test(file: String, crate_path: String) {
let file_path_buf = PathBuf::from(file.clone());
let create_path_buf = PathBuf::from(crate_path);
let cwd = file_path_buf.parent().unwrap();
println!("testing test case: {:?}", cwd);
println!("testing test case: {cwd:?}");

let entry_name = "index".to_string();

Expand Down
8 changes: 4 additions & 4 deletions crates/compiler/tests/tree_shake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn tree_shake_test() {
"tests/fixtures/tree_shake/**/index.ts",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing tree shake: {:?}", cwd);
println!("testing tree shake: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand All @@ -52,7 +52,7 @@ fn tree_shake_development() {
|file, crate_path| {
let cwd = file.parent().unwrap();
let entry_name = "index".to_string();
println!("testing tree shake: {:?}", cwd);
println!("testing tree shake: {cwd:?}");

let compiler = create_compiler_with_args(cwd.into(), crate_path, |mut config, plguin| {
config.input = HashMap::from([(entry_name.clone(), "./index.ts".to_string())]);
Expand All @@ -73,7 +73,7 @@ fn tree_shake_html_entry() {
"tests/fixtures/tree_shake/html_entry/**/index.html",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing tree shake: {:?}", cwd);
println!("testing tree shake: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler(
Expand Down Expand Up @@ -153,7 +153,7 @@ fn tree_shake_changed_ast() {
"tests/fixtures/tree_shake/changed_ast/entry.ts",
|file, crate_path| {
let cwd = file.parent().unwrap();
println!("testing tree shake: {:?}", cwd);
println!("testing tree shake: {cwd:?}");

let entry_name = "index".to_string();
let compiler = create_compiler_with_plugins(
Expand Down
Loading
Loading