Skip to content
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 @@ -158,6 +158,7 @@ impl Rule for UseGenericFontNames {
fn is_in_font_face_at_rule(node: &CssGenericProperty) -> bool {
node.syntax()
.ancestors()
.skip(1)
.find(|n| n.kind() == CssSyntaxKind::CSS_AT_RULE)
.and_then(|n| n.cast::<CssAtRule>())
.and_then(|n| n.rule().ok())
Expand Down
12 changes: 6 additions & 6 deletions crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ impl Rule for NoUnknownUnit {
if unit == "x" {
let mut allow_x = false;

for ancestor in dimension.unit_token().ok()?.ancestors() {
for ancestor in dimension.unit_token().ok()?.ancestors().skip(1) {
match ancestor.kind() {
CssSyntaxKind::CSS_FUNCTION => {
let function_name_token = ancestor
.cast::<CssFunction>()?
.name()
.ok()?
.as_css_identifier()
.and_then(|name| name.value_token().ok())?;
.cast::<CssFunction>()?
.name()
.ok()?
.as_css_identifier()
.and_then(|name| name.value_token().ok())?;
let function_name = function_name_token
.text_trimmed()
.to_ascii_lowercase_cow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn is_within_not_pseudo_class(node: &AnyCssPseudoClassNth) -> bool {
let number_of_not = node
.syntax()
.ancestors()
.skip(1)
.filter_map(|n| n.cast::<CssPseudoClassFunctionSelectorList>())
.filter_map(|n| n.name().ok())
.filter_map(|n| n.value_token().ok())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Rule for NoDuplicateProperties {
if prop
.syntax()
.ancestors()
.skip(1)
.any(|node| CssKeyframesAtRule::can_cast(node.kind()))
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_html_analyze/src/lint/a11y/no_autofocus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn is_inside_allowed_context(attr: &HtmlAttribute) -> Option<bool> {
let mut skip_first_element = true;

// Walk up the ancestors to find if we're inside a dialog or popover
for ancestor in attr.syntax().ancestors() {
for ancestor in attr.syntax().ancestors().skip(1) {
let Some(tag_element) = get_tag_element(&ancestor) else {
continue;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl Rule for UseVueValidVIf {
fn find_conflicting_else_directives(v_if: &VueDirective) -> Option<TextRange> {
v_if.syntax()
.ancestors()
.skip(1)
.find_map(HtmlAttributeList::cast)?
.into_iter()
.find_map(|attr| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Rule for UseSortedAttributes {
}

fn text_range(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<TextRange> {
ctx.query().syntax().ancestors().find_map(|node| {
ctx.query().syntax().ancestors().skip(1).find_map(|node| {
JsxOpeningElement::cast_ref(&node)
.map(|element| element.range())
.or_else(|| JsxSelfClosingElement::cast_ref(&node).map(|element| element.range()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl Rule for UseSortedKeys {
ctx.query()
.syntax()
.ancestors()
.skip(1)
.find_map(JsObjectExpression::cast)
.map(|object| object.range())
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/frameworks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(crate) fn is_framework_lib_export(binding: &Binding, package_names: &[&str])
binding
.syntax()
.ancestors()
.skip(1)
.find_map(|ancestor| JsImport::cast(ancestor)?.source_text().ok())
.is_some_and(|source| package_names.contains(&source.text()))
}
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_js_analyze/src/frameworks/vue/vue_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ impl AnyVueSetupDeclaration {
&& let Some(declarator) = binding
.syntax()
.ancestors()
.skip(1)
.find_map(|syntax| JsVariableDeclarator::try_cast(syntax).ok())
&& let Some(initializer) = declarator.initializer()
&& let Some(expression) = initializer
Expand Down Expand Up @@ -781,6 +782,7 @@ impl AnyVueSetupDeclaration {
&& let Some(declarator) = binding
.syntax()
.ancestors()
.skip(1)
.find_map(|syntax| JsVariableDeclarator::try_cast(syntax).ok())
&& let Some(initializer) = declarator.initializer()
&& let Some(expression) = initializer
Expand Down Expand Up @@ -811,6 +813,7 @@ impl AnyVueSetupDeclaration {
&& let Some(declarator) = binding
.syntax()
.ancestors()
.skip(1)
.find_map(|syntax| JsVariableDeclarator::try_cast(syntax).ok())
&& let Some(decl_initializer) = declarator.initializer()
&& let Some(decl_expr) = decl_initializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl Rule for UseAriaActivedescendantWithTabindex {
let old_attribute_list = descendant_attribute
.syntax()
.ancestors()
.skip(1)
.find_map(JsxAttributeList::cast)?;

let new_attribute = jsx_attribute(AnyJsxAttributeName::JsxName(jsx_name(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Rule for NoThisInStatic {
let static_method = this_super_expression
.syntax()
.ancestors()
.skip(1)
.find(|x| {
AnyJsControlFlowRoot::can_cast(x.kind())
&& !JsArrowFunctionExpression::can_cast(x.kind())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ impl Rule for NoUselessConstructor {
return None;
}
}
let class = constructor.syntax().ancestors().find_map(AnyJsClass::cast);
let class = constructor
.syntax()
.ancestors()
.skip(1)
.find_map(AnyJsClass::cast);
if let Some(class) = &class
&& !class.decorators().is_empty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Rule for NoUselessLabel {
_ => None,
}?;
let label = label_token.text_trimmed();
for parent in stmt.syntax().ancestors() {
for parent in stmt.syntax().ancestors().skip(1) {
if is_breakable_statement_kind(parent.kind()) {
if let Some(labeled_stmt) = JsLabeledStatement::cast(parent.parent()?)
&& labeled_stmt.label_token().ok()?.text_trimmed() == label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl Rule for NoUselessThisAlias {
let this_scope = declarator
.syntax()
.ancestors()
.skip(1)
.find_map(AnyJsControlFlowRoot::cast)?;
for write in id.all_writes(model) {
let assign = JsAssignmentExpression::cast(write.syntax().parent()?)?;
Expand All @@ -106,6 +107,7 @@ impl Rule for NoUselessThisAlias {
let current_this_scope = reference
.syntax()
.ancestors()
.skip(1)
.filter(|x| !JsArrowFunctionExpression::can_cast(x.kind()))
.find_map(AnyJsControlFlowRoot::cast)?;
if this_scope != current_this_scope {
Expand Down Expand Up @@ -138,6 +140,7 @@ impl Rule for NoUselessThisAlias {
let var_decl = declarator
.syntax()
.ancestors()
.skip(1)
.find_map(JsVariableDeclaration::cast)?;
let mut mutation = ctx.root().begin();
let this_expr = AnyJsExpression::from(make::js_this_expression(make::token(T![this])));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl ConditionalStatement {
}
// Checks if the self statement is in a generator function
fn is_in_generator_function(&self) -> bool {
self.syntax().ancestors().any(|node| {
self.syntax().ancestors().skip(1).any(|node| {
match JsFunctionDeclaration::try_cast(node) {
Ok(func_decl) => func_decl.star_token(),
Err(node) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Rule for NoConstructorReturn {
let _arg = ret.argument()?;
ret.syntax()
.ancestors()
.skip(1)
.find(|x| AnyJsControlFlowRoot::can_cast(x.kind()))
.and_then(JsConstructorClassMember::cast)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl Rule for NoInvalidConstructorSuper {
let extends_clause = node
.syntax()
.ancestors()
.skip(1)
.find_map(|node| AnyJsClass::cast(node)?.extends_clause());

match (super_range, extends_clause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Rule for NoNestedComponentDefinitions {
&& let Some(parent_component) = node
.syntax()
.ancestors()
.skip(1)
.skip_while(|ancestor| ancestor.eq(node.syntax()))
.find_map(|syntax| ReactComponentInfo::from_declaration(&syntax))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl Rule for NoProcessGlobal {
.query()
.syntax()
.ancestors()
.skip(1)
.find(is_top_level_statement)?;
// insert new import at:
// 1. after the most recent import statement. Or, if no such import exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Rule for NoSetterReturn {
let _arg = ret.argument()?;
ret.syntax()
.ancestors()
.skip(1)
.find(|x| AnyJsControlFlowRoot::can_cast(x.kind()))
.and_then(JsSetterMember::cast)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl Rule for NoSolidDestructuredProps {
let Some(parameters) = binding_pattern
.syntax()
.ancestors()
.skip(1)
.find_map(JsParameters::cast)
else {
return vec![];
Expand Down Expand Up @@ -186,6 +187,7 @@ fn is_binding_a_jsx_prop(binding: &AnyJsBinding, model: &SemanticModel) -> Optio
if reference
.syntax()
.ancestors()
.skip(1)
.find_map(JsxExpressionAttributeValue::cast)
.is_some()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Rule for NoUndeclaredVariables {
// arguments object within non-arrow functions
if text == "arguments" {
let is_in_non_arrow_function =
identifier.syntax().ancestors().any(|ancestor| {
identifier.syntax().ancestors().skip(1).any(|ancestor| {
!matches!(
AnyJsFunction::cast(ancestor),
None | Some(AnyJsFunction::JsArrowFunctionExpression(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl Rule for UseQwikValidLexicalScope {
fn is_wrapped_with_dollar(expr: &AnyJsExpression) -> bool {
expr.syntax()
.ancestors()
.skip(1)
.find_map(JsCallExpression::cast)
.and_then(|call| call.callee().ok())
.and_then(|callee| callee.as_js_reference_identifier())
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery/no_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,22 @@ fn is_inside_type_parameter(binding: &Binding) -> bool {
binding
.syntax()
.ancestors()
.skip(1)
.any(|ancestor| ancestor.cast::<TsTypeParameter>().is_some())
}

fn is_inside_type_member(binding: &Binding) -> bool {
binding
.syntax()
.ancestors()
.skip(1)
.any(|ancestor| ancestor.cast::<TsPropertySignatureTypeMember>().is_some())
}

fn is_inside_function_parameters(binding: &Binding) -> bool {
binding
.syntax()
.ancestors()
.skip(1)
.any(|ancestor| ancestor.cast::<JsParameterList>().is_some())
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ fn check_condition_necessity(
let inside_catch = expr
.syntax()
.ancestors()
.skip(1)
.any(|ancestor| JsCatchClause::can_cast(ancestor.kind()));

if inside_catch {
Expand Down
Loading