Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auto-fix for E275 #8133

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_diagnostics::Violation;
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_parser::TokenKind;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -29,11 +29,15 @@ use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;
#[violation]
pub struct MissingWhitespaceAfterKeyword;

impl Violation for MissingWhitespaceAfterKeyword {
impl AlwaysFixableViolation for MissingWhitespaceAfterKeyword {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing whitespace after keyword")
}

fn fix_title(&self) -> String {
format!("Added missing whitespace after keyword")
}
}

/// E275
Expand All @@ -59,7 +63,9 @@ pub(crate) fn missing_whitespace_after_keyword(
))
&& tok0.end() == tok1.start()
{
context.push(MissingWhitespaceAfterKeyword, tok0.range());
let mut diagnostic = Diagnostic::new(MissingWhitespaceAfterKeyword, tok0.range());
diagnostic.set_fix(Fix::safe_edit(Edit::insertion(" ".to_string(), tok0.end())));
context.push_diagnostic(diagnostic);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E27.py:37:8: E275 Missing whitespace after keyword
E27.py:37:8: E275 [*] Missing whitespace after keyword
|
35 | from w import (e, f)
36 | #: E275
Expand All @@ -10,8 +10,19 @@ E27.py:37:8: E275 Missing whitespace after keyword
38 | #: E275
39 | from importable.module import(e, f)
|
= help: Added missing whitespace after keyword

E27.py:39:24: E275 Missing whitespace after keyword
ℹ Fix
34 34 | #: E271
35 35 | from w import (e, f)
36 36 | #: E275
37 |-from w import(e, f)
37 |+from w import (e, f)
38 38 | #: E275
39 39 | from importable.module import(e, f)
40 40 | #: E275

E27.py:39:24: E275 [*] Missing whitespace after keyword
|
37 | from w import(e, f)
38 | #: E275
Expand All @@ -20,8 +31,19 @@ E27.py:39:24: E275 Missing whitespace after keyword
40 | #: E275
41 | try:
|
= help: Added missing whitespace after keyword

ℹ Fix
36 36 | #: E275
37 37 | from w import(e, f)
38 38 | #: E275
39 |-from importable.module import(e, f)
39 |+from importable.module import (e, f)
40 40 | #: E275
41 41 | try:
42 42 | from importable.module import(e, f)

E27.py:42:28: E275 Missing whitespace after keyword
E27.py:42:28: E275 [*] Missing whitespace after keyword
|
40 | #: E275
41 | try:
Expand All @@ -30,8 +52,19 @@ E27.py:42:28: E275 Missing whitespace after keyword
43 | except ImportError:
44 | pass
|
= help: Added missing whitespace after keyword

ℹ Fix
39 39 | from importable.module import(e, f)
40 40 | #: E275
41 41 | try:
42 |- from importable.module import(e, f)
42 |+ from importable.module import (e, f)
43 43 | except ImportError:
44 44 | pass
45 45 | #: E275

E27.py:46:1: E275 Missing whitespace after keyword
E27.py:46:1: E275 [*] Missing whitespace after keyword
|
44 | pass
45 | #: E275
Expand All @@ -40,8 +73,19 @@ E27.py:46:1: E275 Missing whitespace after keyword
47 | pass
48 | else:
|
= help: Added missing whitespace after keyword

E27.py:54:5: E275 Missing whitespace after keyword
ℹ Fix
43 43 | except ImportError:
44 44 | pass
45 45 | #: E275
46 |-if(foo):
46 |+if (foo):
47 47 | pass
48 48 | else:
49 49 | pass

E27.py:54:5: E275 [*] Missing whitespace after keyword
|
52 | #: E275:2:11
53 | if True:
Expand All @@ -50,5 +94,16 @@ E27.py:54:5: E275 Missing whitespace after keyword
55 | #: Okay
56 | def f():
|
= help: Added missing whitespace after keyword

ℹ Fix
51 51 | matched = {"true": True, "false": False}
52 52 | #: E275:2:11
53 53 | if True:
54 |- assert(1)
54 |+ assert (1)
55 55 | #: Okay
56 56 | def f():
57 57 | print((yield))


Loading