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

refactor(parser/js): rename import assertions to import attributes #4373

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
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ fn remove_import_specifier(
let default_specifier = default_extra_clause.default_specifier().ok()?;
let from_token = default_extra_clause.from_token().ok()?;
let source = default_extra_clause.source().ok()?;
let assertion = default_extra_clause.assertion();
let assertion = default_extra_clause.attribute();
if default_specifier.syntax() == specifier {
let new_clause = match default_extra_clause.specifier().ok()? {
AnyJsCombinedSpecifier::JsNamedImportSpecifiers(named_specifier) => {
let named_clause =
make::js_import_named_clause(named_specifier, from_token, source);
let named_clause = if let Some(assertion) = assertion {
named_clause.with_assertion(assertion)
named_clause.with_attribute(assertion)
} else {
named_clause
};
Expand All @@ -198,7 +198,7 @@ fn remove_import_specifier(
source,
);
let namespace_clause = if let Some(assertion) = assertion {
namespace_clause.with_assertion(assertion)
namespace_clause.with_attribute(assertion)
} else {
namespace_clause
};
Expand All @@ -212,7 +212,7 @@ fn remove_import_specifier(
let default_clause =
make::js_import_default_clause(default_specifier, from_token, source);
let default_clause = if let Some(assertion) = assertion {
default_clause.with_assertion(assertion)
default_clause.with_attribute(assertion)
} else {
default_clause
};
Expand Down
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())
}
})
}
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/style/use_import_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ impl Rule for UseImportType {
}
let import = ctx.query();
let import_clause = import.import_clause().ok()?;
if import_clause.assertion().is_some() {
if import_clause.attribute().is_some() {
return None;
}
// 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