Repository: astral-sh/ruff
File: crates/ruff_linter/src/suppression.rs (Rust)

Code before:
                        if indents.is_empty() {
                            // OR if self.pending is empty?
                            continue 'comments;
                        }
                    }
                    TokenKind::Comment => {
                        let Some(suppression) =
                            suppressions.next_if(|suppression| suppression.range == token.range())
                        else {
                            continue;
                        };

                        let Some(indent) =
                            indentation_at_offset(suppression.range.start(), self.source)
                        else {
                            // trailing suppressions are not supported
                            self.invalid.push(InvalidSuppression {
                                kind: InvalidSuppressionKind::Trailing,
                                comment: suppression,
                            });
                            continue;
                        };

                        // comment matches current block's indentation, or precedes an indent/dedent token
                        if indent == current_indent
                            || tokens[token_index..]
                                .iter()
                                .find(|t| !t.kind().is_trivia())
                                .is_some_and(|t| {
                                    t.kind() == TokenKind::Dedent || t.kind() == TokenKind::Indent
                                })
                        {
                            self.pending.push(PendingSuppressionComment {
                                indent,
                                comment: suppression,
                            });
                        } else {
                            // weirdly indented? ¯\_(ツ)_/¯
                            self.invalid.push(InvalidSuppression {
                                kind: InvalidSuppressionKind::Indentation,
                                comment: suppression,
                            });
                        }
                    }
                    _ => {}
                }
            }

            self.match_comments("", TextRange::up_to(self.source.text_len()));
        }


Review comment (suggestion):
You need to change this to `after`. The tests then pass

Code after:
                        if indents.is_empty() || self.pending.is_empty() {
                            continue 'comments;
                        }
                    }
                    TokenKind::Comment => {
                        let Some(suppression) =
                            suppressions.next_if(|suppression| suppression.range == token.range())
                        else {
                            continue;
                        };

                        let Some(indent) =
                            indentation_at_offset(suppression.range.start(), self.source)
                        else {
                            // trailing suppressions are not supported
                            self.invalid.push(InvalidSuppression {
                                kind: InvalidSuppressionKind::Trailing,
                                comment: suppression,
                            });
                            continue;
                        };

                        // comment matches current block's indentation, or precedes an indent/dedent token
                        if indent == current_indent
                            || after[token_index..]
                                .iter()
                                .find(|t| !t.kind().is_trivia())
                                .is_some_and(|t| {
                                    matches!(t.kind(), TokenKind::Dedent | TokenKind::Indent)
                                })
                        {
                            self.pending.push(PendingSuppressionComment {
                                indent,
                                comment: suppression,
                            });
                        } else {
                            // weirdly indented? ¯\_(ツ)_/¯
                            self.invalid.push(InvalidSuppression {
                                kind: InvalidSuppressionKind::Indentation,
                                comment: suppression,
                            });
                        }
                    }
                    _ => {}
                }
            }
        }

        self.match_comments("", TextRange::up_to(self.source.text_len()));

        Suppressions {