Skip to content

Commit 93cb6aa

Browse files
style: modernize format strings to use inline syntax
- Update format strings to use modern Rust inline syntax (e.g., {variable}) - Apply consistent formatting across taplo, taplo-cli, and formatter modules - Improve readability and follow Rust best practices
1 parent 0d5f986 commit 93cb6aa

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

crates/taplo-cli/src/commands/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<E: Environment> Taplo<E> {
260260
self.env
261261
.stderr()
262262
.write_all(
263-
format!("Failed to write diff to stdout: {:?}", e)
263+
format!("Failed to write diff to stdout: {e:?}")
264264
.as_str()
265265
.as_bytes(),
266266
)

crates/taplo/src/dom/to_toml.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Node {
4141

4242
// Use the original representation of primitives if available.
4343
if let Some(syntax) = self.syntax() {
44-
return write!(f, "{}", syntax);
44+
return write!(f, "{syntax}");
4545
}
4646
}
4747

@@ -153,7 +153,7 @@ impl Node {
153153
Node::Bool(b) => write!(f, "{}", b.value())?,
154154
Node::Str(s) => {
155155
if let Some(syntax) = s.syntax() {
156-
write!(f, "{}", syntax)?;
156+
write!(f, "{syntax}")?;
157157
} else {
158158
let escaped = escape(s.value());
159159

crates/taplo/src/formatter/mod.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ impl core::fmt::Display for OptionParseError {
138138
"invalid formatting option: {}",
139139
match self {
140140
OptionParseError::InvalidOption(k) => {
141-
format!(r#"invalid option "{}""#, k)
141+
format!(r#"invalid option "{k}""#)
142142
}
143143
OptionParseError::InvalidValue { key, error } => {
144-
format!(r#"invalid value for option "{}": {}"#, key, error)
144+
format!(r#"invalid value for option "{key}": {error}"#)
145145
}
146146
}
147147
)
@@ -418,10 +418,6 @@ impl FormattedItem for FormattedEntry {
418418
fn trailing_comment(&self) -> Option<String> {
419419
self.comment.clone()
420420
}
421-
422-
fn syntax(&self) -> SyntaxElement {
423-
self.syntax.clone()
424-
}
425421
}
426422

427423
fn format_root(node: SyntaxNode, options: &Options, context: &Context) -> String {
@@ -1194,22 +1190,17 @@ fn format_table_header(
11941190
}
11951191

11961192
// Simply a tuple of the formatted item and an optional trailing comment.
1197-
impl<T: AsRef<str>> FormattedItem for (SyntaxElement, T, Option<T>) {
1193+
impl<T: AsRef<str> + Clone> FormattedItem for (SyntaxElement, T, Option<T>) {
11981194
fn write_to(&self, formatted: &mut String, _options: &Options) {
11991195
*formatted += self.1.as_ref()
12001196
}
12011197

12021198
fn trailing_comment(&self) -> Option<String> {
12031199
self.2.as_ref().map(|s| s.as_ref().to_string())
12041200
}
1205-
1206-
fn syntax(&self) -> SyntaxElement {
1207-
self.0.clone()
1208-
}
12091201
}
12101202

12111203
trait FormattedItem {
1212-
fn syntax(&self) -> SyntaxElement;
12131204
#[allow(clippy::ptr_arg)]
12141205
fn write_to(&self, formatted: &mut String, options: &Options);
12151206
fn trailing_comment(&self) -> Option<String>;

crates/taplo/src/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn time_in_arrays() {
1414

1515
let errors = parse(src).errors;
1616

17-
assert!(errors.is_empty(), "{:#?}", errors);
17+
assert!(errors.is_empty(), "{errors:#?}");
1818
}
1919

2020
#[test]
@@ -25,5 +25,5 @@ fn comments_after_tables() {
2525
"#;
2626
let errors = parse(src).errors;
2727

28-
assert!(errors.is_empty(), "{:#?}", errors);
28+
assert!(errors.is_empty(), "{errors:#?}");
2929
}

0 commit comments

Comments
 (0)