Skip to content
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
23 changes: 13 additions & 10 deletions crates/oxc_cfg/src/dot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{borrow::Cow, fmt};
use std::{
borrow::Cow,
fmt::{self, Debug, Display},
};

use itertools::Itertools as _;
use petgraph::{
Expand Down Expand Up @@ -104,12 +107,12 @@ impl<'a> Attr<'a> {
}
}

impl fmt::Debug for Attr<'_> {
impl Debug for Attr<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Int(i) => write!(f, "{i}"),
Self::String(s) => write!(f, "{s:?}"),
Self::Identifier(ident) => write!(f, "{ident}"), // display instead of debug
Self::Int(i) => Display::fmt(i, f),
Self::String(s) => Debug::fmt(s, f),
Self::Identifier(ident) => Display::fmt(ident, f), // Display instead of Debug
}
}
}
Expand Down Expand Up @@ -167,17 +170,17 @@ where
}
}

impl fmt::Debug for Attrs<'_> {
impl Debug for Attrs<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.0.is_empty() {
return Ok(());
}

let l = self.0.len();
for (i, (k, v)) in self.0.iter().enumerate() {
write!(f, "{k}={v:?}")?;
if i < l - 1 {
write!(f, ", ")?;
if i == 0 {
write!(f, "{k}={v:?}")?;
} else {
write!(f, ", {k}={v:?}")?;
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl OxcCode {
}
}

impl fmt::Display for OxcCode {
impl Display for OxcCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match (&self.scope, &self.number) {
(Some(scope), Some(number)) => write!(f, "{scope}({number})"),
Expand All @@ -126,9 +126,9 @@ pub struct OxcDiagnosticInner {
pub url: Option<Cow<'static, str>>,
}

impl fmt::Display for OxcDiagnostic {
impl Display for OxcDiagnostic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.message)
self.message.fmt(f)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_parser/src/lexer/kind.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! ECMAScript Token Kinds

use std::fmt;
use std::fmt::{self, Display};

/// Lexer token kind
///
Expand Down Expand Up @@ -693,8 +693,8 @@ impl Kind {
}
}

impl fmt::Display for Kind {
impl Display for Kind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_str())
self.to_str().fmt(f)
}
}
2 changes: 1 addition & 1 deletion crates/oxc_syntax/src/es_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ impl fmt::Display for ESTarget {
Self::ES2025 => "es2025",
Self::ESNext => "esnext",
};
write!(f, "{s}",)
f.write_str(s)
}
}
33 changes: 17 additions & 16 deletions tasks/rulegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,22 +621,23 @@ impl RuleKind {

impl Display for RuleKind {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::ESLint => write!(f, "eslint"),
Self::Typescript => write!(f, "typescript-eslint"),
Self::Jest => write!(f, "eslint-plugin-jest"),
Self::Unicorn => write!(f, "eslint-plugin-unicorn"),
Self::Import => write!(f, "eslint-plugin-import"),
Self::React => write!(f, "eslint-plugin-react"),
Self::ReactPerf => write!(f, "eslint-plugin-react-perf"),
Self::JSXA11y => write!(f, "eslint-plugin-jsx-a11y"),
Self::Oxc => write!(f, "oxc"),
Self::NextJS => write!(f, "eslint-plugin-next"),
Self::JSDoc => write!(f, "eslint-plugin-jsdoc"),
Self::Node => write!(f, "eslint-plugin-n"),
Self::Promise => write!(f, "eslint-plugin-promise"),
Self::Vitest => write!(f, "eslint-plugin-vitest"),
}
let kind_name = match self {
Self::ESLint => "eslint",
Self::Typescript => "typescript-eslint",
Self::Jest => "eslint-plugin-jest",
Self::Unicorn => "eslint-plugin-unicorn",
Self::Import => "eslint-plugin-import",
Self::React => "eslint-plugin-react",
Self::ReactPerf => "eslint-plugin-react-perf",
Self::JSXA11y => "eslint-plugin-jsx-a11y",
Self::Oxc => "oxc",
Self::NextJS => "eslint-plugin-next",
Self::JSDoc => "eslint-plugin-jsdoc",
Self::Node => "eslint-plugin-n",
Self::Promise => "eslint-plugin-promise",
Self::Vitest => "eslint-plugin-vitest",
};
f.write_str(kind_name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tasks/website/src/linter/rules/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl HtmlWriter {
// Write the opening tag
write!(s, "<{tag}")?;
if attrs.is_empty() {
writeln!(s, ">")?;
s.write_str(">\n")?;
} else {
writeln!(s, " {attrs}>")?;
}
Expand Down
Loading