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

feat(linter): add eslint/sort-imports rule #3568

Merged
merged 1 commit into from
Jun 11, 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
16 changes: 16 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3068,6 +3068,22 @@ pub enum ImportDeclarationSpecifier<'a> {
ImportNamespaceSpecifier(Box<'a, ImportNamespaceSpecifier<'a>>),
}

impl<'a> ImportDeclarationSpecifier<'a> {
pub fn name(&self) -> CompactStr {
match self {
ImportDeclarationSpecifier::ImportSpecifier(specifier) => {
specifier.local.name.to_compact_str()
}
ImportDeclarationSpecifier::ImportNamespaceSpecifier(specifier) => {
specifier.local.name.to_compact_str()
}
ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => {
specifier.local.name.to_compact_str()
}
}
}
}

// import {imported} from "source"
// import {imported as local} from "source"
#[visited_node]
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ mod eslint {
pub mod radix;
pub mod require_await;
pub mod require_yield;
pub mod sort_imports;
pub mod symbol_description;
pub mod unicode_bom;
pub mod use_isnan;
Expand Down Expand Up @@ -490,6 +491,7 @@ oxc_macros::declare_all_lint_rules! {
eslint::radix,
eslint::require_yield,
eslint::symbol_description,
eslint::sort_imports,
eslint::unicode_bom,
eslint::use_isnan,
eslint::valid_typeof,
Expand Down
Loading