From 06440dc5ba58ccc44c2126d7b9ac8fe310e5bfbf Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Fri, 9 Jan 2026 15:45:22 -0800 Subject: [PATCH] Update source kind from path mapping --- crates/ruff_linter/src/source_kind.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/ruff_linter/src/source_kind.rs b/crates/ruff_linter/src/source_kind.rs index bdcd43bbfe..c039fc45ab 100644 --- a/crates/ruff_linter/src/source_kind.rs +++ b/crates/ruff_linter/src/source_kind.rs @@ -101,14 +101,21 @@ impl SourceKind { /// Read the [`SourceKind`] from the given path. Returns `None` if the source is not a Python /// source file. pub fn from_path(path: &Path, source_type: PySourceType) -> Result, SourceError> { - if source_type.is_ipynb() { - let notebook = Notebook::from_path(path)?; - Ok(notebook - .is_python_notebook() - .then_some(Self::IpyNotebook(Box::new(notebook)))) - } else { - let contents = std::fs::read_to_string(path)?; - Ok(Some(Self::Python(contents))) + match source_type { + PySourceType::Ipynb => { + let notebook = Notebook::from_path(path)?; + Ok(notebook + .is_python_notebook() + .then_some(Self::IpyNotebook(Box::new(notebook)))) + } + PySourceType::Markdown => { + let contents = std::fs::read_to_string(path)?; + Ok(Some(Self::Markdown(contents))) + } + PySourceType::Python | PySourceType::Stub => { + let contents = std::fs::read_to_string(path)?; + Ok(Some(Self::Python(contents))) + } } }