mirror of https://github.com/astral-sh/ruff
Ignore direct source-children in implicit-namespace-package (#2560)
This commit is contained in:
parent
e6316b185e
commit
4149bc7be8
|
|
@ -13,7 +13,7 @@ pub fn check_file_path(
|
||||||
|
|
||||||
// flake8-no-pep420
|
// flake8-no-pep420
|
||||||
if settings.rules.enabled(&Rule::ImplicitNamespacePackage) {
|
if settings.rules.enabled(&Rule::ImplicitNamespacePackage) {
|
||||||
if let Some(diagnostic) = implicit_namespace_package(path, package) {
|
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.src) {
|
||||||
diagnostics.push(diagnostic);
|
diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use ruff_macros::derive_message_formats;
|
use ruff_macros::derive_message_formats;
|
||||||
|
|
||||||
|
|
@ -19,8 +19,19 @@ impl Violation for ImplicitNamespacePackage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// INP001
|
/// INP001
|
||||||
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
|
pub fn implicit_namespace_package(
|
||||||
if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") {
|
path: &Path,
|
||||||
|
package: Option<&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 a source directory (e.g., `src/manage.py`).
|
||||||
|
&& !path
|
||||||
|
.parent()
|
||||||
|
.map_or(false, |parent| src.iter().any(|src| src == parent))
|
||||||
|
{
|
||||||
#[cfg(all(test, windows))]
|
#[cfg(all(test, windows))]
|
||||||
let path = path
|
let path = path
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue