Skip to content

Commit

Permalink
feat(linter): support report `@typescript-eslint/consistent-type-impo…
Browse files Browse the repository at this point in the history
…rts` (#3895)

This PR only contains the part about report error, adding the fixer part will make the whole PR difficult to review at one time.

There are also some commented cases. One kind of them is `decorator`, as it blocked by #3645, another kind of them is type reference, need to solve #3799 first. I added TODO flags for them.
  • Loading branch information
mysteryven committed Jun 30, 2024
1 parent 3870ed5 commit b257d53
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_dynamic_delete;
Expand Down Expand Up @@ -526,6 +527,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 b257d53

Please sign in to comment.