Skip to content

Commit 06440dc

Browse files
committed
Update source kind from path mapping
1 parent 64fd7e9 commit 06440dc

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

crates/ruff_linter/src/source_kind.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,21 @@ impl SourceKind {
101101
/// Read the [`SourceKind`] from the given path. Returns `None` if the source is not a Python
102102
/// source file.
103103
pub fn from_path(path: &Path, source_type: PySourceType) -> Result<Option<Self>, SourceError> {
104-
if source_type.is_ipynb() {
105-
let notebook = Notebook::from_path(path)?;
106-
Ok(notebook
107-
.is_python_notebook()
108-
.then_some(Self::IpyNotebook(Box::new(notebook))))
109-
} else {
110-
let contents = std::fs::read_to_string(path)?;
111-
Ok(Some(Self::Python(contents)))
104+
match source_type {
105+
PySourceType::Ipynb => {
106+
let notebook = Notebook::from_path(path)?;
107+
Ok(notebook
108+
.is_python_notebook()
109+
.then_some(Self::IpyNotebook(Box::new(notebook))))
110+
}
111+
PySourceType::Markdown => {
112+
let contents = std::fs::read_to_string(path)?;
113+
Ok(Some(Self::Markdown(contents)))
114+
}
115+
PySourceType::Python | PySourceType::Stub => {
116+
let contents = std::fs::read_to_string(path)?;
117+
Ok(Some(Self::Python(contents)))
118+
}
112119
}
113120
}
114121

0 commit comments

Comments
 (0)