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 committed Jun 25, 2024
1 parent 187f078 commit df5f905
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 @@ -1370,19 +1370,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 @@ -128,6 +128,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 @@ -520,6 +521,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 df5f905

Please sign in to comment.