From 33fe988cfc2efb8c837644aa14a2c3968534c7c8 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 29 Jan 2024 11:33:42 -0800 Subject: [PATCH] Remove preview gating for `pycodestyle` rules (#9685) ## Summary Un-gates the behavior to allow `sys.path` modifications between imports, which removed a bunch of false positives in the ecosystem CI at the time. --- crates/ruff_linter/src/checkers/ast/mod.rs | 3 +- .../ruff_linter/src/rules/pycodestyle/mod.rs | 1 - ...s__pycodestyle__tests__E402_E402_0.py.snap | 30 ------------------- ...style__tests__preview__E402_E402_0.py.snap | 28 ----------------- 4 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__preview__E402_E402_0.py.snap diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index ac648ac64e942..d13a7a9270c0b 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -342,8 +342,7 @@ where || helpers::is_assignment_to_a_dunder(stmt) || helpers::in_nested_block(self.semantic.current_statements()) || imports::is_matplotlib_activation(stmt, self.semantic()) - || self.settings.preview.is_enabled() - && imports::is_sys_path_modification(stmt, self.semantic())) + || imports::is_sys_path_modification(stmt, self.semantic())) { self.semantic.flags |= SemanticModelFlags::IMPORT_BOUNDARY; } diff --git a/crates/ruff_linter/src/rules/pycodestyle/mod.rs b/crates/ruff_linter/src/rules/pycodestyle/mod.rs index 54993e975ea43..317993e97b65d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/mod.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/mod.rs @@ -68,7 +68,6 @@ mod tests { } #[test_case(Rule::IsLiteral, Path::new("constant_literals.py"))] - #[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_0.py"))] #[test_case(Rule::TypeComparison, Path::new("E721.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402_0.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402_0.py.snap index 29ab0d19c9a67..197644bcd690f 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402_0.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402_0.py.snap @@ -1,36 +1,6 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E402_0.py:25:1: E402 Module level import not at top of file - | -23 | sys.path.insert(0, "some/path") -24 | -25 | import f - | ^^^^^^^^ E402 -26 | -27 | import matplotlib - | - -E402_0.py:27:1: E402 Module level import not at top of file - | -25 | import f -26 | -27 | import matplotlib - | ^^^^^^^^^^^^^^^^^ E402 -28 | -29 | matplotlib.use("Agg") - | - -E402_0.py:31:1: E402 Module level import not at top of file - | -29 | matplotlib.use("Agg") -30 | -31 | import g - | ^^^^^^^^ E402 -32 | -33 | __some__magic = 1 - | - E402_0.py:35:1: E402 Module level import not at top of file | 33 | __some__magic = 1 diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__preview__E402_E402_0.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__preview__E402_E402_0.py.snap deleted file mode 100644 index 197644bcd690f..0000000000000 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__preview__E402_E402_0.py.snap +++ /dev/null @@ -1,28 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/pycodestyle/mod.rs ---- -E402_0.py:35:1: E402 Module level import not at top of file - | -33 | __some__magic = 1 -34 | -35 | import h - | ^^^^^^^^ E402 - | - -E402_0.py:45:1: E402 Module level import not at top of file - | -43 | import j -44 | -45 | import k; import l - | ^^^^^^^^ E402 - | - -E402_0.py:45:11: E402 Module level import not at top of file - | -43 | import j -44 | -45 | import k; import l - | ^^^^^^^^ E402 - | - -