-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(W191): add indentation_contains_tabs (#3249)
- Loading branch information
1 parent
d285f5c
commit e8ba9c9
Showing
12 changed files
with
591 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#: W191 | ||
if False: | ||
print # indented with 1 tab | ||
#: | ||
|
||
|
||
#: W191 | ||
y = x == 2 \ | ||
or x == 3 | ||
#: E101 W191 W504 | ||
if ( | ||
x == ( | ||
3 | ||
) or | ||
y == 4): | ||
pass | ||
#: E101 W191 | ||
if x == 2 \ | ||
or y > 1 \ | ||
or x == 3: | ||
pass | ||
#: E101 W191 | ||
if x == 2 \ | ||
or y > 1 \ | ||
or x == 3: | ||
pass | ||
#: | ||
|
||
#: E101 W191 W504 | ||
if (foo == bar and | ||
baz == bop): | ||
pass | ||
#: E101 W191 W504 | ||
if ( | ||
foo == bar and | ||
baz == bop | ||
): | ||
pass | ||
#: | ||
|
||
#: E101 E101 W191 W191 | ||
if start[1] > end_col and not ( | ||
over_indent == 4 and indent_next): | ||
return (0, "E121 continuation line over-" | ||
"indented for visual indent") | ||
#: | ||
|
||
#: E101 W191 | ||
|
||
|
||
def long_function_name( | ||
var_one, var_two, var_three, | ||
var_four): | ||
print(var_one) | ||
#: E101 W191 W504 | ||
if ((row < 0 or self.moduleCount <= row or | ||
col < 0 or self.moduleCount <= col)): | ||
raise Exception("%s,%s - %s" % (row, col, self.moduleCount)) | ||
#: E101 E101 E101 E101 W191 W191 W191 W191 W191 W191 | ||
if bar: | ||
return ( | ||
start, 'E121 lines starting with a ' | ||
'closing bracket should be indented ' | ||
"to match that of the opening " | ||
"bracket's line" | ||
) | ||
# | ||
#: E101 W191 W504 | ||
# you want vertical alignment, so use a parens | ||
if ((foo.bar("baz") and | ||
foo.bar("bop") | ||
)): | ||
print "yes" | ||
#: E101 W191 W504 | ||
# also ok, but starting to look like LISP | ||
if ((foo.bar("baz") and | ||
foo.bar("bop"))): | ||
print "yes" | ||
#: E101 W191 W504 | ||
if (a == 2 or | ||
b == "abc def ghi" | ||
"jkl mno"): | ||
return True | ||
#: E101 W191 W504 | ||
if (a == 2 or | ||
b == """abc def ghi | ||
jkl mno"""): | ||
return True | ||
#: W191:2:1 W191:3:1 E101:3:2 | ||
if length > options.max_line_length: | ||
return options.max_line_length, \ | ||
"E501 line too long (%d characters)" % length | ||
|
||
|
||
# | ||
#: E101 W191 W191 W504 | ||
if os.path.exists(os.path.join(path, PEP8_BIN)): | ||
cmd = ([os.path.join(path, PEP8_BIN)] + | ||
self._pep8_options(targetfile)) | ||
#: W191 | ||
''' | ||
multiline string with tab in it''' | ||
#: E101 W191 | ||
'''multiline string | ||
with tabs | ||
and spaces | ||
''' | ||
#: Okay | ||
'''sometimes, you just need to go nuts in a multiline string | ||
and allow all sorts of crap | ||
like mixed tabs and spaces | ||
or trailing whitespace | ||
or long long long long long long long long long long long long long long long long long lines | ||
''' # nopep8 | ||
#: Okay | ||
'''this one | ||
will get no warning | ||
even though the noqa comment is not immediately after the string | ||
''' + foo # noqa | ||
# | ||
#: E101 W191 | ||
if foo is None and bar is "bop" and \ | ||
blah == 'yeah': | ||
blah = 'yeahnah' | ||
|
||
|
||
# | ||
#: W191 W191 W191 | ||
if True: | ||
foo( | ||
1, | ||
2) | ||
#: W191 W191 W191 W191 W191 | ||
def test_keys(self): | ||
"""areas.json - All regions are accounted for.""" | ||
expected = set([ | ||
u'Norrbotten', | ||
u'V\xe4sterbotten', | ||
]) | ||
#: W191 | ||
x = [ | ||
'abc' | ||
] | ||
#: |
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
34 changes: 34 additions & 0 deletions
34
crates/ruff/src/rules/pycodestyle/rules/indentation_contains_tabs.rs
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,34 @@ | ||
use ruff_macros::{define_violation, derive_message_formats}; | ||
use rustpython_parser::ast::Location; | ||
|
||
use crate::ast::types::Range; | ||
use crate::ast::whitespace::leading_space; | ||
use crate::registry::Diagnostic; | ||
use crate::violation::Violation; | ||
|
||
define_violation!( | ||
pub struct IndentationContainsTabs; | ||
); | ||
impl Violation for IndentationContainsTabs { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Indentation contains tabs") | ||
} | ||
} | ||
|
||
/// W191 | ||
pub fn indentation_contains_tabs(lineno: usize, line: &str) -> Option<Diagnostic> { | ||
let indent = leading_space(line); | ||
|
||
if indent.contains('\t') { | ||
Some(Diagnostic::new( | ||
IndentationContainsTabs, | ||
Range::new( | ||
Location::new(lineno + 1, 0), | ||
Location::new(lineno + 1, indent.chars().count()), | ||
), | ||
)) | ||
} else { | ||
None | ||
} | ||
} |
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.