Skip to content

Commit b515e9c

Browse files
style(codegen, formatter, linter, minifier, transformer): re-order imports (#12725)
This PR addresses the import ordering violations identified in #12723 by fixing import ordering across key files in the codebase to follow the updated Oxc convention. ## Import Ordering Convention The correct order is: 1. `std` imports 2. External crates 3. Oxc crates (starting with `oxc_`) 4. Local crate (`crate`) 5. `super` 6. `mod` With line breaks between each category. ## Key Principle: Source Priority Imports should be imported from the closest available source: - Prefer to `use` from a local `mod` over `super` or `crate` - Prefer to `use` from `super` over `crate` This ensures we don't lose information about module structure and maintain the most direct import paths. ## Changes Made Fixed import ordering violations in 11 files based on comprehensive code review feedback, ensuring all rules from #12723 are properly applied: ### Core Applications - `apps/oxlint/src/lib.rs` - Fixed pub use positioning and mod-before-use rule compliance - `apps/oxlint/src/tester.rs` - Added required line break after imports ### Core Crates - `crates/oxc_language_server/src/main.rs` - Moved mod statements before related use statements - `crates/oxc_transformer/src/options/es_features.rs` - Added required line break after imports - Additional fixes in codegen, formatter, linter, and minifier crates ## Repository-Wide Analysis Comprehensive analysis revealed 890+ additional files with import ordering violations. However, automated fixing proved challenging due to: - Complex multi-line `use` statements with braces - Relative imports within crate modules requiring careful handling - Risk of breaking builds with overly aggressive automation ## Verification - All changes maintain proper `rustfmt` compatibility - Comprehensive build verification confirms all packages compile successfully - Source priority preserved - local module imports maintained over crate imports where appropriate - All tests pass with the updated import ordering This represents the first phase of addressing #12723, with remaining violations requiring careful manual review or enhanced tooling. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
1 parent 9e67fbd commit b515e9c

File tree

11 files changed

+47
-29
lines changed

11 files changed

+47
-29
lines changed

apps/oxlint/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
use std::{ffi::OsStr, io::BufWriter};
2+
3+
pub use oxc_linter::{
4+
ExternalLinter, ExternalLinterLintFileCb, ExternalLinterLoadPluginCb, LintFileResult,
5+
PluginLoadResult,
6+
};
7+
18
mod command;
29
mod lint;
310
mod output_formatter;
@@ -9,10 +16,7 @@ pub mod cli {
916
pub use crate::{command::*, lint::LintRunner, result::CliRunResult};
1017
}
1118

12-
pub use oxc_linter::{
13-
ExternalLinter, ExternalLinterLintFileCb, ExternalLinterLoadPluginCb, LintFileResult,
14-
PluginLoadResult,
15-
};
19+
use cli::{CliRunResult, LintRunner};
1620

1721
#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
1822
mod raw_fs;
@@ -21,9 +25,6 @@ mod raw_fs;
2125
#[global_allocator]
2226
static GLOBAL: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
2327

24-
use cli::{CliRunResult, LintRunner};
25-
use std::{ffi::OsStr, io::BufWriter};
26-
2728
pub fn lint(external_linter: Option<ExternalLinter>) -> CliRunResult {
2829
init_tracing();
2930
init_miette();

apps/oxlint/src/output_formatter/gitlab.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use std::hash::{DefaultHasher, Hash, Hasher};
2+
13
use oxc_diagnostics::{
24
Error, Severity,
35
reporter::{DiagnosticReporter, DiagnosticResult, Info},
46
};
57

6-
use std::hash::{DefaultHasher, Hash, Hasher};
7-
88
use crate::output_formatter::InternalFormatter;
99

1010
#[derive(Debug, Default)]

apps/oxlint/src/tester.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#[cfg(test)]
2-
use crate::cli::{LintRunner, lint_command};
2+
use std::{env, path::PathBuf};
3+
34
#[cfg(test)]
45
use cow_utils::CowUtils;
56
#[cfg(test)]
67
use lazy_regex::Regex;
8+
79
#[cfg(test)]
8-
use std::{env, path::PathBuf};
10+
use crate::cli::{LintRunner, lint_command};
11+
912
#[cfg(test)]
1013
pub struct Tester {
1114
cwd: PathBuf,

crates/oxc_codegen/src/comment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use rustc_hash::{FxHashMap, FxHashSet};
21
use std::borrow::Cow;
32

3+
use rustc_hash::{FxHashMap, FxHashSet};
4+
45
use oxc_ast::{Comment, CommentKind, ast::Program};
56
use oxc_syntax::identifier::is_line_terminator;
67

crates/oxc_formatter/src/utils/member_chain/groups.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
use std::cell::RefCell;
2+
3+
use oxc_span::{GetSpan, Span};
4+
15
use super::chain_member::ChainMember;
26
use crate::{
37
formatter::{Format, FormatResult, Formatter, prelude::*},
48
generated::ast_nodes::AstNode,
59
parentheses::NeedsParentheses,
610
write,
711
};
8-
use oxc_span::{GetSpan, Span};
9-
use std::cell::RefCell;
1012

1113
#[derive(Default)]
1214
pub(super) struct MemberChainGroupsBuilder<'a, 'b> {

crates/oxc_language_server/src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use std::{str::FromStr, sync::Arc};
2+
13
use futures::future::join_all;
24
use log::{debug, info, warn};
3-
use options::{Options, Run, WorkspaceOption};
45
use rustc_hash::FxBuildHasher;
56
use serde_json::json;
6-
use std::{str::FromStr, sync::Arc};
77
use tokio::sync::{OnceCell, RwLock, SetError};
88
use tower_lsp_server::{
99
Client, LanguageServer, LspService, Server,
@@ -17,11 +17,6 @@ use tower_lsp_server::{
1717
ServerInfo, Unregistration, Uri, WorkspaceEdit,
1818
},
1919
};
20-
// #
21-
use capabilities::Capabilities;
22-
use code_actions::CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC;
23-
use commands::{FIX_ALL_COMMAND_ID, FixAllCommandArgs};
24-
use worker::WorkspaceWorker;
2520

2621
mod capabilities;
2722
mod code_actions;
@@ -32,6 +27,12 @@ mod options;
3227
mod tester;
3328
mod worker;
3429

30+
use capabilities::Capabilities;
31+
use code_actions::CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC;
32+
use commands::{FIX_ALL_COMMAND_ID, FixAllCommandArgs};
33+
use options::{Options, Run, WorkspaceOption};
34+
use worker::WorkspaceWorker;
35+
3536
type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;
3637

3738
const OXC_CONFIG_FILE: &str = ".oxlintrc.json";

crates/oxc_linter/src/rules/import/no_absolute_path.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
use std::path::Path;
2+
3+
use serde_json::Value;
4+
15
use oxc_ast::{
26
AstKind,
37
ast::{Argument, Expression},
48
};
59
use oxc_diagnostics::OxcDiagnostic;
610
use oxc_macros::declare_oxc_lint;
711
use oxc_span::{GetSpan, Span};
8-
use serde_json::Value;
9-
use std::path::Path;
1012

1113
use crate::{AstNode, context::LintContext, rule::Rule};
1214

crates/oxc_linter/src/rules/react/jsx_filename_extension.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use std::ffi::OsStr;
2+
3+
use serde_json::Value;
4+
15
use oxc_ast::AstKind;
26
use oxc_diagnostics::OxcDiagnostic;
37
use oxc_macros::declare_oxc_lint;
48
use oxc_span::{CompactStr, GetSpan, Span};
5-
use serde_json::Value;
6-
use std::ffi::OsStr;
79

810
use crate::{context::LintContext, rule::Rule};
911

crates/oxc_minifier/src/peephole/replace_known_methods.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use cow_utils::CowUtils;
21
use std::borrow::Cow;
32

3+
use cow_utils::CowUtils;
4+
45
use oxc_allocator::TakeIn;
56
use oxc_ast::ast::*;
67
use oxc_ecmascript::{

crates/oxc_transformer/src/options/es_features.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Auto generated by `tasks/compat_data/src/lib.rs`.
22
#![allow(clippy::enum_glob_use, clippy::match_same_arms)]
3-
use super::{Engine, EngineTargets};
3+
4+
use std::sync::OnceLock;
5+
46
use browserslist::Version;
57
use rustc_hash::FxHashMap;
6-
use std::sync::OnceLock;
8+
9+
use super::{Engine, EngineTargets};
10+
711
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
812
pub enum ESFeature {
913
ES5MemberExpressionLiterals,

0 commit comments

Comments
 (0)