Use insta settings instead of cfg (#18134)

Summary
--

I noticed these `cfg` directives while working on diagnostics. I think
it makes more sense to apply an `insta` filter in the test instead. I
copied this filter from a CLI test for the same rule.

Test Plan
--

Existing tests, especially Windows CI on this PR
This commit is contained in:
Brent Westbrook 2025-05-16 10:55:33 -04:00 committed by GitHub
parent 1ba56b4bc6
commit a1d007c37c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 10 deletions

View file

@ -39,7 +39,9 @@ mod tests {
..LinterSettings::for_rule(Rule::ImplicitNamespacePackage)
},
)?;
assert_messages!(snapshot, diagnostics);
insta::with_settings!({filters => vec![(r"\\", "/")]}, {
assert_messages!(snapshot, diagnostics);
});
Ok(())
}
}

View file

@ -83,10 +83,6 @@ pub(crate) fn implicit_namespace_package(
// Ignore PEP 723 scripts.
&& ScriptTag::parse(locator.contents().as_bytes()).is_none()
{
#[cfg(all(test, windows))]
let path = path
.to_string_lossy()
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
return Some(Diagnostic::new(
ImplicitNamespacePackage {
filename: fs::relativize_path(path),
@ -104,11 +100,6 @@ pub(crate) fn implicit_namespace_package(
.ancestors()
.find(|parent| !parent.join("__init__.py").exists())
{
#[cfg(all(test, windows))]
let path = path
.to_string_lossy()
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
return Some(Diagnostic::new(
ImplicitNamespacePackage {
filename: fs::relativize_path(path),