Skip to content

Commit

Permalink
refactor(parser/js): rename import assertions to import attributes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored and ematipico committed Nov 7, 2024
1 parent a0bd960 commit 2aed596
Show file tree
Hide file tree
Showing 61 changed files with 587 additions and 582 deletions.
6 changes: 3 additions & 3 deletions crates/biome_js_analyze/src/lint/nursery/use_explicit_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn is_property_of_object_with_type(syntax: &SyntaxNode<JsLanguage>) -> bool {
/// const castTyped = <() => string>(() => '');
/// ```
fn is_type_assertion(syntax: &SyntaxNode<JsLanguage>) -> bool {
fn is_assertion_kind(kind: JsSyntaxKind) -> bool {
fn is_attribute_kind(kind: JsSyntaxKind) -> bool {
matches!(
kind,
JsSyntaxKind::TS_AS_EXPRESSION | JsSyntaxKind::TS_TYPE_ASSERTION_EXPRESSION
Expand All @@ -544,9 +544,9 @@ fn is_type_assertion(syntax: &SyntaxNode<JsLanguage>) -> bool {
if parent.kind() == JsSyntaxKind::JS_PARENTHESIZED_EXPRESSION {
parent
.parent()
.is_some_and(|grandparent| is_assertion_kind(grandparent.kind()))
.is_some_and(|grandparent| is_attribute_kind(grandparent.kind()))
} else {
is_assertion_kind(parent.kind())
is_attribute_kind(parent.kind())
}
})
}
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/lint/style/use_import_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Rule for UseImportType {
let import = ctx.query();
let import_clause = import.import_clause().ok()?;
// Import attributes and type-only imports are not compatible.
if import_clause.assertion().is_some() {
if import_clause.attribute().is_some() {
return None;
}
let model = ctx.model();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ impl Rule for NoTypeOnlyImportAttributes {
| AnyJsExportClause::TsExportAssignmentClause(_)
| AnyJsExportClause::TsExportDeclareClause(_) => None,
AnyJsExportClause::JsExportFromClause(clause) => Some(RuleState {
assertion_range: clause.assertion()?.range(),
assertion_range: clause.attribute()?.range(),
type_token_range: clause.type_token()?.text_trimmed_range(),
}),
AnyJsExportClause::JsExportNamedFromClause(clause) => {
let assertion_range = clause.assertion()?.range();
let assertion_range = clause.attribute()?.range();
let type_token = clause.type_token().or_else(|| {
clause
.specifiers()
Expand All @@ -77,7 +77,7 @@ impl Rule for NoTypeOnlyImportAttributes {
AnyJsModuleItem::JsImport(import) => match import.import_clause().ok()? {
AnyJsImportClause::JsImportBareClause(_) => None,
AnyJsImportClause::JsImportCombinedClause(clause) => {
let assertion_range = clause.assertion()?.range();
let assertion_range = clause.attribute()?.range();
let type_token = find_first_type_token(
clause.specifier().ok()?.as_js_named_import_specifiers()?,
)?;
Expand All @@ -87,11 +87,11 @@ impl Rule for NoTypeOnlyImportAttributes {
})
}
AnyJsImportClause::JsImportDefaultClause(clause) => Some(RuleState {
assertion_range: clause.assertion()?.range(),
assertion_range: clause.attribute()?.range(),
type_token_range: clause.type_token()?.text_trimmed_range(),
}),
AnyJsImportClause::JsImportNamedClause(clause) => {
let assertion_range = clause.assertion()?.range();
let assertion_range = clause.attribute()?.range();
let type_token = clause
.type_token()
.or_else(|| find_first_type_token(&clause.named_specifiers().ok()?))?;
Expand All @@ -101,7 +101,7 @@ impl Rule for NoTypeOnlyImportAttributes {
})
}
AnyJsImportClause::JsImportNamespaceClause(clause) => Some(RuleState {
assertion_range: clause.assertion()?.range(),
assertion_range: clause.attribute()?.range(),
type_token_range: clause.type_token()?.text_trimmed_range(),
}),
},
Expand Down
Loading

0 comments on commit 2aed596

Please sign in to comment.