Use file path for detecting package root (#18914)
Ref: https://github.com/astral-sh/ruff/pull/18910#discussion_r2163847956
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user