mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
Omit non-.py[i] files from module naming rules (#3153)
This commit is contained in:
parent
049e77b939
commit
21d02cd51f
4 changed files with 14 additions and 0 deletions
0
crates/ruff/resources/test/fixtures/pep8_naming/N999/module/valid_name/file-with-dashes
vendored
Normal file
0
crates/ruff/resources/test/fixtures/pep8_naming/N999/module/valid_name/file-with-dashes
vendored
Normal 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/__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/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/__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<()> {
|
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||||
let diagnostics = test_path(
|
let diagnostics = test_path(
|
||||||
|
|
|
@ -43,6 +43,13 @@ impl Violation for InvalidModuleName {
|
||||||
|
|
||||||
/// N999
|
/// N999
|
||||||
pub fn invalid_module_name(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
|
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 {
|
if let Some(package) = package {
|
||||||
let module_name = if path.file_name().map_or(false, |file_name| {
|
let module_name = if path.file_name().map_or(false, |file_name| {
|
||||||
file_name == "__init__.py"
|
file_name == "__init__.py"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff/src/rules/pep8_naming/mod.rs
|
||||||
|
expression: diagnostics
|
||||||
|
---
|
||||||
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue