mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Use explicit fields for implicit-namespace-package
This commit is contained in:
parent
c8f60c9588
commit
6a87c99004
4 changed files with 13 additions and 6 deletions
|
@ -28,12 +28,14 @@ define_violation!(
|
||||||
/// [`namespace-packages`](https://github.com/charliermarsh/ruff#namespace-packages)
|
/// [`namespace-packages`](https://github.com/charliermarsh/ruff#namespace-packages)
|
||||||
/// configuration option. Adding a namespace package to the configuration
|
/// configuration option. Adding a namespace package to the configuration
|
||||||
/// will suppress this violation for a given package.
|
/// will suppress this violation for a given package.
|
||||||
pub struct ImplicitNamespacePackage(pub String);
|
pub struct ImplicitNamespacePackage {
|
||||||
|
pub filename: String,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
impl Violation for ImplicitNamespacePackage {
|
impl Violation for ImplicitNamespacePackage {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
let ImplicitNamespacePackage(filename) = self;
|
let ImplicitNamespacePackage { filename } = self;
|
||||||
format!("File `{filename}` is part of an implicit namespace package. Add an `__init__.py`.")
|
format!("File `{filename}` is part of an implicit namespace package. Add an `__init__.py`.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,9 @@ pub fn implicit_namespace_package(
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
|
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
|
||||||
Some(Diagnostic::new(
|
Some(Diagnostic::new(
|
||||||
ImplicitNamespacePackage(fs::relativize_path(path)),
|
ImplicitNamespacePackage {
|
||||||
|
filename: fs::relativize_path(path),
|
||||||
|
},
|
||||||
Range::default(),
|
Range::default(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
ImplicitNamespacePackage: "./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py"
|
ImplicitNamespacePackage:
|
||||||
|
filename: "./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py"
|
||||||
location:
|
location:
|
||||||
row: 1
|
row: 1
|
||||||
column: 0
|
column: 0
|
||||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
ImplicitNamespacePackage: "./resources/test/fixtures/flake8_no_pep420/test_fail_nonempty/example.py"
|
ImplicitNamespacePackage:
|
||||||
|
filename: "./resources/test/fixtures/flake8_no_pep420/test_fail_nonempty/example.py"
|
||||||
location:
|
location:
|
||||||
row: 1
|
row: 1
|
||||||
column: 0
|
column: 0
|
||||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
ImplicitNamespacePackage: "./resources/test/fixtures/flake8_no_pep420/test_fail_shebang/example.py"
|
ImplicitNamespacePackage:
|
||||||
|
filename: "./resources/test/fixtures/flake8_no_pep420/test_fail_shebang/example.py"
|
||||||
location:
|
location:
|
||||||
row: 1
|
row: 1
|
||||||
column: 0
|
column: 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue