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

refactor: add variables to format strings directly #3299

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ pub trait Rule: RuleMeta + Sized {
<Self::Group as RuleGroup>::NAME,
Self::METADATA.name
);
let suppression_text = format!("biome-ignore {}", rule_category);
let suppression_text = format!("biome-ignore {rule_category}");
let root = ctx.root();
let token = root.syntax().token_at_offset(text_range.start());
let mut mutation = root.begin();
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/migrate/ignorefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn convert_pattern(line: &str) -> Result<String, &'static str> {
}
let result = if let Some(stripped_line) = line.strip_prefix('/') {
// Patterns tha tstarts with `/` are relative to the ignore file
format!("./{}", stripped_line)
format!("./{stripped_line}")
} else if line.find('/').is_some_and(|index| index < (line.len() - 1))
|| line == "**"
|| line == "**/"
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/snap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl CliSnapshot {
let redacted_content =
redact_snapshot(file_content).unwrap_or(String::new().into());

let _ = write!(content, "## `{}`\n\n", redacted_name);
let _ = write!(content, "## `{redacted_name}`\n\n");
let _ = write!(content, "```{extension}");
content.push('\n');
content.push_str(&redacted_content);
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_configuration/src/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ fn expand_unknown_glob_patterns(pattern: &str) -> Result<Vec<String>, EditorConf
let start = start.parse().map_err(|err| {
EditorConfigDiagnostic::invalid_glob_pattern(
s,
format!("Error parsing the start of the range: {}", err),
format!("Error parsing the start of the range: {err}"),
)
})?;
let end = end.parse().map_err(|err| {
EditorConfigDiagnostic::invalid_glob_pattern(
s,
format!("Error parsing the end of the range: {}", err),
format!("Error parsing the end of the range: {err}"),
)
})?;
self.variants = Some(VariantType::Range((start, end)));
Expand Down
9 changes: 3 additions & 6 deletions crates/biome_css_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) {
let extension = input_file.extension().unwrap_or_default();

let input_code = read_to_string(input_file)
.unwrap_or_else(|err| panic!("failed to read {:?}: {:?}", input_file, err));
.unwrap_or_else(|err| panic!("failed to read {input_file:?}: {err:?}"));
let quantity_diagnostics = if let Some(scripts) = scripts_from_json(extension, &input_code) {
for script in scripts {
analyze_and_snap(
Expand Down Expand Up @@ -184,10 +184,7 @@ fn check_code_action(
assert_eq!(new_tree.to_string(), output);

if has_bogus_nodes_or_empty_slots(&new_tree) {
panic!(
"modified tree has bogus nodes or empty slots:\n{new_tree:#?} \n\n {}",
new_tree
)
panic!("modified tree has bogus nodes or empty slots:\n{new_tree:#?} \n\n {new_tree}")
}

// Checks the returned tree contains no missing children node
Expand All @@ -206,7 +203,7 @@ pub(crate) fn _run_suppression_test(input: &'static str, _: &str, _: &str, _: &s
let input_file = Path::new(input);
let file_name = input_file.file_name().and_then(OsStr::to_str).unwrap();
let input_code = read_to_string(input_file)
.unwrap_or_else(|err| panic!("failed to read {:?}: {:?}", input_file, err));
.unwrap_or_else(|err| panic!("failed to read {input_file:?}: {err:?}"));

let (group, rule) = parse_test_path(input_file);

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_formatter/tests/quick_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn quick_test() {
}
"#;
let parse = parse_css(src, CssParserOptions::default());
println!("{:#?}", parse);
println!("{parse:#?}");

let options = CssFormatOptions::default()
.with_line_width(LineWidth::try_from(80).unwrap())
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ impl<'src> CssLexer<'src> {

let char = self.current_char_unchecked();
let err = ParseDiagnostic::new(
format!("unexpected character `{}`", char),
format!("unexpected character `{char}`"),
self.text_position()..self.text_position() + char.text_len(),
);
self.diagnostics.push(err);
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_css_parser/src/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ fn losslessness(string: String) -> bool {
.recv_timeout(Duration::from_secs(2))
.unwrap_or_else(|_| {
panic!(
"Lexer is infinitely recursing with this code: ->{}<-",
string
"Lexer is infinitely recursing with this code: ->{string}<-"
)
});

Expand Down
5 changes: 2 additions & 3 deletions crates/biome_css_parser/src/syntax/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ pub(crate) fn expected_non_css_wide_keyword_identifier(
// two details being added, but since we're adding the hint as well, we
// only want to show one code frame.
ParseDiagnostic::new(
format!("Expected an identifier but instead found '{}'", text),
format!("Expected an identifier but instead found '{text}'"),
range,
)
.with_hint(format!(
"'{}' is a CSS-wide keyword that cannot be used here",
text
"'{text}' is a CSS-wide keyword that cannot be used here"
))
} else {
expected_identifier(p, range)
Expand Down
12 changes: 3 additions & 9 deletions crates/biome_css_parser/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,12 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_
.descendants()
.any(|node| node.kind().is_bogus())
{
panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes: \n {formatted_ast:#?} \n\n {}", formatted_ast);
panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes: \n {formatted_ast:#?} \n\n {formatted_ast}");
}

let syntax = parsed.syntax();
if has_bogus_nodes_or_empty_slots(&syntax) {
panic!(
"modified tree has bogus nodes or empty slots:\n{syntax:#?} \n\n {}",
syntax
)
panic!("modified tree has bogus nodes or empty slots:\n{syntax:#?} \n\n {syntax}")
}
}
ExpectedOutcome::Fail => {
Expand Down Expand Up @@ -188,9 +185,6 @@ pub fn quick_test() {
let syntax = root.syntax();
dbg!(&syntax, root.diagnostics(), root.has_errors());
if has_bogus_nodes_or_empty_slots(&syntax) {
panic!(
"modified tree has bogus nodes or empty slots:\n{syntax:#?} \n\n {}",
syntax
)
panic!("modified tree has bogus nodes or empty slots:\n{syntax:#?} \n\n {syntax}")
}
}
2 changes: 1 addition & 1 deletion crates/biome_deserialize/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl std::fmt::Display for VisitableType {
VisitableType::MAP => "an object",
_ => unreachable!("Unhandled deserialization type."),
};
write!(fmt, "{}", expected_type)?;
write!(fmt, "{expected_type}")?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_diagnostics/src/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Diagnostic for BpafError {

fn description(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let bpaf::ParseFailure::Stderr(reason) = &self.error {
write!(fmt, "{}", reason)?;
write!(fmt, "{reason}")?;
}
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_diagnostics/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ impl FromStr for Severity {
"warn" => Ok(Self::Warning),
"error" => Ok(Self::Error),
v => Err(format!(
"Found unexpected value ({}), valid values are: info, warn, error.",
v
"Found unexpected value ({v}), valid values are: info, warn, error."
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_diagnostics/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<D: Diagnostic + ?Sized> fmt::Display for PrintHeader<'_, D> {
} else {
let path_name = Path::new(name);
if path_name.is_absolute() {
let link = format!("file://{}", name);
let link = format!("file://{name}");
fmt.write_markup(markup! {
<Hyperlink href={link}>{name}</Hyperlink>
})?;
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_diagnostics/src/display/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ pub(super) fn print_backtrace(

if let Some(lineno) = symbol.lineno() {
// SAFETY: Writing a `u32` to a string should not fail
write!(text, ":{}", lineno).unwrap();
write!(text, ":{lineno}").unwrap();

if let Some(colno) = symbol.colno() {
// SAFETY: Writing a `u32` to a string should not fail
write!(text, ":{}", colno).unwrap();
write!(text, ":{colno}").unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_diagnostics/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl std::fmt::Display for PanicError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let r = f.write_fmt(format_args!("{}\n", self.info));
if let Some(backtrace) = &self.backtrace {
f.write_fmt(format_args!("Backtrace: {}", backtrace))
f.write_fmt(format_args!("Backtrace: {backtrace}"))
} else {
r
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl std::fmt::Debug for LocatedTokenText {
}

fn debug_assert_no_newlines(text: &str) {
debug_assert!(!text.contains('\r'), "The content '{}' contains an unsupported '\\r' line terminator character but text must only use line feeds '\\n' as line separator. Use '\\n' instead of '\\r' and '\\r\\n' to insert a line break in strings.", text);
debug_assert!(!text.contains('\r'), "The content '{text}' contains an unsupported '\\r' line terminator character but text must only use line feeds '\\n' as line separator. Use '\\n' instead of '\\r' and '\\r\\n' to insert a line break in strings.");
}

/// Pushes some content to the end of the current line
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_formatter/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Diagnostic for PrintError {
fn message(&self, fmt: &mut Formatter<'_>) -> std::io::Result<()> {
match self {
PrintError::InvalidDocument(inner) => {
let inner = format!("{}", inner);
let inner = format!("{inner}");
fmt.write_markup(markup! {
"Invalid document: "{{inner}}
})
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl biome_console::fmt::Display for IndentWidth {
impl Display for IndentWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let value = self.value();
f.write_str(&std::format!("{}", value))
f.write_str(&std::format!("{value}"))
}
}

Expand Down Expand Up @@ -364,7 +364,7 @@ impl biome_console::fmt::Display for LineWidth {
impl Display for LineWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let value = self.value();
f.write_str(&std::format!("{}", value))
f.write_str(&std::format!("{value}"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/biome_formatter_test/src/diff_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl DiffReport {
}

let line = line.strip_suffix('\n').unwrap_or(line);
writeln!(diff, "{}{}", tag, line).unwrap();
writeln!(diff, "{tag}{line}").unwrap();
}

let ratio = matched_lines as f64 / biome_lines.max(prettier_lines) as f64;
Expand Down Expand Up @@ -402,7 +402,7 @@ impl DiffReport {
diff,
} in report_metric_data.files.iter()
{
writeln!(report, "### {}", filename).unwrap();
writeln!(report, "### {filename}").unwrap();

if let Some(diff) = diff {
writeln!(report, "```diff").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_formatter_test/src/snapshot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> SnapshotBuilder<'a> {
writeln!(self.snapshot).unwrap();

writeln!(self.snapshot, "-----").unwrap();
write!(self.snapshot, "{}", options).unwrap();
write!(self.snapshot, "{options}").unwrap();
writeln!(self.snapshot, "-----").unwrap();
writeln!(self.snapshot).unwrap();

Expand Down Expand Up @@ -128,7 +128,7 @@ impl<'a> SnapshotBuilder<'a> {
writeln!(self.snapshot).unwrap();

for (range, text) in formatted.verbatim() {
writeln!(self.snapshot, "{:?} => {:?}", text, range).unwrap();
writeln!(self.snapshot, "{text:?} => {range:?}").unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_formatter_test/src/test_prettier_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> PrettierTestFile<'a> {
);

let mut input_code = read_to_string(input_file)
.unwrap_or_else(|err| panic!("failed to read {:?}: {:?}", input_file, err));
.unwrap_or_else(|err| panic!("failed to read {input_file:?}: {err:?}"));

let (_, range_start_index, range_end_index) = strip_prettier_placeholders(&mut input_code);
let parse_input = input_code.replace(PRETTIER_IGNORE, BIOME_IGNORE);
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_formatter_test/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn get_prettier_diff(
let input_extension = input_file.extension().and_then(OsStr::to_str);

let prettier_snapshot_path = input_extension
.map(|ext| input_file.with_extension(format!("{}.prettier-snap", ext)))
.map(|ext| input_file.with_extension(format!("{ext}.prettier-snap")))
.filter(|path| path.exists());

let prettier_snapshot_path = prettier_snapshot_path.expect("failed to find prettier snapshot");
Expand All @@ -128,14 +128,14 @@ pub fn get_prettier_diff(
// The output matches prettier's output. There's no need for a snapshot that duplicates the output.
// Delete the snapshot file if it already exists, otherwise return early to not create a new snapshot.
if let Some(input_extension) = input_extension {
let snapshot_file_name = input_file.with_extension(format!("{}.snap", input_extension));
let snapshot_file_name = input_file.with_extension(format!("{input_extension}.snap"));

if snapshot_file_name.exists() && snapshot_file_name.is_file() {
remove_file(snapshot_file_name).ok(); // not the end of the world if it fails
}

let new_snapshot_file_name =
input_file.with_extension(format!("{}.snap.new", input_extension));
input_file.with_extension(format!("{input_extension}.snap.new"));
if new_snapshot_file_name.exists() && new_snapshot_file_name.is_file() {
remove_file(new_snapshot_file_name).ok(); // not the end of the world if it fails
}
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl Advices for ErrorKind {
match self {
ErrorKind::CantReadFile(path) => visitor.record_log(
LogCategory::Error,
&format!("Biome can't read the following file, maybe for permissions reasons or it doesn't exist: {}", path)
&format!("Biome can't read the following file, maybe for permissions reasons or it doesn't exist: {path}")
),

ErrorKind::UnknownFileType => visitor.record_log(
Expand All @@ -446,11 +446,11 @@ impl Advices for ErrorKind {
),
ErrorKind::DereferencedSymlink(path) => visitor.record_log(
LogCategory::Info,
&format!("Biome encountered a file system entry that is a broken symbolic link: {}", path),
&format!("Biome encountered a file system entry that is a broken symbolic link: {path}"),
),
ErrorKind::DeeplyNestedSymlinkExpansion(path) => visitor.record_log(
LogCategory::Error,
&format!("Biome encountered a file system entry with too many nested symbolic links, possibly forming an infinite cycle: {}", path),
&format!("Biome encountered a file system entry with too many nested symbolic links, possibly forming an infinite cycle: {path}"),
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl FileSystem for OsFileSystem {
// R: renamed
// Source: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
.arg("--diff-filter=ACMR")
.arg(format!("{}...HEAD", base))
.arg(format!("{base}...HEAD"))
.output()?;

Ok(String::from_utf8_lossy(&output.stdout)
Expand Down
9 changes: 3 additions & 6 deletions crates/biome_graphql_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) {
let extension = input_file.extension().unwrap_or_default();

let input_code = read_to_string(input_file)
.unwrap_or_else(|err| panic!("failed to read {:?}: {:?}", input_file, err));
.unwrap_or_else(|err| panic!("failed to read {input_file:?}: {err:?}"));
let quantity_diagnostics = if let Some(scripts) = scripts_from_json(extension, &input_code) {
for script in scripts {
analyze_and_snap(
Expand Down Expand Up @@ -174,10 +174,7 @@ fn check_code_action(
assert_eq!(new_tree.to_string(), output);

if has_bogus_nodes_or_empty_slots(&new_tree) {
panic!(
"modified tree has bogus nodes or empty slots:\n{new_tree:#?} \n\n {}",
new_tree
)
panic!("modified tree has bogus nodes or empty slots:\n{new_tree:#?} \n\n {new_tree}")
}

// Checks the returned tree contains no missing children node
Expand All @@ -196,7 +193,7 @@ pub(crate) fn _run_suppression_test(input: &'static str, _: &str, _: &str, _: &s
let input_file = Path::new(input);
let file_name = input_file.file_name().and_then(OsStr::to_str).unwrap();
let input_code = read_to_string(input_file)
.unwrap_or_else(|err| panic!("failed to read {:?}: {:?}", input_file, err));
.unwrap_or_else(|err| panic!("failed to read {input_file:?}: {err:?}"));

let (group, rule) = parse_test_path(input_file);

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_graphql_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<'src> GraphqlLexer<'src> {

let char = self.current_char_unchecked();
let err = ParseDiagnostic::new(
format!("unexpected character `{}`", char),
format!("unexpected character `{char}`"),
self.text_position()..self.text_position() + char.text_len(),
);
self.diagnostics.push(err);
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_graphql_parser/src/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ fn losslessness(string: String) -> bool {
.recv_timeout(Duration::from_secs(2))
.unwrap_or_else(|_| {
panic!(
"Lexer is infinitely recursing with this code: ->{}<-",
string
"Lexer is infinitely recursing with this code: ->{string}<-"
)
});

Expand Down
Loading
Loading