mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor: unify the usage of std::fmt import
This commit is contained in:
parent
b6d00e5a6e
commit
f0066ea4cc
6 changed files with 30 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::fmt::Display;
|
use std::fmt;
|
||||||
|
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use oxc_allocator::{Box, Vec};
|
use oxc_allocator::{Box, Vec};
|
||||||
|
|
@ -947,8 +947,8 @@ impl VariableDeclarationKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for VariableDeclarationKind {
|
impl fmt::Display for VariableDeclarationKind {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Self::Var => "var",
|
Self::Var => "var",
|
||||||
Self::Const => "const",
|
Self::Const => "const",
|
||||||
|
|
@ -1805,8 +1805,8 @@ pub enum ModuleExportName {
|
||||||
StringLiteral(StringLiteral),
|
StringLiteral(StringLiteral),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ModuleExportName {
|
impl fmt::Display for ModuleExportName {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Self::Identifier(identifier) => identifier.name.to_string(),
|
Self::Identifier(identifier) => identifier.name.to_string(),
|
||||||
Self::StringLiteral(literal) => literal.value.to_string(),
|
Self::StringLiteral(literal) => literal.value.to_string(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::fmt::{Display, Formatter, Result};
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
@ -135,8 +135,8 @@ impl AssignmentOperator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for AssignmentOperator {
|
impl fmt::Display for AssignmentOperator {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let operator = self.as_str();
|
let operator = self.as_str();
|
||||||
write!(f, "{operator}")
|
write!(f, "{operator}")
|
||||||
}
|
}
|
||||||
|
|
@ -278,8 +278,8 @@ impl BinaryOperator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for BinaryOperator {
|
impl fmt::Display for BinaryOperator {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let operator = self.as_str();
|
let operator = self.as_str();
|
||||||
write!(f, "{operator}")
|
write!(f, "{operator}")
|
||||||
}
|
}
|
||||||
|
|
@ -307,8 +307,8 @@ impl LogicalOperator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for LogicalOperator {
|
impl fmt::Display for LogicalOperator {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let operator = self.as_str();
|
let operator = self.as_str();
|
||||||
write!(f, "{operator}")
|
write!(f, "{operator}")
|
||||||
}
|
}
|
||||||
|
|
@ -368,8 +368,8 @@ impl UnaryOperator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for UnaryOperator {
|
impl fmt::Display for UnaryOperator {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let operator = self.as_str();
|
let operator = self.as_str();
|
||||||
write!(f, "{operator}")
|
write!(f, "{operator}")
|
||||||
}
|
}
|
||||||
|
|
@ -394,8 +394,8 @@ impl UpdateOperator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for UpdateOperator {
|
impl fmt::Display for UpdateOperator {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let operator = self.as_str();
|
let operator = self.as_str();
|
||||||
write!(f, "{operator}")
|
write!(f, "{operator}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use serde::{ser::Serializer, Serialize};
|
use serde::{ser::Serializer, Serialize};
|
||||||
|
|
||||||
use crate::ast::{Program, RegExpFlags};
|
use crate::ast::{Program, RegExpFlags};
|
||||||
|
|
@ -29,7 +31,7 @@ impl<'a> Program<'a> {
|
||||||
|
|
||||||
pub fn serialize_bigint<T, S>(value: &T, s: S) -> Result<S::Ok, S::Error>
|
pub fn serialize_bigint<T, S>(value: &T, s: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
T: std::fmt::Display,
|
T: fmt::Display,
|
||||||
S: serde::Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
s.collect_str(&format_args!("{value}n"))
|
s.collect_str(&format_args!("{value}n"))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::fmt::Display;
|
use std::fmt;
|
||||||
|
|
||||||
use oxc_allocator::{Box, Vec};
|
use oxc_allocator::{Box, Vec};
|
||||||
use oxc_ast::ast::{
|
use oxc_ast::ast::{
|
||||||
|
|
@ -951,8 +951,8 @@ impl VariableDeclarationKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for VariableDeclarationKind {
|
impl fmt::Display for VariableDeclarationKind {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Self::Var => "var",
|
Self::Var => "var",
|
||||||
Self::Const => "const",
|
Self::Const => "const",
|
||||||
|
|
@ -1809,8 +1809,8 @@ pub enum ModuleExportName {
|
||||||
StringLiteral(StringLiteral),
|
StringLiteral(StringLiteral),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ModuleExportName {
|
impl fmt::Display for ModuleExportName {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Self::Identifier(identifier) => identifier.name.to_string(),
|
Self::Identifier(identifier) => identifier.name.to_string(),
|
||||||
Self::StringLiteral(literal) => literal.value.to_string(),
|
Self::StringLiteral(literal) => literal.value.to_string(),
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt;
|
||||||
|
|
||||||
use oxc_semantic::Symbol;
|
use oxc_semantic::Symbol;
|
||||||
|
|
||||||
use crate::{context::LintContext, AstNode};
|
use crate::{context::LintContext, AstNode};
|
||||||
|
|
||||||
pub trait Rule: Sized + Default + Debug {
|
pub trait Rule: Sized + Default + fmt::Debug {
|
||||||
/// Initialize from eslint json configuration
|
/// Initialize from eslint json configuration
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn from_configuration(_value: serde_json::Value) -> Self {
|
fn from_configuration(_value: serde_json::Value) -> Self {
|
||||||
|
|
@ -54,8 +54,8 @@ impl RuleCategory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for RuleCategory {
|
impl fmt::Display for RuleCategory {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Correctness => write!(f, "Correctness"),
|
Self::Correctness => write!(f, "Correctness"),
|
||||||
Self::Restriction => write!(f, "Restriction"),
|
Self::Restriction => write!(f, "Restriction"),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::str::FromStr;
|
use std::{fmt, str::FromStr};
|
||||||
|
|
||||||
use crate::project_root;
|
use crate::project_root;
|
||||||
|
|
||||||
|
|
@ -79,6 +79,6 @@ impl TestFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn err_to_string<E: std::fmt::Debug>(e: E) -> String {
|
fn err_to_string<E: fmt::Debug>(e: E) -> String {
|
||||||
format!("{e:?}")
|
format!("{e:?}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue