refactor: unify the usage of std::fmt import

This commit is contained in:
Boshen 2023-04-27 22:21:16 +08:00
parent b6d00e5a6e
commit f0066ea4cc
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
6 changed files with 30 additions and 28 deletions

View file

@ -1,4 +1,4 @@
use std::fmt::Display;
use std::fmt;
use num_bigint::BigUint;
use oxc_allocator::{Box, Vec};
@ -947,8 +947,8 @@ impl VariableDeclarationKind {
}
}
impl Display for VariableDeclarationKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl fmt::Display for VariableDeclarationKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::Var => "var",
Self::Const => "const",
@ -1805,8 +1805,8 @@ pub enum ModuleExportName {
StringLiteral(StringLiteral),
}
impl Display for ModuleExportName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl fmt::Display for ModuleExportName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::Identifier(identifier) => identifier.name.to_string(),
Self::StringLiteral(literal) => literal.value.to_string(),

View file

@ -1,4 +1,4 @@
use std::fmt::{Display, Formatter, Result};
use std::fmt;
#[cfg(feature = "serde")]
use serde::Serialize;
@ -135,8 +135,8 @@ impl AssignmentOperator {
}
}
impl Display for AssignmentOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
impl fmt::Display for AssignmentOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let operator = self.as_str();
write!(f, "{operator}")
}
@ -278,8 +278,8 @@ impl BinaryOperator {
}
}
impl Display for BinaryOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
impl fmt::Display for BinaryOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let operator = self.as_str();
write!(f, "{operator}")
}
@ -307,8 +307,8 @@ impl LogicalOperator {
}
}
impl Display for LogicalOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
impl fmt::Display for LogicalOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let operator = self.as_str();
write!(f, "{operator}")
}
@ -368,8 +368,8 @@ impl UnaryOperator {
}
}
impl Display for UnaryOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
impl fmt::Display for UnaryOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let operator = self.as_str();
write!(f, "{operator}")
}
@ -394,8 +394,8 @@ impl UpdateOperator {
}
}
impl Display for UpdateOperator {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
impl fmt::Display for UpdateOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let operator = self.as_str();
write!(f, "{operator}")
}

View file

@ -1,3 +1,5 @@
use std::fmt;
use serde::{ser::Serializer, Serialize};
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>
where
T: std::fmt::Display,
T: fmt::Display,
S: serde::Serializer,
{
s.collect_str(&format_args!("{value}n"))

View file

@ -1,4 +1,4 @@
use std::fmt::Display;
use std::fmt;
use oxc_allocator::{Box, Vec};
use oxc_ast::ast::{
@ -951,8 +951,8 @@ impl VariableDeclarationKind {
}
}
impl Display for VariableDeclarationKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl fmt::Display for VariableDeclarationKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::Var => "var",
Self::Const => "const",
@ -1809,8 +1809,8 @@ pub enum ModuleExportName {
StringLiteral(StringLiteral),
}
impl Display for ModuleExportName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl fmt::Display for ModuleExportName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::Identifier(identifier) => identifier.name.to_string(),
Self::StringLiteral(literal) => literal.value.to_string(),

View file

@ -1,10 +1,10 @@
use std::fmt::{Debug, Display};
use std::fmt;
use oxc_semantic::Symbol;
use crate::{context::LintContext, AstNode};
pub trait Rule: Sized + Default + Debug {
pub trait Rule: Sized + Default + fmt::Debug {
/// Initialize from eslint json configuration
#[must_use]
fn from_configuration(_value: serde_json::Value) -> Self {
@ -54,8 +54,8 @@ impl RuleCategory {
}
}
impl Display for RuleCategory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl fmt::Display for RuleCategory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Correctness => write!(f, "Correctness"),
Self::Restriction => write!(f, "Restriction"),

View file

@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{fmt, str::FromStr};
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:?}")
}