Skip to content
Closed
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
15 changes: 13 additions & 2 deletions crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,8 @@ impl RuleRunner for crate::rules::jsdoc::require_returns_type::RequireReturnsTyp
}

impl RuleRunner for crate::rules::jsdoc::require_yields::RequireYields {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const NODE_TYPES: Option<&AstTypesBitset> =
Some(&AstTypesBitset::from_types(&[AstType::Function, AstType::YieldExpression]));
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

Expand Down Expand Up @@ -2389,7 +2390,17 @@ impl RuleRunner
}

impl RuleRunner for crate::rules::typescript::array_type::ArrayType {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
AstType::TSArrayType,
AstType::TSAsExpression,
AstType::TSConditionalType,
AstType::TSIndexedAccessType,
AstType::TSMappedType,
AstType::TSTypeAliasDeclaration,
AstType::TSTypeAnnotation,
AstType::TSTypeParameterInstantiation,
AstType::TSTypeReference,
]));
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

Expand Down
20 changes: 17 additions & 3 deletions tasks/linter_codegen/src/match_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ impl<'a> MatchDetector<'a> {
run_func: &syn::ImplItemFn,
rule_runner_data: &'a RuleRunnerData,
) -> Option<NodeTypeSet> {
// Only consider when the body's only statement is `match node.kind() { ... }`
let block = &run_func.block;
if block.stmts.len() != 1 {
// Find first match statement, skipping only simple `let = ...` statements. If there is
// anything else, especially control flow, then we return.
let first_stmt = block.stmts.iter().find(|stmt| {
// skip let statements that are not diverging
if let Stmt::Local(local) = stmt
&& let Some(init) = &local.init
&& init.diverge.is_none()
{
return false;
}
// Otherwise, take the first statement we find
true
})?;
// Must be the only applicable statement in the block (cannot have anything after it)
if let Some(last_stmt) = block.stmts.last()
&& !std::ptr::eq(first_stmt, last_stmt)
{
return None;
}
let first_stmt = &block.stmts[0];
// Must be an expression statement
let Stmt::Expr(expr, _) = first_stmt else { return None };
// Must be a match expression
Expand Down
Loading