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(js_syntax): separate AnyJsImportLike and AnyJsImportSourceLike #4600

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::globals::is_node_builtin_module;
use crate::services::manifest::Manifest;
use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{inner_string_text, AnyJsImportClause, AnyJsImportLike};
use biome_js_syntax::{inner_string_text, AnyJsImportClause, AnyJsImportSourceLike};
use biome_rowan::AstNode;
use biome_rowan::TextRange;

Expand Down Expand Up @@ -47,7 +47,7 @@ declare_lint_rule! {
}

impl Rule for NoNodejsModules {
type Query = Manifest<AnyJsImportLike>;
type Query = Manifest<AnyJsImportSourceLike>;
type State = TextRange;
type Signals = Option<Self::State>;
type Options = ();
Expand All @@ -57,7 +57,7 @@ impl Rule for NoNodejsModules {
if node.is_in_ts_module_declaration() {
return None;
}
if let AnyJsImportLike::JsModuleSource(module_source) = &node {
if let AnyJsImportSourceLike::JsModuleSource(module_source) = &node {
if let Some(import_clause) = module_source.parent::<AnyJsImportClause>() {
if import_clause.type_token().is_some() {
// Ignore type-only imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnosti
use biome_console::markup;
use biome_deserialize::{Deserializable, DeserializableType};
use biome_deserialize_macros::Deserializable;
use biome_js_syntax::{AnyJsImportClause, AnyJsImportLike};
use biome_js_syntax::{AnyJsImportClause, AnyJsImportSourceLike};
use biome_rowan::AstNode;

use crate::utils::restricted_glob::{CandidatePath, RestrictedGlob};
Expand Down Expand Up @@ -199,7 +199,7 @@ pub struct RuleState {
}

impl Rule for NoUndeclaredDependencies {
type Query = Manifest<AnyJsImportLike>;
type Query = Manifest<AnyJsImportSourceLike>;
type State = RuleState;
type Signals = Option<Self::State>;
type Options = NoUndeclaredDependenciesOptions;
Expand All @@ -223,7 +223,7 @@ impl Rule for NoUndeclaredDependencies {
|| (is_optional_dependency_available && ctx.is_optional_dependency(package_name))
};

let token_text = node.inner_string_text()?;
let token_text = node.module_source_text()?;
let package_name = parse_package_name(token_text.text())?;
if is_available(package_name)
// Self package imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, FixKind, Rule,
use biome_console::markup;
use biome_deserialize_macros::Deserializable;
use biome_js_factory::make;
use biome_js_syntax::{inner_string_text, AnyJsImportLike, JsSyntaxToken};
use biome_js_syntax::{inner_string_text, AnyJsImportSourceLike, JsSyntaxToken};
use biome_rowan::BatchMutationExt;

use crate::JsRuleAction;
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct SuggestedExtensionMapping {
}

impl Rule for UseImportExtensions {
type Query = Ast<AnyJsImportLike>;
type Query = Ast<AnyJsImportSourceLike>;
type State = UseImportExtensionsState;
type Signals = Option<Self::State>;
type Options = Box<UseImportExtensionsOptions>;
Expand Down Expand Up @@ -205,7 +205,7 @@ pub struct UseImportExtensionsState {

fn get_extensionless_import(
file_ext: &str,
node: &AnyJsImportLike,
node: &AnyJsImportSourceLike,
custom_suggested_imports: &FxHashMap<Box<str>, SuggestedExtensionMapping>,
) -> Option<UseImportExtensionsState> {
let module_name_token = node.module_name_token()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use biome_analyze::context::RuleContext;
use biome_analyze::{declare_lint_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_deserialize_macros::Deserializable;
use biome_js_syntax::{inner_string_text, AnyJsImportLike};
use biome_js_syntax::{inner_string_text, AnyJsImportSourceLike};
use biome_rowan::TextRange;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct RestrictedImportsOptions {
}

impl Rule for NoRestrictedImports {
type Query = Ast<AnyJsImportLike>;
type Query = Ast<AnyJsImportSourceLike>;
type State = (TextRange, String);
type Signals = Option<Self::State>;
type Options = Box<RestrictedImportsOptions>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::JsRuleAction;
use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, FixKind, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_js_syntax::{inner_string_text, AnyJsImportLike, JsSyntaxKind, JsSyntaxToken};
use biome_js_syntax::{inner_string_text, AnyJsImportSourceLike, JsSyntaxKind, JsSyntaxToken};
use biome_rowan::BatchMutationExt;

declare_lint_rule! {
Expand Down Expand Up @@ -33,7 +33,7 @@ declare_lint_rule! {
}

impl Rule for UseNodeAssertStrict {
type Query = Ast<AnyJsImportLike>;
type Query = Ast<AnyJsImportSourceLike>;
type State = JsSyntaxToken;
type Signals = Option<Self::State>;
type Options = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use biome_analyze::{
context::RuleContext, declare_lint_rule, FixKind, Rule, RuleDiagnostic, RuleSource,
};
use biome_console::markup;
use biome_js_syntax::{inner_string_text, AnyJsImportLike, JsSyntaxKind, JsSyntaxToken};
use biome_js_syntax::{inner_string_text, AnyJsImportSourceLike, JsSyntaxKind, JsSyntaxToken};
use biome_rowan::BatchMutationExt;

use crate::services::manifest::Manifest;
Expand Down Expand Up @@ -58,7 +58,7 @@ declare_lint_rule! {
}

impl Rule for UseNodejsImportProtocol {
type Query = Manifest<AnyJsImportLike>;
type Query = Manifest<AnyJsImportSourceLike>;
type State = JsSyntaxToken;
type Signals = Option<Self::State>;
type Options = ();
Expand Down
Loading
Loading