-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61f2d7c
commit bc510c8
Showing
12 changed files
with
403 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#: E201:1:6 | ||
spam( ham[1], {eggs: 2}) | ||
#: E201:1:10 | ||
spam(ham[ 1], {eggs: 2}) | ||
#: E201:1:15 | ||
spam(ham[1], { eggs: 2}) | ||
#: E201:1:6 | ||
spam( ham[1], {eggs: 2}) | ||
#: E201:1:10 | ||
spam(ham[ 1], {eggs: 2}) | ||
#: E201:1:15 | ||
spam(ham[1], { eggs: 2}) | ||
#: Okay | ||
spam(ham[1], {eggs: 2}) | ||
#: | ||
|
||
|
||
#: E202:1:23 | ||
spam(ham[1], {eggs: 2} ) | ||
#: E202:1:22 | ||
spam(ham[1], {eggs: 2 }) | ||
#: E202:1:11 | ||
spam(ham[1 ], {eggs: 2}) | ||
#: E202:1:23 | ||
spam(ham[1], {eggs: 2} ) | ||
#: E202:1:22 | ||
spam(ham[1], {eggs: 2 }) | ||
#: E202:1:11 | ||
spam(ham[1 ], {eggs: 2}) | ||
#: Okay | ||
spam(ham[1], {eggs: 2}) | ||
|
||
result = func( | ||
arg1='some value', | ||
arg2='another value', | ||
) | ||
|
||
result = func( | ||
arg1='some value', | ||
arg2='another value' | ||
) | ||
|
||
result = [ | ||
item for item in items | ||
if item > 5 | ||
] | ||
#: | ||
|
||
|
||
#: E203:1:10 | ||
if x == 4 : | ||
print x, y | ||
x, y = y, x | ||
#: E203:1:10 | ||
if x == 4 : | ||
print x, y | ||
x, y = y, x | ||
#: E203:2:15 E702:2:16 | ||
if x == 4: | ||
print x, y ; x, y = y, x | ||
#: E203:2:15 E702:2:16 | ||
if x == 4: | ||
print x, y ; x, y = y, x | ||
#: E203:3:13 | ||
if x == 4: | ||
print x, y | ||
x, y = y , x | ||
#: E203:3:13 | ||
if x == 4: | ||
print x, y | ||
x, y = y , x | ||
#: Okay | ||
if x == 4: | ||
print x, y | ||
x, y = y, x | ||
a[b1, :] == a[b1, ...] | ||
b = a[:, b1] | ||
#: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1447,6 +1447,10 @@ | |
"E10", | ||
"E101", | ||
"E2", | ||
"E20", | ||
"E201", | ||
"E202", | ||
"E203", | ||
"E22", | ||
"E221", | ||
"E222", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use once_cell::sync::Lazy; | ||
use regex::Regex; | ||
|
||
use ruff_macros::derive_message_formats; | ||
|
||
use crate::define_violation; | ||
use crate::registry::DiagnosticKind; | ||
use crate::violation::Violation; | ||
|
||
define_violation!( | ||
pub struct WhitespaceAfterOpenBracket; | ||
); | ||
impl Violation for WhitespaceAfterOpenBracket { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Whitespace after '('") | ||
} | ||
} | ||
|
||
define_violation!( | ||
pub struct WhitespaceBeforeCloseBracket; | ||
); | ||
impl Violation for WhitespaceBeforeCloseBracket { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Whitespace before ')'") | ||
} | ||
} | ||
|
||
define_violation!( | ||
pub struct WhitespaceBeforePunctuation; | ||
); | ||
impl Violation for WhitespaceBeforePunctuation { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Whitespace before ',', ';', or ':'") | ||
} | ||
} | ||
|
||
// TODO(charlie): Pycodestyle has a negative lookahead on the end. | ||
static EXTRANEOUS_WHITESPACE_REGEX: Lazy<Regex> = | ||
Lazy::new(|| Regex::new(r"([\[({][ \t]|[ \t][]}),;:])").unwrap()); | ||
|
||
/// E201, E202, E203 | ||
pub fn extraneous_whitespace(line: &str) -> Vec<(usize, DiagnosticKind)> { | ||
let mut diagnostics = vec![]; | ||
for line_match in EXTRANEOUS_WHITESPACE_REGEX.captures_iter(line) { | ||
let match_ = line_match.get(1).unwrap(); | ||
let text = match_.as_str(); | ||
let char = text.trim(); | ||
let found = match_.start(); | ||
if text.chars().last().unwrap().is_ascii_whitespace() { | ||
diagnostics.push((found + 1, WhitespaceAfterOpenBracket.into())); | ||
} else if line.chars().nth(found - 1).map_or(false, |c| c != ',') { | ||
if char == "}" || char == "]" || char == ")" { | ||
diagnostics.push((found, WhitespaceBeforeCloseBracket.into())); | ||
} else { | ||
diagnostics.push((found, WhitespaceBeforePunctuation.into())); | ||
} | ||
} | ||
} | ||
diagnostics | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.