Skip to content

Commit

Permalink
Implement isort compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Mar 1, 2024
1 parent 94d04a6 commit 2fcdfbb
Show file tree
Hide file tree
Showing 15 changed files with 1,250 additions and 303 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# These rules test for intentional "odd" formatting. Using a formatter fixes that
[E{1,2,3}*.py]
generated_code = true
ij_formatter_enabled = false

[W*.py]
generated_code = true
ij_formatter_enabled = false
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@ class BackendProxy:
import abcd



abcd.foo()

def __init__(self, backend_module: str, backend_obj: str | None) -> None: ...

if TYPE_CHECKING:
import os



from typing_extensions import TypeAlias


abcd.foo()

def __call__(self, name: str, *args: Any, **kwargs: Any) -> Any:
...

if TYPE_CHECKING:
from typing_extensions import TypeAlias

def __call__(self, name: str, *args: Any, **kwargs: Any) -> Any: ...
def __call__2(self, name: str, *args: Any, **kwargs: Any) -> Any:
...


def _exit(self) -> None: ...
Expand Down
54 changes: 46 additions & 8 deletions crates/ruff_linter/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,58 @@ mod tests {
Ok(())
}

/// Tests the compatibility of the blank line rules and isort.
#[test_case(Rule::BlankLinesTopLevel)]
#[test_case(Rule::TooManyBlankLines)]
fn blank_lines_isort(rule_code: Rule) -> Result<()> {
let snapshot = format!("blank_lines_{}_isort", rule_code.noqa_code());
/// Tests the compatibility of the blank line top level rule and isort.
#[test_case(-1, 0)]
#[test_case(1, 1)]
#[test_case(0, 0)]
#[test_case(4, 4)]
fn blank_lines_top_level_isort_compatibility(
lines_after_imports: isize,
lines_between_types: usize,
) -> Result<()> {
let snapshot = format!(
"blank_lines_top_level_isort_compatibility-lines-after({lines_after_imports})-between({lines_between_types})"
);
let diagnostics = test_path(
Path::new("pycodestyle").join("E30_isort.py"),
&settings::LinterSettings {
isort: isort::settings::Settings {
lines_after_imports,
lines_between_types,
..isort::settings::Settings::default()
},
..settings::LinterSettings::for_rules([
Rule::BlankLinesTopLevel,
Rule::UnsortedImports,
])
},
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}

/// Tests the compatibility of the blank line too many lines and isort.
#[test_case(-1, 0)]
#[test_case(1, 1)]
#[test_case(0, 0)]
#[test_case(4, 4)]
fn too_many_blank_lines_isort_compatibility(
lines_after_imports: isize,
lines_between_types: usize,
) -> Result<()> {
let snapshot = format!("too_many_blank_lines_isort_compatibility-lines-after({lines_after_imports})-between({lines_between_types})");
let diagnostics = test_path(
Path::new("pycodestyle").join("E30_isort.py"),
&settings::LinterSettings {
isort: isort::settings::Settings {
lines_after_imports: 1,
lines_between_types: 1,
lines_after_imports,
lines_between_types,
..isort::settings::Settings::default()
},
..settings::LinterSettings::for_rules([rule_code, Rule::UnsortedImports])
..settings::LinterSettings::for_rules([
Rule::TooManyBlankLines,
Rule::UnsortedImports,
])
},
)?;
assert_messages!(snapshot, diagnostics);
Expand Down
Loading

0 comments on commit 2fcdfbb

Please sign in to comment.