Skip to content

Commit

Permalink
chore: improve some format by running cargo +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 18, 2024
1 parent e592883 commit 051ceb6
Show file tree
Hide file tree
Showing 483 changed files with 1,443 additions and 1,073 deletions.
4 changes: 2 additions & 2 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub enum OutputFormat {

impl FromStr for OutputFormat {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"json" => Ok(Self::Json),
Expand Down Expand Up @@ -251,8 +252,7 @@ mod warning_options {

#[cfg(test)]
mod lint_options {
use std::fs::File;
use std::path::PathBuf;
use std::{fs::File, path::PathBuf};

use oxc_linter::AllowWarnDeny;

Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod ignore;
mod lint;

use bpaf::Bpaf;
use std::path::PathBuf;

use bpaf::Bpaf;

pub use self::{
ignore::IgnoreOptions,
lint::{lint_command, LintCommand, OutputFormat, OutputOptions, WarningOptions},
Expand Down Expand Up @@ -64,8 +65,7 @@ fn expand_glob(paths: Vec<PathBuf>) -> Vec<PathBuf> {

#[cfg(test)]
mod misc_options {
use super::lint::lint_command;
use super::MiscOptions;
use super::{lint::lint_command, MiscOptions};

fn get_misc_options(arg: &str) -> MiscOptions {
let args = arg.split(' ').map(std::string::ToString::to_string).collect::<Vec<_>>();
Expand Down
6 changes: 4 additions & 2 deletions apps/oxlint/src/lint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ignore::gitignore::Gitignore;
use std::{env, io::BufWriter, time::Instant};

use ignore::gitignore::Gitignore;
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler};
use oxc_linter::{
partial_loader::LINT_PARTIAL_LOADER_EXT, LintOptions, LintService, LintServiceOptions, Linter,
Expand Down Expand Up @@ -122,7 +122,9 @@ impl Runner for LintRunner {
if !path.is_file() {
let path = if path.is_relative() { cwd.join(path) } else { path.clone() };
return CliRunResult::InvalidOptions {
message: format!("The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.", ),
message: format!(
"The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.",
),
};
}
}
Expand Down
3 changes: 1 addition & 2 deletions apps/oxlint/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ impl Walk {
mod test {
use std::{env, ffi::OsString};

use crate::IgnoreOptions;

use super::{Extensions, Walk};
use crate::IgnoreOptions;

#[test]
fn test_walk_with_extensions() {
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ impl DerefMut for Allocator {
mod test {
use std::ops::Deref;

use crate::Allocator;
use bumpalo::Bump;

use crate::Allocator;

#[test]
fn test_api() {
let bump = Bump::new();
Expand Down
7 changes: 5 additions & 2 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use serde::Serialize;
#[cfg(feature = "serialize")]
use tsify::Tsify;

use super::inherit_variants;
use super::{jsx::*, literal::*, ts::*};
use super::{inherit_variants, jsx::*, literal::*, ts::*};

#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
Expand Down Expand Up @@ -1173,6 +1172,7 @@ impl<'a> AssignmentTarget<'a> {
pub fn get_identifier(&self) -> Option<&str> {
self.as_simple_assignment_target().and_then(|it| it.get_identifier())
}

pub fn get_expression(&self) -> Option<&Expression<'a>> {
self.as_simple_assignment_target().and_then(|it| it.get_expression())
}
Expand Down Expand Up @@ -2937,12 +2937,15 @@ impl MethodDefinitionKind {
pub fn is_constructor(&self) -> bool {
matches!(self, Self::Constructor)
}

pub fn is_method(&self) -> bool {
matches!(self, Self::Method)
}

pub fn is_set(&self) -> bool {
matches!(self, Self::Set)
}

pub fn is_get(&self) -> bool {
matches!(self, Self::Get)
}
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast/src/ast/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use serde::Serialize;
#[cfg(feature = "serialize")]
use tsify::Tsify;

use super::{js::*, literal::*, ts::*};

use super::inherit_variants;
use super::{inherit_variants, js::*, literal::*, ts::*};

// 1.2 JSX Elements

Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ mod literal;
mod macros;
mod ts;

pub use self::{js::*, jsx::*, literal::*, ts::*};
use macros::inherit_variants;

pub use self::{js::*, jsx::*, literal::*, ts::*};
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ pub use crate::{
#[cfg(target_pointer_width = "64")]
#[test]
fn size_asserts() {
use crate::ast;
use static_assertions::assert_eq_size;

use crate::ast;

assert_eq_size!(ast::Statement, [u8; 16]);
assert_eq_size!(ast::Expression, [u8; 16]);
assert_eq_size!(ast::Declaration, [u8; 16]);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use oxc_allocator::{Box, Vec};
use oxc_span::Span;
use serde::{
ser::{SerializeSeq, Serializer},
Serialize,
Expand All @@ -9,8 +11,6 @@ use crate::ast::{
Elision, FormalParameter, FormalParameterKind, FormalParameters, ObjectAssignmentTarget,
ObjectPattern, Program, RegExpFlags, TSTypeAnnotation,
};
use oxc_allocator::{Box, Vec};
use oxc_span::Span;

pub struct EcmaFormatter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ast::*;
use oxc_span::Atom;

use crate::ast::*;

// TODO: <https://github.com/babel/babel/blob/419644f27c5c59deb19e71aaabd417a3bc5483ca/packages/babel-traverse/src/scope/index.ts#L61>
pub trait GatherNodeParts<'a> {
fn gather<F: FnMut(Atom<'a>)>(&self, f: &mut F);
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/visit/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
use oxc_allocator::Vec;
use oxc_syntax::scope::ScopeFlags;
use walk::*;

use crate::{ast::*, ast_kind::AstKind};

use walk::*;

/// Syntax tree traversal
pub trait Visit<'a>: Sized {
#[allow(unused_variables)]
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/visit/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
use oxc_allocator::Vec;
use oxc_syntax::scope::ScopeFlags;

use crate::{ast::*, AstType};

#[allow(clippy::wildcard_imports)]
use self::walk_mut::*;
use crate::{ast::*, AstType};

/// Syntax tree traversal to mutate an exclusive borrow of a syntax tree in place.
pub trait VisitMut<'a>: Sized {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_cfg/src/builder/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{BasicBlockId, EdgeType};

use super::ControlFlowGraphBuilder;
use crate::{BasicBlockId, EdgeType};

bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -181,6 +180,7 @@ impl<'a, 'c> RefCtxCursor<'a, 'c> {
self.0.flags.insert(CtxFlags::BREAK);
self
}

/// Allow continue entries in this context.
pub fn allow_continue(self) -> Self {
self.0.flags.insert(CtxFlags::CONTINUE);
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_cfg/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod context;

use crate::ReturnInstructionKind;
use context::Ctx;

pub use context::{CtxCursor, CtxFlags};
use oxc_syntax::node::AstNodeId;
use petgraph::Direction;
Expand All @@ -11,6 +9,7 @@ use super::{
BasicBlock, BasicBlockId, ControlFlowGraph, EdgeType, ErrorEdgeKind, Graph, Instruction,
InstructionKind, IterationInstructionKind, LabeledInstruction,
};
use crate::ReturnInstructionKind;

#[derive(Debug, Default)]
struct ErrorHarness(ErrorEdgeKind, BasicBlockId);
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_cfg/src/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use petgraph::{
visit::EdgeRef,
};

use super::IterationInstructionKind;
use crate::{
BasicBlock, ControlFlowGraph, EdgeType, Instruction, InstructionKind, LabeledInstruction,
ReturnInstructionKind,
};

use super::IterationInstructionKind;

pub trait DisplayDot {
fn display_dot(&self) -> String;
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_cfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use petgraph::{
pub mod graph {
pub use petgraph::*;
pub mod visit {
pub use super::super::visit::*;
pub use petgraph::visit::*;

pub use super::super::visit::*;
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use oxc_syntax::{
precedence::{GetPrecedence, Precedence},
};

use crate::annotation_comment::{gen_comment, get_leading_annotate_comment};
use crate::{Codegen, Context, Operator};
use crate::{
annotation_comment::{gen_comment, get_leading_annotate_comment},
Codegen, Context, Operator,
};

pub trait Gen<const MINIFY: bool> {
fn gen(&self, _p: &mut Codegen<{ MINIFY }>, _ctx: Context) {}
Expand Down
13 changes: 6 additions & 7 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ mod sourcemap_builder;

use std::{borrow::Cow, ops::Range};

use rustc_hash::FxHashMap;

use oxc_ast::ast::{BlockStatement, Directive, Expression, Program, Statement};
use oxc_ast::{Comment, Trivias};
use oxc_ast::{
ast::{BlockStatement, Directive, Expression, Program, Statement},
Comment, Trivias,
};
use oxc_span::{Atom, Span};
use oxc_syntax::{
identifier::is_identifier_part,
operator::{BinaryOperator, UnaryOperator, UpdateOperator},
precedence::Precedence,
symbol::SymbolId,
};

use crate::operator::Operator;
use crate::sourcemap_builder::SourcemapBuilder;
use rustc_hash::FxHashMap;

pub use crate::{
context::Context,
gen::{Gen, GenExpr},
};
use crate::{operator::Operator, sourcemap_builder::SourcemapBuilder};

/// Code generator without whitespace removal.
pub type CodeGenerator<'a> = Codegen<'a, false>;
Expand Down
12 changes: 10 additions & 2 deletions crates/oxc_codegen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ fn for_stmt() {
fn typescript() {
test_ts("let x: string = `\\x01`;", "let x: string = `\\x01`;\n", false);

test_ts("function foo<T extends string>(x: T, y: string, ...restOfParams: Omit<T, 'x'>): T {\n\treturn x;\n}", "function foo<T extends string>(x: T, y: string, ...restOfParams: Omit<T, 'x'>): T {\n\treturn x;\n}\n", false);
test_ts(
"function foo<T extends string>(x: T, y: string, ...restOfParams: Omit<T, 'x'>): T {\n\treturn x;\n}",
"function foo<T extends string>(x: T, y: string, ...restOfParams: Omit<T, 'x'>): T {\n\treturn x;\n}\n",
false,
);

test_ts(
"let x: string[] = ['abc', 'def', 'ghi'];",
Expand Down Expand Up @@ -167,7 +171,11 @@ fn typescript() {
);
test_ts("let x: string['length'] = 123;", "let x: string['length'] = 123;\n", false);

test_ts("function isString(value: unknown): asserts value is string {\n\tif (typeof value !== 'string') {\n\t\tthrow new Error('Not a string');\n\t}\n}", "function isString(value: unknown): asserts value is string {\n\tif (typeof value !== 'string') {\n\t\tthrow new Error('Not a string');\n\t}\n}\n", false);
test_ts(
"function isString(value: unknown): asserts value is string {\n\tif (typeof value !== 'string') {\n\t\tthrow new Error('Not a string');\n\t}\n}",
"function isString(value: unknown): asserts value is string {\n\tif (typeof value !== 'string') {\n\t\tthrow new Error('Not a string');\n\t}\n}\n",
false,
);

// type-only imports/exports
test_ts("import type { Foo } from 'foo';", "import type { Foo } from 'foo';\n", false);
Expand Down
5 changes: 2 additions & 3 deletions crates/oxc_diagnostics/src/graphic_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
/// origin file: https://github.com/zkat/miette/blob/75fea0935e495d0215518c80d32dd820910982e3/src/handlers/graphical.rs#L1
use std::fmt::{self, Write};

use owo_colors::{OwoColorize, Style};
use unicode_width::UnicodeWidthChar;

use miette::{
Diagnostic, LabeledSpan, ReportHandler, Severity, SourceCode, SourceSpan, SpanContents,
ThemeCharacters,
};
use owo_colors::{OwoColorize, Style};
use unicode_width::UnicodeWidthChar;

use crate::graphical_theme::GraphicalTheme;

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct OxcDiagnostic {

impl Deref for OxcDiagnostic {
type Target = Box<OxcDiagnosticInner>;

fn deref(&self) -> &Self::Target {
&self.inner
}
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_diagnostics/src/reporter/checkstyle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{borrow::Cow, collections::HashMap};

use crate::{Error, Severity};

use super::{DiagnosticReporter, Info};
use crate::{Error, Severity};

#[derive(Default)]
pub struct CheckstyleReporter {
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_diagnostics/src/reporter/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::{
io::{BufWriter, Stdout, Write},
};

use crate::{Error, Severity};

use super::{writer, DiagnosticReporter, Info};
use crate::{Error, Severity};

pub struct GithubReporter {
writer: BufWriter<Stdout>,
Expand Down Expand Up @@ -40,7 +39,9 @@ fn format_github(diagnostic: &Error) -> String {
let title = rule_id.map_or(Cow::Borrowed("oxlint"), Cow::Owned);
let filename = escape_property(&filename);
let message = escape_data(&message);
format!("::{severity} file={filename},line={line},endLine={line},col={column},endColumn={column},title={title}::{message}\n")
format!(
"::{severity} file={filename},line={line},endLine={line},col={column},endColumn={column},title={title}::{message}\n"
)
}

fn escape_data(value: &str) -> String {
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_diagnostics/src/reporter/graphical.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io::{BufWriter, Stdout, Write};

use crate::{Error, GraphicalReportHandler};

use super::{writer, DiagnosticReporter};
use crate::{Error, GraphicalReportHandler};

pub struct GraphicalReporter {
handler: GraphicalReportHandler,
Expand Down
Loading

0 comments on commit 051ceb6

Please sign in to comment.