mirror of https://github.com/astral-sh/ruff
[ty_test] Use let-else pattern in generate_hover_outputs
Replace nested if-let blocks with let-else + continue to reduce indentation and improve readability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
19600ecd51
commit
ab261360e4
|
|
@ -86,28 +86,33 @@ pub(crate) fn generate_hover_outputs(
|
|||
|
||||
// Look for hover assertions in this line's assertions
|
||||
for assertion in line_assertions.iter() {
|
||||
if let crate::assertion::UnparsedAssertion::Hover(hover_text) = assertion {
|
||||
let crate::assertion::UnparsedAssertion::Hover(hover_text) = assertion else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Find the down arrow position in the comment text to determine the column
|
||||
if let Some(arrow_position) = hover_text.find('↓') {
|
||||
let Some(arrow_position) = hover_text.find('↓') else {
|
||||
// No down arrow - skip this hover assertion (will be caught as error by matcher)
|
||||
continue;
|
||||
};
|
||||
|
||||
// Get the start offset of the target line
|
||||
let target_line_start = lines.line_start(target_line, &source);
|
||||
|
||||
// Calculate the hover position: start of target line + arrow column (0-indexed)
|
||||
let hover_offset =
|
||||
target_line_start + TextSize::try_from(arrow_position).unwrap();
|
||||
let hover_offset = target_line_start + TextSize::try_from(arrow_position).unwrap();
|
||||
|
||||
// Get the inferred type at that position
|
||||
if let Some(inferred_type) = infer_type_at_position(db, file, hover_offset) {
|
||||
let Some(inferred_type) = infer_type_at_position(db, file, hover_offset) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
hover_outputs.push(matcher::CheckOutput::Hover {
|
||||
offset: hover_offset,
|
||||
inferred_type,
|
||||
});
|
||||
}
|
||||
}
|
||||
// If no down arrow, skip this hover assertion (will be caught as error by matcher)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hover_outputs
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue