mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +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)
|
||||
/// configuration option. Adding a namespace package to the configuration
|
||||
/// will suppress this violation for a given package.
|
||||
pub struct ImplicitNamespacePackage(pub String);
|
||||
pub struct ImplicitNamespacePackage {
|
||||
pub filename: String,
|
||||
}
|
||||
);
|
||||
impl Violation for ImplicitNamespacePackage {
|
||||
#[derive_message_formats]
|
||||
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`.")
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +64,9 @@ pub fn implicit_namespace_package(
|
|||
.to_string_lossy()
|
||||
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
|
||||
Some(Diagnostic::new(
|
||||
ImplicitNamespacePackage(fs::relativize_path(path)),
|
||||
ImplicitNamespacePackage {
|
||||
filename: fs::relativize_path(path),
|
||||
},
|
||||
Range::default(),
|
||||
))
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- 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:
|
||||
row: 1
|
||||
column: 0
|
||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- 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:
|
||||
row: 1
|
||||
column: 0
|
||||
|
|
|
@ -3,7 +3,8 @@ source: crates/ruff/src/rules/flake8_no_pep420/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- 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:
|
||||
row: 1
|
||||
column: 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue