Use file path for detecting package root (#18914)

Ref: https://github.com/astral-sh/ruff/pull/18910#discussion_r2163847956
This commit is contained in:
Dhruv Manilawala 2025-06-24 18:02:41 +05:30 committed by GitHub
parent 66fc7c8fc0
commit 2c4c015f74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,13 +81,18 @@ pub(crate) fn check(
return DiagnosticsMap::default();
}
let package = detect_package_root(
document_path
.parent()
.expect("a path to a document should have a parent path"),
&settings.linter.namespace_packages,
)
.map(PackageRoot::root);
let file_path = query.file_path();
let package = if let Some(file_path) = &file_path {
detect_package_root(
file_path
.parent()
.expect("a path to a document should have a parent path"),
&settings.linter.namespace_packages,
)
.map(PackageRoot::root)
} else {
None
};
let source_type = query.source_type();