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: use inlined args for format! #8228

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ no_effect_underscore_binding = "warn"
ref_binding_to_reference = "warn"
ref_option_ref = "warn"
stable_sort_primitive = "warn"
uninlined_format_args = "warn"
unnecessary_box_returns = "warn"
unnecessary_join = "warn"
unnested_or_patterns = "warn"
Expand Down
17 changes: 4 additions & 13 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,10 +1208,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
}

let ordinal = self.ordinal_by_module.get(&module).unwrap_or_else(|| {
panic!(
"expected a module ordinal for identifier '{}', but none was found.",
module
)
panic!("expected a module ordinal for identifier '{module}', but none was found.")
});
if active_state.is_true() && min_available_modules.bit(*ordinal) {
// already in parent chunks, skip it for now
Expand Down Expand Up @@ -1298,7 +1295,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
let chunk_ukey = if let Some(chunk_name) = compilation
.get_module_graph()
.block_by_id(&block_id)
.unwrap_or_else(|| panic!("should have block: {:?}", block_id))
.unwrap_or_else(|| panic!("should have block: {block_id:?}"))
.get_group_options()
.and_then(|x| x.name())
{
Expand Down Expand Up @@ -1696,10 +1693,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
.iter()
.filter_map(|module| {
let ordinal = self.ordinal_by_module.get(module).unwrap_or_else(|| {
panic!(
"expected a module ordinal for identifier '{}', but none was found.",
module
)
panic!("expected a module ordinal for identifier '{module}', but none was found.")
});
if !cgi.min_available_modules.bit(*ordinal) {
Some(*module)
Expand Down Expand Up @@ -1736,10 +1730,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
if active_state.is_true() {
active_connections.push(i);
let module_ordinal = self.ordinal_by_module.get(module).unwrap_or_else(|| {
panic!(
"expected a module ordinal for identifier '{}', but none was found.",
module
)
panic!("expected a module ordinal for identifier '{module}', but none was found.")
});
if cgi.min_available_modules.bit(*module_ordinal) {
cgi.skipped_items.insert(*module);
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/chunk_graph/chunk_graph_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ChunkGraph {
self
.chunk_graph_module_by_module_identifier
.get_mut(&module_identifier)
.unwrap_or_else(|| panic!("Module({}) should be added before using", module_identifier))
.unwrap_or_else(|| panic!("Module({module_identifier}) should be added before using"))
}

pub(crate) fn expect_chunk_graph_module(
Expand All @@ -138,7 +138,7 @@ impl ChunkGraph {
self
.chunk_graph_module_by_module_identifier
.get(&module_identifier)
.unwrap_or_else(|| panic!("Module({}) should be added before using", module_identifier))
.unwrap_or_else(|| panic!("Module({module_identifier}) should be added before using"))
}

pub(crate) fn get_chunk_graph_module_mut(
Expand All @@ -154,7 +154,7 @@ impl ChunkGraph {
let chunk_graph_module = self
.chunk_graph_module_by_module_identifier
.get(&module_identifier)
.unwrap_or_else(|| panic!("Module({}) should be added before using", module_identifier));
.unwrap_or_else(|| panic!("Module({module_identifier}) should be added before using"));
&chunk_graph_module.chunks
}

Expand Down
31 changes: 13 additions & 18 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ impl Module for ConcatenatedModule {
let low = span.real_lo();
let high = span.real_hi();
if identifier.shorthand {
source.insert(high, &format!(": {}", new_name), None);
source.insert(high, &format!(": {new_name}"), None);
continue;
}

Expand Down Expand Up @@ -1195,11 +1195,7 @@ impl Module for ConcatenatedModule {
match info {
ModuleInfo::Concatenated(info) => {
result.add(RawStringSource::from(
format!(
"\n;// CONCATENATED MODULE: {}\n",
module_readable_identifier
)
.as_str(),
format!("\n;// CONCATENATED MODULE: {module_readable_identifier}\n").as_str(),
));
// https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/ConcatenatedModule.js#L1582
result.add(info.source.clone().expect("should have source"));
Expand All @@ -1213,8 +1209,7 @@ impl Module for ConcatenatedModule {
}
ModuleInfo::External(info) => {
result.add(RawStringSource::from(format!(
"\n// EXTERNAL MODULE: {}\n",
module_readable_identifier
"\n// EXTERNAL MODULE: {module_readable_identifier}\n"
)));

runtime_requirements.insert(RuntimeGlobals::REQUIRE);
Expand All @@ -1230,7 +1225,7 @@ impl Module for ConcatenatedModule {

if condition != "true" {
is_conditional = true;
result.add(RawStringSource::from(format!("if ({}) {{\n", condition)));
result.add(RawStringSource::from(format!("if ({condition}) {{\n")));
}

result.add(RawStringSource::from(format!(
Expand Down Expand Up @@ -1704,7 +1699,7 @@ impl ConcatenatedModule {
let module_graph = compilation.get_module_graph();
let module = module_graph
.module_by_identifier(&module_id)
.unwrap_or_else(|| panic!("should have module {}", module_id));
.unwrap_or_else(|| panic!("should have module {module_id}"));
let codegen_res = module.code_generation(compilation, runtime, Some(concatenation_scope))?;
let CodeGenerationResult {
mut inner,
Expand Down Expand Up @@ -1850,7 +1845,7 @@ impl ConcatenatedModule {
info
.internal_names
.iter()
.map(|(name, symbol)| format!("{}: {}", name, symbol))
.map(|(name, symbol)| format!("{name}: {symbol}"))
.collect::<Vec<String>>()
.join(", ")
)
Expand All @@ -1867,11 +1862,11 @@ impl ConcatenatedModule {
};
if is_property_access && as_call && !call_context {
return if asi_safe.unwrap_or_default() {
format!("(0,{})", reference)
format!("(0,{reference})")
} else if let Some(_asi_safe) = asi_safe {
format!(";(0,{})", reference)
format!(";(0,{reference})")
} else {
format!("/*#__PURE__*/Object({})", reference)
format!("/*#__PURE__*/Object({reference})")
};
}
reference
Expand Down Expand Up @@ -1989,13 +1984,13 @@ impl ConcatenatedModule {
.cloned()
.expect("should have default access name");
let default_export = if as_call {
format!("{}()", default_access_name)
format!("{default_access_name}()")
} else if let Some(true) = asi_safe {
format!("({}())", default_access_name)
format!("({default_access_name}())")
} else if let Some(false) = asi_safe {
format!(";({}())", default_access_name)
format!(";({default_access_name}())")
} else {
format!("{}.a", default_access_name)
format!("{default_access_name}.a")
};

return Binding::Raw(RawBinding {
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/context_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,13 +1113,13 @@ fn create_identifier(options: &ContextModuleOptions) -> Identifier {
}
id += "|groupOptions: {";
if let Some(o) = group.prefetch_order {
id.push_str(&format!("prefetchOrder: {},", o));
id.push_str(&format!("prefetchOrder: {o},"));
}
if let Some(o) = group.preload_order {
id.push_str(&format!("preloadOrder: {},", o));
id.push_str(&format!("preloadOrder: {o},"));
}
if let Some(o) = group.fetch_priority {
id.push_str(&format!("fetchPriority: {},", o));
id.push_str(&format!("fetchPriority: {o},"));
}
id += "}";
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/context_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ fn alternative_requests(
items.push(item.clone());
for module in resolve_options.modules() {
let dir = module.cow_replace('\\', "/");
if item.request.starts_with(&format!("./{}/", dir)) {
if item.request.starts_with(&format!("./{dir}/")) {
items.push(AlternativeRequest::new(
item.context.clone(),
item.request[dir.len() + 3..].to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ContextElementDependency {
path: &Utf8Path,
attributes: Option<&ImportAttributes>,
) -> String {
let mut ident = format!("context{}|{}", resource, path);
let mut ident = format!("context{resource}|{path}");
if let Some(attributes) = attributes {
ident += &json_stringify(&attributes);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/dependency/runtime_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ fn throw_missing_module_error_function(request: &str) -> String {
}

pub fn throw_missing_module_error_block(request: &str) -> String {
let e = format!("Cannot find module '{}'", request);
let e = format!("Cannot find module '{request}'");
format!(
"var e = new Error({}); e.code = 'MODULE_NOT_FOUND'; throw e;",
json!(e)
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/external_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl ExternalModule {
);

if let Some(concatenation_scope) = concatenation_scope {
let external_module_id = format!("__WEBPACK_EXTERNAL_MODULE_{}__", id);
let external_module_id = format!("__WEBPACK_EXTERNAL_MODULE_{id}__");
let namespace_export_with_name =
format!("{}{}", NAMESPACE_OBJECT_EXPORT, &external_module_id);
concatenation_scope.register_namespace_export(&namespace_export_with_name);
Expand Down
10 changes: 5 additions & 5 deletions crates/rspack_core/src/incremental/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl fmt::Display for Mutations {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "[")?;
for mutation in self.iter() {
writeln!(f, "{},", mutation)?;
writeln!(f, "{mutation},")?;
}
writeln!(f, "]")
}
Expand All @@ -60,10 +60,10 @@ pub enum Mutation {
impl fmt::Display for Mutation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Mutation::ModuleBuild { module } => write!(f, "build module {}", module),
Mutation::ModuleRemove { module } => write!(f, "remove module {}", module),
Mutation::ModuleSetAsync { module } => write!(f, "set async module {}", module),
Mutation::ModuleSetId { module } => write!(f, "set id module {}", module),
Mutation::ModuleBuild { module } => write!(f, "build module {module}"),
Mutation::ModuleRemove { module } => write!(f, "remove module {module}"),
Mutation::ModuleSetAsync { module } => write!(f, "set async module {module}"),
Mutation::ModuleSetId { module } => write!(f, "set id module {module}"),
Mutation::ChunkSetId { chunk } => write!(f, "set id chunk {}", chunk.as_u32()),
Mutation::ChunkAdd { chunk } => write!(f, "add chunk {}", chunk.as_u32()),
Mutation::ChunkSplit { from, to } => {
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/init_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl InitFragmentKey {
| InitFragmentKey::CommonJsExports(_)
| InitFragmentKey::Const(_) => first(fragments),
InitFragmentKey::ESMCompatibility | InitFragmentKey::Unique(_) => {
debug_assert!(fragments.len() == 1, "fragment = {:?}", self);
debug_assert!(fragments.len() == 1, "fragment = {self:?}");
first(fragments)
}
}
Expand Down Expand Up @@ -657,7 +657,7 @@ impl<C: InitFragmentRenderContext> InitFragment<C> for ExternalModuleInitFragmen
if imports_string.is_empty() {
String::new()
} else {
format!(", {}", imports_string)
format!(", {imports_string}")
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/options/filename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn render_template(
replace_all_placeholder(
t,
EXT_PLACEHOLDER,
&ext.map(|ext| format!(".{}", ext)).unwrap_or_default(),
&ext.map(|ext| format!(".{ext}")).unwrap_or_default(),
)
});
} else if let Some(ResourceParsedData {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/options/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl std::fmt::Display for CrossOriginLoading {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CrossOriginLoading::Disable => write!(f, "false"),
CrossOriginLoading::Enable(value) => write!(f, "\"{}\"", value),
CrossOriginLoading::Enable(value) => write!(f, "\"{value}\""),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn resolve_for_error_hints(
{
// If the specifier is a relative path pointing to the current directory,
// we can suggest the path relative to the current directory.
format!("{}{}", prefix, relative_path)
format!("{prefix}{relative_path}")
} else if PARENT_PATH_REGEX.is_match(args.specifier) {
// If the specifier is a relative path to which the parent directory is,
// then we return the relative path directly.
Expand Down Expand Up @@ -244,7 +244,7 @@ which tries to resolve these kind of requests in the current directory too.",
let mut suggestion = file.path().relative(&args.context).assert_utf8();

if !suggestion.as_str().starts_with('.') {
suggestion = Utf8PathBuf::from(format!("./{}", suggestion));
suggestion = Utf8PathBuf::from(format!("./{suggestion}"));
}
Some(suggestion)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/resolver/resolver_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl fmt::Debug for ResolveInnerOptions<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::RspackResolver(options) => {
write!(f, "{:?}", options)
write!(f, "{options:?}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/self_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct SelfModule {

impl SelfModule {
pub fn new(module_identifier: ModuleIdentifier) -> Self {
let identifier = format!("self {}", module_identifier);
let identifier = format!("self {module_identifier}");
Self {
identifier: ModuleIdentifier::from(identifier.as_str()),
readable_identifier: identifier,
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/utils/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ pub fn to_comment(str: &str) -> String {

let result = COMMENT_END_REGEX.replace_all(str, "* /");

format!("/*! {} */", result)
format!("/*! {result} */")
}
8 changes: 4 additions & 4 deletions crates/rspack_core/src/utils/compile_boolean_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ pub fn compile_boolean_matcher_from_lists(
BooleanMatcher::Matcher(Box::new(|_| "true".to_string()))
} else if positive_items.len() == 1 {
let item = to_simple_string(&positive_items[0]);
BooleanMatcher::Matcher(Box::new(move |value| format!("{} == {}", item, value)))
BooleanMatcher::Matcher(Box::new(move |value| format!("{item} == {value}")))
} else if negative_items.len() == 1 {
let item = to_simple_string(&negative_items[0]);
BooleanMatcher::Matcher(Box::new(move |value| format!("{} != {}", item, value)))
BooleanMatcher::Matcher(Box::new(move |value| format!("{item} != {value}")))
} else {
let positive_regexp = items_to_regexp(positive_items);
let negative_regexp = items_to_regexp(negative_items);

if positive_regexp.len() <= negative_regexp.len() {
BooleanMatcher::Matcher(Box::new(move |value| {
format!("/^{}$/.test({})", positive_regexp, value)
format!("/^{positive_regexp}$/.test({value})")
}))
} else {
BooleanMatcher::Matcher(Box::new(move |value| {
format!("!/^{}$/.test({})", negative_regexp, value)
format!("!/^{negative_regexp}$/.test({value})")
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/utils/file_counter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl FileCounter {
self.inner.remove(path);
}
} else {
panic!("can not remove file {:?}", path);
panic!("can not remove file {path:?}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/utils/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn stringify_loaders_and_resource<'a>(
.map(|i| &*i.loader)
.collect::<Vec<_>>()
.join("!");
Cow::Owned(format!("{s}!{}", resource))
Cow::Owned(format!("{s}!{resource}"))
} else {
Cow::Borrowed(resource)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/utils/task_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod test {
)
.await;
assert!(
format!("{:?}", res).contains("throw sync error"),
format!("{res:?}").contains("throw sync error"),
"should return sync error"
);
assert_eq!(context.call_sync_task_count, 0);
Expand All @@ -239,7 +239,7 @@ mod test {
)
.await;
assert!(
format!("{:?}", res).contains("throw async error"),
format!("{res:?}").contains("throw async error"),
"should return async error"
);
assert_eq!(context.call_sync_task_count, 1);
Expand Down
Loading
Loading