mirror of https://github.com/astral-sh/ruff
Avoid implicit-namespace-package checks for .pyi files (#2420)
This commit is contained in:
parent
142b627bb8
commit
84a8b628b8
|
|
@ -13,18 +13,19 @@ mod tests {
|
||||||
use crate::registry::Rule;
|
use crate::registry::Rule;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
|
||||||
#[test_case(Path::new("test_pass_init"); "INP001_0")]
|
#[test_case(Path::new("test_pass_init"), Path::new("example.py"); "INP001_0")]
|
||||||
#[test_case(Path::new("test_fail_empty"); "INP001_1")]
|
#[test_case(Path::new("test_fail_empty"), Path::new("example.py"); "INP001_1")]
|
||||||
#[test_case(Path::new("test_fail_nonempty"); "INP001_2")]
|
#[test_case(Path::new("test_fail_nonempty"), Path::new("example.py"); "INP001_2")]
|
||||||
#[test_case(Path::new("test_fail_shebang"); "INP001_3")]
|
#[test_case(Path::new("test_fail_shebang"), Path::new("example.py"); "INP001_3")]
|
||||||
#[test_case(Path::new("test_ignored"); "INP001_4")]
|
#[test_case(Path::new("test_ignored"), Path::new("example.py"); "INP001_4")]
|
||||||
#[test_case(Path::new("test_pass_namespace_package"); "INP001_5")]
|
#[test_case(Path::new("test_pass_namespace_package"), Path::new("example.py"); "INP001_5")]
|
||||||
fn test_flake8_no_pep420(path: &Path) -> Result<()> {
|
#[test_case(Path::new("test_pass_pyi"), Path::new("example.pyi"); "INP001_6")]
|
||||||
|
fn test_flake8_no_pep420(path: &Path, filename: &Path) -> Result<()> {
|
||||||
let snapshot = format!("{}", path.to_string_lossy());
|
let snapshot = format!("{}", path.to_string_lossy());
|
||||||
// Platform-independent paths
|
|
||||||
let p = PathBuf::from(format!(
|
let p = PathBuf::from(format!(
|
||||||
"./resources/test/fixtures/flake8_no_pep420/{}/example.py",
|
"./resources/test/fixtures/flake8_no_pep420/{}/{}",
|
||||||
path.display()
|
path.display(),
|
||||||
|
filename.display()
|
||||||
));
|
));
|
||||||
let diagnostics = test_path(
|
let diagnostics = test_path(
|
||||||
p.as_path(),
|
p.as_path(),
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ impl Violation for ImplicitNamespacePackage {
|
||||||
|
|
||||||
/// INP001
|
/// INP001
|
||||||
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
|
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
|
||||||
if package.is_none() {
|
if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") {
|
||||||
Some(Diagnostic::new(
|
Some(Diagnostic::new(
|
||||||
ImplicitNamespacePackage(fs::relativize_path(path)),
|
ImplicitNamespacePackage(fs::relativize_path(path)),
|
||||||
Range::default(),
|
Range::default(),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
source: src/rules/flake8_no_pep420/mod.rs
|
||||||
|
expression: diagnostics
|
||||||
|
---
|
||||||
|
[]
|
||||||
|
|
||||||
Loading…
Reference in New Issue