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

style(rust): cargo +nightly fmt #7877

Merged
merged 1 commit into from
Dec 14, 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
4 changes: 3 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use_small_heuristics = "Max"
# Use field initialize shorthand if possible
use_field_init_shorthand = true

reorder_modules = true

# All unstable features that we wish for
# unstable_features = true
# version = "Two"
# style_edition = "2024"
# Provide a cleaner impl order
# reorder_impl_items = true
# Provide a cleaner import sort order
Expand Down
3 changes: 2 additions & 1 deletion apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ impl EnablePlugins {

#[cfg(test)]
mod plugins {
use super::{EnablePlugins, OverrideToggle};
use oxc_linter::LintPlugins;

use super::{EnablePlugins, OverrideToggle};

#[test]
fn test_override_default() {
let mut plugins = LintPlugins::default();
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use oxc_allocator::{Allocator, Box, FromIn, String, Vec};
use oxc_span::{Atom, GetSpan, Span, SPAN};
use oxc_syntax::{number::NumberBase, operator::UnaryOperator, scope::ScopeId};

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

/// Type that can be used in any AST builder method call which requires an `IntoIn<'a, Anything<'a>>`.
/// Pass `NONE` instead of `None::<Anything<'a>>`.
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ impl<'a> Declaration<'a> {
_ => true,
}
}

/// Get the identifier bound by this declaration.
///
/// ## Example
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cow_utils::CowUtils;
use num_bigint::BigInt;
use num_traits::Num;

use oxc_allocator::Box;
use oxc_span::{Atom, Span};
use oxc_syntax::number::BigintBase;
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_codegen/src/comment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc_hash::FxHashMap;

use oxc_ast::{Comment, CommentKind};
use oxc_syntax::identifier::is_line_terminator;
use rustc_hash::FxHashMap;

use crate::{Codegen, LegalComment};

Expand Down
45 changes: 32 additions & 13 deletions crates/oxc_codegen/tests/integration/esbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ fn test_new() {
"new Worker(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );",
"new Worker(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n",
);
test( "new Worker(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))",
"new Worker(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n");
test(
"new Worker(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))",
"new Worker(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n",
);

// non-webpack comments
test("new Worker(/* before */ foo)", "new Worker(\n\t/* before */\n\tfoo\n);\n");
Expand Down Expand Up @@ -252,14 +254,18 @@ fn test_call() {
"require(// webpackFoo: 1\n // webpackBar: 2\n 'path');",
"require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\"\n);\n",
);
test( "require(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});",
"require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n");
test(
"require(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});",
"require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n",
);
test(
"require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path');",
"require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\"\n);\n",
);
test( "require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});",
"require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n");
test(
"require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});",
"require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n",
);
test(
"require(\n /* multi\n * line\n * webpackBar: */ 'path');",
"require(\n\t/* multi\n\t* line\n\t* webpackBar: */\n\t\"path\"\n);\n",
Expand All @@ -276,7 +282,10 @@ fn test_call() {
"require(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );",
"require(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n",
);
test( "require(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", "require(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n");
test(
"require(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );",
"require(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n",
);

// non-webpack comments
test("require(/* before */ foo)", "require(\n\t/* before */\n\tfoo\n);\n");
Expand Down Expand Up @@ -668,13 +677,18 @@ fn test_import() {
"import(// webpackFoo: 1\n // webpackBar: 2\n 'path');",
"import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\"\n);\n",
);
test( "import(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});", "import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n");
test(
"import(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});",
"import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n",
);
test(
"import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path');",
"import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\"\n);\n",
);
test( "import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});",
"import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n");
test(
"import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});",
"import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n",
);
test(
"import(\n /* multi\n * line\n * webpackBar: */ 'path');",
"import(\n\t/* multi\n\t* line\n\t* webpackBar: */\n\t\"path\"\n);\n",
Expand All @@ -691,9 +705,14 @@ fn test_import() {
"import(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );",
"import(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n",
);
test( "import(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", "import(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n");
test( "import(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))",
"import(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n");
test(
"import(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );",
"import(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n",
);
test(
"import(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))",
"import(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n",
);

// non-webpack comments
test("import(/* before */ foo)", "import(\n\t/* before */\n\tfoo\n);\n");
Expand Down
13 changes: 7 additions & 6 deletions crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{snapshot, snapshot_options};
use oxc_codegen::CodegenOptions;

use crate::{snapshot, snapshot_options};

#[test]
fn ts() {
let cases = [
Expand Down Expand Up @@ -52,10 +53,10 @@ export type Component<
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
| ComponentPublicInstanceConstructor<Props>
",
"(a || b) as any",
"(a ** b) as any",
"(function g() {}) as any",
r#"
"(a || b) as any",
"(a ** b) as any",
"(function g() {}) as any",
r#"
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
Expand Down Expand Up @@ -88,7 +89,7 @@ export { name12, /* …, */ nameN } from "module-name";
export { import1 as name13, import2 as name14, /* …, */ name15 } from "module-name";
export { default, /* …, */ } from "module-name";
export { default as name16 } from "module-name";
"#
"#,
];

snapshot("ts", &cases);
Expand Down
9 changes: 4 additions & 5 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ impl<T> Default for SparseStack<T> {
}

impl<T> SparseStack<T> {
/// Maximum capacity for entries (either `Some` or `None`).
///
/// Effectively unlimited on 64-bit systems.
pub const MAX_TOTAL_CAPACITY: usize = NonEmptyStack::<bool>::MAX_CAPACITY;

/// Maximum capacity for filled entries (`Some`).
///
/// Unless `size_of::<T>() == 1`, `MAX_FILLED_CAPACITY` is lower than [`MAX_TOTAL_CAPACITY`].
Expand All @@ -50,6 +45,10 @@ impl<T> SparseStack<T> {
///
/// [`MAX_TOTAL_CAPACITY`]: Self::MAX_TOTAL_CAPACITY
pub const MAX_FILLED_CAPACITY: usize = Stack::<T>::MAX_CAPACITY;
/// Maximum capacity for entries (either `Some` or `None`).
///
/// Effectively unlimited on 64-bit systems.
pub const MAX_TOTAL_CAPACITY: usize = NonEmptyStack::<bool>::MAX_CAPACITY;

/// Create new `SparseStack`.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_diagnostics/src/reporter/checkstyle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::borrow::Cow;

use rustc_hash::FxHashMap;

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

#[derive(Default)]
pub struct CheckstyleReporter {
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_ecmascript/src/array_join.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ToJsString;
use oxc_ast::ast::*;

use crate::ToJsString;

pub trait ArrayJoin<'a> {
/// `Array.prototype.join ( separator )`
/// <https://tc39.es/ecma262/#sec-array.prototype.join>
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ecmascript/src/constant_evaluation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ use std::{borrow::Cow, cmp::Ordering};

use num_bigint::BigInt;
use num_traits::Zero;

use oxc_ast::ast::*;

use crate::{side_effects::MayHaveSideEffects, ToBigInt, ToBoolean, ToInt32, ToJsString, ToNumber};

pub use self::{is_literal_value::IsLiteralValue, value::ConstantValue, value_type::ValueType};
use crate::{side_effects::MayHaveSideEffects, ToBigInt, ToBoolean, ToInt32, ToJsString, ToNumber};

pub trait ConstantEvaluation<'a> {
fn is_global_reference(&self, ident: &IdentifierReference<'a>) -> bool {
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ecmascript/src/string_to_big_int.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use num_traits::Zero;

use num_bigint::BigInt;
use num_traits::Zero;

/// `StringToBigInt`
///
Expand Down
12 changes: 2 additions & 10 deletions crates/oxc_ecmascript/src/to_big_int.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use num_bigint::BigInt;
use num_traits::{One, Zero};

use oxc_ast::ast::{BigIntLiteral, Expression};
use oxc_syntax::operator::UnaryOperator;

Expand Down Expand Up @@ -35,15 +34,8 @@ impl<'a> ToBigInt<'a> for Expression<'a> {
}
Expression::UnaryExpression(unary_expr) => match unary_expr.operator {
UnaryOperator::LogicalNot => {
self.to_boolean().map(
|boolean| {
if boolean {
BigInt::one()
} else {
BigInt::zero()
}
},
)
self.to_boolean()
.map(|boolean| if boolean { BigInt::one() } else { BigInt::zero() })
}
UnaryOperator::UnaryNegation => {
unary_expr.argument.to_big_int().map(std::ops::Neg::neg)
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ecmascript/src/to_string.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::borrow::Cow;

use crate::array_join::ArrayJoin;
use crate::ToBoolean;
use oxc_ast::ast::*;
use oxc_syntax::operator::UnaryOperator;

use crate::{array_join::ArrayJoin, ToBoolean};

/// `ToString`
///
/// <https://tc39.es/ecma262/#sec-tostring>
Expand Down
8 changes: 3 additions & 5 deletions crates/oxc_isolated_declarations/src/declaration.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use std::cell::Cell;

use oxc_allocator::{Box, CloneIn, Vec};
use oxc_ast::ast::*;
use oxc_ast::visit::walk_mut::walk_ts_signatures;
use oxc_ast::{Visit, VisitMut};
use oxc_ast::{ast::*, visit::walk_mut::walk_ts_signatures, Visit, VisitMut};
use oxc_ecmascript::BoundNames;
use oxc_span::{GetSpan, SPAN};
use oxc_syntax::scope::ScopeFlags;

use crate::diagnostics::accessor_must_have_explicit_return_type;
use crate::{
diagnostics::{
binding_element_export, inferred_type_of_expression, signature_computed_property_name,
accessor_must_have_explicit_return_type, binding_element_export,
inferred_type_of_expression, signature_computed_property_name,
variable_must_have_explicit_type,
},
IsolatedDeclarations,
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_isolated_declarations/src/enum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use rustc_hash::FxHashMap;

use oxc_allocator::CloneIn;
use oxc_ast::ast::*;
use oxc_ecmascript::ToInt32;
Expand All @@ -8,6 +6,7 @@ use oxc_syntax::{
number::{NumberBase, ToJsString},
operator::{BinaryOperator, UnaryOperator},
};
use rustc_hash::FxHashMap;

use crate::{diagnostics::enum_member_initializers, IsolatedDeclarations};

Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{Atom, GetSpan, SourceType, SPAN};
use rustc_hash::{FxHashMap, FxHashSet};

use crate::scope::ScopeTree;
use diagnostics::function_with_assigning_properties;
use crate::{diagnostics::function_with_assigning_properties, scope::ScopeTree};

#[derive(Debug, Default, Clone, Copy)]
pub struct IsolatedDeclarationsOptions {
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_isolated_declarations/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use oxc_allocator::Box;
use oxc_allocator::CloneIn;
use oxc_allocator::Vec;
use oxc_allocator::{Box, CloneIn, Vec};
use oxc_ast::{ast::*, NONE};
use oxc_span::{Atom, GetSpan, SPAN};

Expand Down
8 changes: 3 additions & 5 deletions crates/oxc_isolated_declarations/src/scope.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use bitflags::bitflags;
use rustc_hash::FxHashMap;

use std::cell::Cell;

use oxc_ast::ast::*;
use oxc_ast::{visit::walk::*, Visit};
use bitflags::bitflags;
use oxc_ast::{ast::*, visit::walk::*, Visit};
use oxc_span::Atom;
use oxc_syntax::scope::{ScopeFlags, ScopeId};
use rustc_hash::FxHashMap;

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_isolated_declarations/src/signatures.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use rustc_hash::FxHashMap;

use oxc_allocator::{CloneIn, Vec};
use oxc_ast::ast::{TSMethodSignatureKind, TSSignature};
use oxc_span::GetSpan;
use rustc_hash::FxHashMap;

use crate::IsolatedDeclarations;

Expand Down
14 changes: 6 additions & 8 deletions crates/oxc_language_server/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ use std::{

use cow_utils::CowUtils;
use log::debug;
use rustc_hash::FxHashSet;
use tower_lsp::lsp_types::{
self, CodeDescription, DiagnosticRelatedInformation, DiagnosticSeverity, NumberOrString,
Position, Range, Url,
};

use oxc_allocator::Allocator;
use oxc_data_structures::rope::{get_line_column, Rope};
use oxc_diagnostics::{Error, NamedSource, Severity};
use oxc_linter::loader::LINT_PARTIAL_LOADER_EXT;
use oxc_linter::{
loader::{JavaScriptSource, Loader},
loader::{JavaScriptSource, Loader, LINT_PARTIAL_LOADER_EXT},
FixKind, Linter, ModuleRecord,
};
use oxc_parser::{ParseOptions, Parser};
use oxc_semantic::SemanticBuilder;
use oxc_span::VALID_EXTENSIONS;
use rustc_hash::FxHashSet;
use tower_lsp::lsp_types::{
self, CodeDescription, DiagnosticRelatedInformation, DiagnosticSeverity, NumberOrString,
Position, Range, Url,
};

const LINT_DOC_LINK_PREFIX: &str = "https://oxc.rs/docs/guide/usage/linter/rules";
#[derive(Debug)]
Expand Down
Loading
Loading