Omit non-.py[i] files from module naming rules (#3153)

This commit is contained in:
Charlie Marsh 2023-02-22 19:38:46 -05:00 committed by GitHub
parent 049e77b939
commit 21d02cd51f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 0 deletions

View file

@ -43,6 +43,7 @@ mod tests {
#[test_case(Rule::InvalidModuleName, Path::new("N999/module/valid_name/__main__.py"); "N999_10")]
#[test_case(Rule::InvalidModuleName, Path::new("N999/module/valid_name/0001_initial.py"); "N999_11")]
#[test_case(Rule::InvalidModuleName, Path::new("N999/module/valid_name/__setup__.py"); "N999_12")]
#[test_case(Rule::InvalidModuleName, Path::new("N999/module/valid_name/file-with-dashes"); "N999_13")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(

View file

@ -43,6 +43,13 @@ impl Violation for InvalidModuleName {
/// N999
pub fn invalid_module_name(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
if !path
.extension()
.map_or(false, |ext| ext == "py" || ext == "pyi")
{
return None;
}
if let Some(package) = package {
let module_name = if path.file_name().map_or(false, |file_name| {
file_name == "__init__.py"

View file

@ -0,0 +1,6 @@
---
source: crates/ruff/src/rules/pep8_naming/mod.rs
expression: diagnostics
---
[]