Skip to content

Commit

Permalink
feat(linter): add @typescript-eslint/consistent-type-imports rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven authored and Boshen committed Jun 30, 2024
1 parent 9bc36ed commit 2e7389d
Show file tree
Hide file tree
Showing 4 changed files with 3,211 additions and 10 deletions.
17 changes: 7 additions & 10 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,19 +1374,16 @@ impl AccessorPropertyType {
}

impl<'a> ImportDeclarationSpecifier<'a> {
pub fn name(&self) -> CompactStr {
pub fn local(&self) -> &BindingIdentifier<'a> {
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()
}
ImportDeclarationSpecifier::ImportSpecifier(specifier) => &specifier.local,
ImportDeclarationSpecifier::ImportNamespaceSpecifier(specifier) => &specifier.local,
ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => &specifier.local,
}
}
pub fn name(&self) -> CompactStr {
self.local().name.to_compact_str()
}
}

impl<'a> ImportAttributeKey<'a> {
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 @@ -129,6 +129,7 @@ mod typescript {
pub mod ban_types;
pub mod consistent_indexed_object_style;
pub mod consistent_type_definitions;
pub mod consistent_type_imports;
pub mod explicit_function_return_type;
pub mod no_duplicate_enum_values;
pub mod no_empty_interface;
Expand Down Expand Up @@ -524,6 +525,7 @@ oxc_macros::declare_all_lint_rules! {
typescript::prefer_enum_initializers,
typescript::ban_types,
typescript::consistent_type_definitions,
typescript::consistent_type_imports,
typescript::consistent_indexed_object_style,
typescript::no_duplicate_enum_values,
typescript::no_empty_interface,
Expand Down
Loading

0 comments on commit 2e7389d

Please sign in to comment.