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

Code before:
        }
    }

    /// Returns the [`Tokens`] for the parsed source file.
    ///
    ///
    /// Unlike [`Self::tokens`], this method always returns
    /// the tokens for the current file, even when within a parsed type annotation.
    pub(crate) fn source_tokens(&self) -> &'a Tokens {
        self.parsed.tokens()
    }

    /// The [`Locator`] for the current file, which enables extraction of source code from byte
    /// offsets.
    pub(crate) const fn locator(&self) -> &'a Locator<'a> {
        self.locator
    }

    pub(crate) const fn source(&self) -> &'a str {
        self.locator.contents()
    }

    /// The AST body for the current module.
    pub(crate) fn python_ast(&self) -> &'a [Stmt] {
        self.parsed.suite()
    }

    /// The [`Stylist`] for the current file, which detects the current line ending, quote, and
    /// indentation style.
    pub(crate) const fn stylist(&self) -> &'a Stylist<'a> {
        self.stylist
    }

    /// The [`Indexer`] for the current file, which contains the offsets of all comments and more.
    pub(crate) const fn indexer(&self) -> &'a Indexer {
        self.indexer
    }

    /// The [`Importer`] for the current file, which enables importing of other modules.
    pub(crate) const fn importer(&self) -> &Importer<'a> {
        &self.importer
    }

    /// The [`SemanticModel`], built up over the course of the AST traversal.
    pub(crate) const fn semantic(&self) -> &SemanticModel<'a> {
        &self.semantic
    }

    /// The [`LinterSettings`] for the current analysis, including the enabled rules.
    pub(crate) const fn settings(&self) -> &'a LinterSettings {
        self.context.settings

Review comment (suggestion):
```suggestion
```

I think it would be preferable to just pass the `Checker` around and access `.parsed.suite()` where needed.

Code after:
        } else {
            self.parsed.tokens()
        }
    }

    /// Returns the [`Tokens`] for the parsed source file.
    ///
    ///
    /// Unlike [`Self::tokens`], this method always returns
    /// the tokens for the current file, even when within a parsed type annotation.
    pub(crate) fn source_tokens(&self) -> &'a Tokens {
        self.parsed.tokens()
    }

    /// The [`Locator`] for the current file, which enables extraction of source code from byte
    /// offsets.
    pub(crate) const fn locator(&self) -> &'a Locator<'a> {
        self.locator
    }

    pub(crate) const fn source(&self) -> &'a str {
        self.locator.contents()
    }

    /// The [`Stylist`] for the current file, which detects the current line ending, quote, and
    /// indentation style.
    pub(crate) const fn stylist(&self) -> &'a Stylist<'a> {
        self.stylist
    }

    /// The [`Indexer`] for the current file, which contains the offsets of all comments and more.
    pub(crate) const fn indexer(&self) -> &'a Indexer {
        self.indexer
    }

    /// The [`Importer`] for the current file, which enables importing of other modules.
    pub(crate) const fn importer(&self) -> &Importer<'a> {
        &self.importer
    }

    /// The [`SemanticModel`], built up over the course of the AST traversal.
    pub(crate) const fn semantic(&self) -> &SemanticModel<'a> {
        &self.semantic
    }

    /// The [`LinterSettings`] for the current analysis, including the enabled rules.
    pub(crate) const fn settings(&self) -> &'a LinterSettings {
        self.context.settings
    }

    /// Returns whether the file under analysis is an `__init__.py` file.