mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 07:38:00 +00:00
Ignore direct source-children in implicit-namespace-package (#2560)
This commit is contained in:
parent
e6316b185e
commit
4149bc7be8
2 changed files with 15 additions and 4 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) {
|
||||
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.src) {
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use ruff_macros::derive_message_formats;
|
||||
|
||||
|
@ -19,8 +19,19 @@ impl Violation for ImplicitNamespacePackage {
|
|||
}
|
||||
|
||||
/// INP001
|
||||
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
|
||||
if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") {
|
||||
pub fn implicit_namespace_package(
|
||||
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))]
|
||||
let path = path
|
||||
.to_string_lossy()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue