Skip to content

Commit

Permalink
Avoid implicit-namespace-package checks for .pyi files
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 31, 2023
1 parent 1dd9ccf commit 8822965
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Empty file.
25 changes: 12 additions & 13 deletions src/rules/flake8_no_pep420/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ mod tests {
use crate::registry::Rule;
use crate::settings::Settings;

#[test_case(Path::new("test_pass_init"); "INP001_0")]
#[test_case(Path::new("test_fail_empty"); "INP001_1")]
#[test_case(Path::new("test_fail_nonempty"); "INP001_2")]
#[test_case(Path::new("test_fail_shebang"); "INP001_3")]
#[test_case(Path::new("test_ignored"); "INP001_4")]
#[test_case(Path::new("test_pass_namespace_package"); "INP001_5")]
fn test_flake8_no_pep420(path: &Path) -> Result<()> {
#[test_case(Path::new("test_pass_init"), Path::new("example.py"); "INP001_0")]
#[test_case(Path::new("test_fail_empty"), Path::new("example.py"); "INP001_1")]
#[test_case(Path::new("test_fail_nonempty"), Path::new("example.py"); "INP001_2")]
#[test_case(Path::new("test_fail_shebang"), Path::new("example.py"); "INP001_3")]
#[test_case(Path::new("test_ignored"), Path::new("example.py"); "INP001_4")]
#[test_case(Path::new("test_pass_namespace_package"), Path::new("example.py"); "INP001_5")]
#[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());
// Platform-independent paths
let p = PathBuf::from(format!(
"./resources/test/fixtures/flake8_no_pep420/{}/example.py",
path.display()
));
let diagnostics = test_path(
p.as_path(),
Path::new("./resources/test/fixtures/flake8_no_pep420")
.join(path)
.join(filename)
.as_path(),
&Settings {
namespace_packages: vec![PathBuf::from(
"./resources/test/fixtures/flake8_no_pep420/test_pass_namespace_package",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/flake8_no_pep420/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Violation for ImplicitNamespacePackage {

/// INP001
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
if package.is_none() {
if package.is_none() && path.extension().map_or(false, |ext| ext == "py") {
Some(Diagnostic::new(
ImplicitNamespacePackage(fs::relativize_path(path)),
Range::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/rules/flake8_no_pep420/mod.rs
expression: diagnostics
---
[]

0 comments on commit 8822965

Please sign in to comment.