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: replace biome_rowan::* type into biome type #3431

Merged
merged 5 commits into from
Jul 16, 2024
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 @@ -7,11 +7,11 @@ use biome_console::markup;
use biome_js_factory::make;
use biome_js_syntax::{
AnyJsImportClause, AnyJsModuleItem, AnyJsNamedImportSpecifier, JsImport, JsLanguage, JsModule,
JsSyntaxToken, TextRange, TriviaPieceKind, T,
JsSyntaxToken, JsSyntaxTrivia, TextRange, TriviaPieceKind, T,
};
use biome_rowan::{
chain_trivia_pieces, syntax::SyntaxTrivia, AstNode, AstNodeExt, AstNodeList, AstSeparatedList,
BatchMutationExt, SyntaxTriviaPiece, TokenText, TriviaPiece,
chain_trivia_pieces, AstNode, AstNodeExt, AstNodeList, AstSeparatedList, BatchMutationExt,
SyntaxTriviaPiece, TokenText, TriviaPiece,
};

use crate::JsRuleAction;
Expand Down Expand Up @@ -667,7 +667,7 @@ fn is_ascii_whitespace(piece: &SyntaxTriviaPiece<JsLanguage>) -> bool {
}

/// Returns true if the provided trivia contains an empty line (two consecutive newline pieces, ignoring whitespace)
fn has_empty_line(trivia: &SyntaxTrivia<JsLanguage>) -> bool {
fn has_empty_line(trivia: &JsSyntaxTrivia) -> bool {
let mut was_newline = false;
trivia
.pieces()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_console::markup;
use biome_deserialize_macros::Deserializable;
use biome_js_syntax::{
AnyFunctionLike, JsBreakStatement, JsContinueStatement, JsElseClause, JsLanguage,
JsLogicalExpression, JsLogicalOperator,
JsLogicalExpression, JsLogicalOperator, JsSyntaxNode,
};
use biome_rowan::{AstNode, Language, SyntaxNode, TextRange, WalkEvent};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Visitor for CognitiveComplexityVisitor {
}

impl CognitiveComplexityVisitor {
fn on_enter(&mut self, node: &SyntaxNode<JsLanguage>) {
fn on_enter(&mut self, node: &JsSyntaxNode) {
let parent = self.stack.last();
if parent
.map(|parent| parent.score == MAX_SCORE)
Expand Down Expand Up @@ -259,7 +259,7 @@ impl CognitiveComplexityVisitor {
}
}

fn on_leave(&mut self, node: &SyntaxNode<JsLanguage>, mut ctx: VisitorContext<JsLanguage>) {
fn on_leave(&mut self, node: &JsSyntaxNode, mut ctx: VisitorContext<JsLanguage>) {
if let Some(exit_node) = AnyFunctionLike::cast_ref(node) {
if let Some(function_state) = self.stack.pop() {
if function_state.function_like == exit_node {
Expand Down Expand Up @@ -299,7 +299,7 @@ impl CognitiveComplexityVisitor {
///
/// Note: These are mostly nodes that increase the complexity of the function's
/// control flow.
fn increases_nesting(node: &SyntaxNode<JsLanguage>) -> bool {
fn increases_nesting(node: &JsSyntaxNode) -> bool {
use biome_js_syntax::JsSyntaxKind::*;
is_loop_node(node)
|| matches!(
Expand All @@ -308,7 +308,7 @@ fn increases_nesting(node: &SyntaxNode<JsLanguage>) -> bool {
)
}

fn is_loop_node(node: &SyntaxNode<JsLanguage>) -> bool {
fn is_loop_node(node: &JsSyntaxNode) -> bool {
use biome_js_syntax::JsSyntaxKind::*;
matches!(
node.kind(),
Expand All @@ -335,7 +335,7 @@ fn is_loop_node(node: &SyntaxNode<JsLanguage>) -> bool {
/// Do note that the SonarSource paper makes no mention of the `with` statement
/// specifically (probably because it's highly specific to JavaScript), so its
/// inclusion here is a personal judgement call.
fn receives_structural_penalty(node: &SyntaxNode<JsLanguage>) -> bool {
fn receives_structural_penalty(node: &JsSyntaxNode) -> bool {
use biome_js_syntax::JsSyntaxKind::*;
receives_nesting_penalty(node)
|| matches!(node.kind(), JS_FINALLY_CLAUSE | JS_WITH_STATEMENT)
Expand All @@ -351,7 +351,7 @@ fn receives_structural_penalty(node: &SyntaxNode<JsLanguage>) -> bool {
/// on the level of nesting in which it occurs.
///
/// Note: This is a strict subset of the nodes that receive a structural penalty.
fn receives_nesting_penalty(node: &SyntaxNode<JsLanguage>) -> bool {
fn receives_nesting_penalty(node: &JsSyntaxNode) -> bool {
use biome_js_syntax::JsSyntaxKind::*;
is_loop_node(node)
|| matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use biome_js_syntax::{
AnyFunctionLike, AnyJsBinding, AnyJsExpression, AnyJsFunction, AnyJsObjectMemberName,
JsArrayAssignmentPatternElement, JsArrayBindingPatternElement, JsCallExpression,
JsConditionalExpression, JsIfStatement, JsLanguage, JsLogicalExpression, JsMethodObjectMember,
JsObjectBindingPatternShorthandProperty, JsReturnStatement, JsSyntaxKind,
JsObjectBindingPatternShorthandProperty, JsReturnStatement, JsSyntaxKind, JsSyntaxNode,
JsTryFinallyStatement, TextRange,
};
use biome_rowan::{declare_node_union, AstNode, Language, SyntaxNode, WalkEvent};
Expand Down Expand Up @@ -148,10 +148,7 @@ fn enclosing_function_if_call_is_at_top_level(
/// // ^^^^^^^^---------------------------- This node is always executed.
/// // ^^^^^^^^^^---^^^^^^^^^--- These nodes are conditionally executed.
/// ```
fn is_conditional_expression(
parent_node: &SyntaxNode<JsLanguage>,
node: &SyntaxNode<JsLanguage>,
) -> bool {
fn is_conditional_expression(parent_node: &JsSyntaxNode, node: &JsSyntaxNode) -> bool {
if let Some(assignment_with_default) = JsArrayAssignmentPatternElement::cast_ref(parent_node) {
return assignment_with_default
.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_js_factory::make::js_variable_declarator_list;
use biome_js_syntax::{JsLanguage, JsVariableDeclarator, JsVariableStatement};
use biome_rowan::{chain_trivia_pieces, SyntaxToken, SyntaxTriviaPiece};
use biome_js_syntax::{JsLanguage, JsSyntaxToken, JsVariableDeclarator, JsVariableStatement};
use biome_rowan::{chain_trivia_pieces, SyntaxTriviaPiece};
use biome_rowan::{AstNode, BatchMutationExt, TextRange};

use crate::JsRuleAction;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Rule for NoUselessUndefinedInitialization {

// Save the separators too
let separators_syntax = declarators.clone().into_syntax();
let separators: Vec<SyntaxToken<JsLanguage>> = separators_syntax.tokens().collect();
let separators: Vec<JsSyntaxToken> = separators_syntax.tokens().collect();

let new_declaration = current_declaration.clone().with_initializer(None);
let new_declarators: Vec<JsVariableDeclarator> = declarators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use biome_analyze::{
use biome_console::markup;
use biome_deserialize_macros::Deserializable;
use biome_js_factory::make;
use biome_js_syntax::{inner_string_text, AnyJsImportLike, JsLanguage};
use biome_rowan::{BatchMutationExt, SyntaxToken};
use biome_js_syntax::{inner_string_text, AnyJsImportLike, JsSyntaxToken};
use biome_rowan::BatchMutationExt;

use crate::JsRuleAction;

Expand Down Expand Up @@ -203,7 +203,7 @@ impl Rule for UseImportExtensions {

pub struct UseImportExtensionsState {
suggestion: Option<(String, String)>,
module_name_token: SyntaxToken<JsLanguage>,
module_name_token: JsSyntaxToken,
}

fn get_extensionless_import(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use biome_analyze::{
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make;
use biome_js_syntax::{AnyTsType, JsLanguage, JsSyntaxKind, TsConditionalType, TsVoidType, T};
use biome_rowan::{AstNode, BatchMutationExt, SyntaxNode};
use biome_js_syntax::{AnyTsType, JsSyntaxKind, JsSyntaxNode, TsConditionalType, TsVoidType, T};
use biome_rowan::{AstNode, BatchMutationExt};

use crate::JsRuleAction;

Expand Down Expand Up @@ -115,7 +115,7 @@ impl Rule for NoConfusingVoidType {
}
}

fn decide_void_type_context(node: &SyntaxNode<JsLanguage>) -> Option<VoidTypeContext> {
fn decide_void_type_context(node: &JsSyntaxNode) -> Option<VoidTypeContext> {
for parent in node.parent()?.ancestors() {
match parent.kind() {
JsSyntaxKind::TS_UNION_TYPE_VARIANT_LIST => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use biome_analyze::{
};
use biome_console::{markup, MarkupBuf};
use biome_js_syntax::{
AnyJsClassMember, AnyTsType, AnyTsTypeMember, JsClassDeclaration, JsLanguage,
AnyJsClassMember, AnyTsType, AnyTsTypeMember, JsClassDeclaration, JsSyntaxToken,
TsDeclareStatement, TsInterfaceDeclaration, TsReferenceType, TsTypeAliasDeclaration,
};
use biome_rowan::{declare_node_union, AstNode, SyntaxToken, TextRange};
use biome_rowan::{declare_node_union, AstNode, TextRange};

declare_lint_rule! {
/// Enforce proper usage of `new` and `constructor`.
Expand Down Expand Up @@ -230,7 +230,7 @@ fn check_type_alias(decl: &TsTypeAliasDeclaration) -> Option<RuleState> {
}

/// Extracts the identifier from a reference type.
fn extract_return_type_ident(reference_type: &TsReferenceType) -> Option<SyntaxToken<JsLanguage>> {
fn extract_return_type_ident(reference_type: &TsReferenceType) -> Option<JsSyntaxToken> {
reference_type
.name()
.ok()?
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_js_analyze/src/react/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use biome_js_syntax::{
AnyJsMemberExpression, JsArrowFunctionExpression, JsCallExpression, JsFunctionExpression,
TextRange,
};
use biome_js_syntax::{JsArrayBindingPatternElement, JsLanguage};
use biome_rowan::{AstNode, SyntaxToken};
use biome_js_syntax::{JsArrayBindingPatternElement, JsSyntaxToken};
use biome_rowan::AstNode;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -110,7 +110,7 @@ impl From<(u8, u8, bool)> for ReactHookConfiguration {
}
}

fn get_untrimmed_callee_name(call: &JsCallExpression) -> Option<SyntaxToken<JsLanguage>> {
fn get_untrimmed_callee_name(call: &JsCallExpression) -> Option<JsSyntaxToken> {
let callee = call.callee().ok()?;

if let Some(identifier) = callee.as_js_identifier_expression() {
Expand Down
14 changes: 3 additions & 11 deletions crates/biome_js_analyze/src/services/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use biome_analyze::{
};
use biome_js_semantic::{SemanticEventExtractor, SemanticModel, SemanticModelBuilder};
use biome_js_syntax::{AnyJsRoot, JsLanguage, JsSyntaxNode, TextRange, WalkEvent};
use biome_rowan::{AstNode, SyntaxNode};
use biome_rowan::AstNode;

pub struct SemanticServices {
model: SemanticModel,
Expand Down Expand Up @@ -103,11 +103,7 @@ impl SemanticModelBuilderVisitor {
impl Visitor for SemanticModelBuilderVisitor {
type Language = JsLanguage;

fn visit(
&mut self,
event: &WalkEvent<SyntaxNode<JsLanguage>>,
_ctx: VisitorContext<JsLanguage>,
) {
fn visit(&mut self, event: &WalkEvent<JsSyntaxNode>, _ctx: VisitorContext<JsLanguage>) {
match event {
WalkEvent::Enter(node) => {
self.builder.push_node(node);
Expand Down Expand Up @@ -142,11 +138,7 @@ impl QueryMatch for SemanticModelEvent {
impl Visitor for SemanticModelVisitor {
type Language = JsLanguage;

fn visit(
&mut self,
event: &WalkEvent<SyntaxNode<JsLanguage>>,
mut ctx: VisitorContext<JsLanguage>,
) {
fn visit(&mut self, event: &WalkEvent<JsSyntaxNode>, mut ctx: VisitorContext<JsLanguage>) {
let root = match event {
WalkEvent::Enter(node) => {
if node.parent().is_some() {
Expand Down
5 changes: 2 additions & 3 deletions crates/biome_js_formatter/src/syntax_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::parentheses::AnyJsParenthesized;
use biome_formatter::{TransformSourceMap, TransformSourceMapBuilder};
use biome_js_syntax::{
AnyJsAssignment, AnyJsExpression, AnyJsOptionalChainExpression, AnyTsType, JsLanguage,
JsLogicalExpression, JsSyntaxKind, JsSyntaxNode,
JsLogicalExpression, JsSyntaxKind, JsSyntaxNode, JsSyntaxTrivia,
};
use biome_rowan::syntax::SyntaxTrivia;
use biome_rowan::{
chain_trivia_pieces, AstNode, SyntaxKind, SyntaxRewriter, SyntaxToken, TextSize,
VisitNodeSignal,
Expand Down Expand Up @@ -447,7 +446,7 @@ impl SyntaxRewriter for JsFormatSyntaxRewriter {
}
}

fn has_type_cast_comment_or_skipped(trivia: &SyntaxTrivia<JsLanguage>) -> bool {
fn has_type_cast_comment_or_skipped(trivia: &JsSyntaxTrivia) -> bool {
trivia.pieces().any(|piece| {
if let Some(comment) = piece.as_comments() {
is_type_comment(&comment)
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_js_semantic/src/semantic_model/closure.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::*;
use biome_js_syntax::{
JsArrowFunctionExpression, JsConstructorClassMember, JsFunctionDeclaration,
JsFunctionExpression, JsGetterClassMember, JsGetterObjectMember, JsLanguage,
JsMethodClassMember, JsMethodObjectMember, JsSetterClassMember, JsSetterObjectMember,
JsFunctionExpression, JsGetterClassMember, JsGetterObjectMember, JsMethodClassMember,
JsMethodObjectMember, JsSetterClassMember, JsSetterObjectMember,
};
use biome_rowan::{AstNode, SyntaxNode, SyntaxNodeCast};
use biome_rowan::{AstNode, SyntaxNodeCast};
use std::rc::Rc;

/// Marker trait that groups all "AstNode" that have closure
Expand Down Expand Up @@ -32,7 +32,7 @@ macro_rules! SyntaxTextRangeHasClosureAstNode {
}

impl AnyHasClosureNode {
pub fn from_node(node: &SyntaxNode<JsLanguage>) -> Option<AnyHasClosureNode> {
pub fn from_node(node: &JsSyntaxNode) -> Option<AnyHasClosureNode> {
match node.kind() {
$(
JsSyntaxKind::$kind => node
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Capture {
}

/// Returns the reference node of the capture
pub fn node(&self) -> &SyntaxNode<JsLanguage> {
pub fn node(&self) -> &JsSyntaxNode {
&self.node
}

Expand Down
Loading