mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:48:22 +00:00
Ignore direct root-children in implicit-namespace-package (#2565)
This commit is contained in:
parent
7d4f0a8320
commit
dd0145624b
2 changed files with 6 additions and 1 deletions
|
@ -13,7 +13,7 @@ pub fn check_file_path(
|
|||
|
||||
// flake8-no-pep420
|
||||
if settings.rules.enabled(&Rule::ImplicitNamespacePackage) {
|
||||
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.src) {
|
||||
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.project_root, &settings.src) {
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,16 @@ impl Violation for ImplicitNamespacePackage {
|
|||
pub fn implicit_namespace_package(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
project_root: &Path,
|
||||
src: &[PathBuf],
|
||||
) -> Option<Diagnostic> {
|
||||
if package.is_none()
|
||||
// Ignore `.pyi` files, which don't require an `__init__.py`.
|
||||
&& path.extension().map_or(true, |ext| ext != "pyi")
|
||||
// Ignore any files that are direct children of the project root.
|
||||
&& !path
|
||||
.parent()
|
||||
.map_or(false, |parent| parent == project_root)
|
||||
// Ignore any files that are direct children of a source directory (e.g., `src/manage.py`).
|
||||
&& !path
|
||||
.parent()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue