mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Remove multiple-statements-on-one-line-def (E704) (#2773)
This commit is contained in:
parent
43b7ee215c
commit
ffb4e89a98
8 changed files with 16 additions and 99 deletions
|
@ -40,10 +40,7 @@ pub fn check_tokens(
|
|||
|| settings
|
||||
.rules
|
||||
.enabled(&Rule::MultipleStatementsOnOneLineSemicolon)
|
||||
|| settings.rules.enabled(&Rule::UselessSemicolon)
|
||||
|| settings
|
||||
.rules
|
||||
.enabled(&Rule::MultipleStatementsOnOneLineDef);
|
||||
|| settings.rules.enabled(&Rule::UselessSemicolon);
|
||||
let enforce_invalid_escape_sequence = settings.rules.enabled(&Rule::InvalidEscapeSequence);
|
||||
let enforce_implicit_string_concatenation = settings
|
||||
.rules
|
||||
|
@ -117,7 +114,7 @@ pub fn check_tokens(
|
|||
}
|
||||
}
|
||||
|
||||
// E701, E702, E703, E704
|
||||
// E701, E702, E703
|
||||
if enforce_compound_statements {
|
||||
diagnostics.extend(
|
||||
pycodestyle::rules::compound_statements(tokens)
|
||||
|
|
|
@ -282,10 +282,6 @@ mod tests {
|
|||
pattern: "examples/*".to_string(),
|
||||
prefix: RuleCodePrefix::F841.into(),
|
||||
},
|
||||
PatternPrefixPair {
|
||||
pattern: "*.pyi".to_string(),
|
||||
prefix: RuleCodePrefix::E704.into(),
|
||||
},
|
||||
];
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ ruff_macros::define_rule_mapping!(
|
|||
E701 => rules::pycodestyle::rules::MultipleStatementsOnOneLineColon,
|
||||
E702 => rules::pycodestyle::rules::MultipleStatementsOnOneLineSemicolon,
|
||||
E703 => rules::pycodestyle::rules::UselessSemicolon,
|
||||
E704 => rules::pycodestyle::rules::MultipleStatementsOnOneLineDef,
|
||||
E711 => rules::pycodestyle::rules::NoneComparison,
|
||||
E712 => rules::pycodestyle::rules::TrueFalseComparison,
|
||||
E713 => rules::pycodestyle::rules::NotInTest,
|
||||
|
@ -774,7 +773,6 @@ impl Rule {
|
|||
| Rule::TrailingCommaOnBareTupleProhibited
|
||||
| Rule::MultipleStatementsOnOneLineColon
|
||||
| Rule::UselessSemicolon
|
||||
| Rule::MultipleStatementsOnOneLineDef
|
||||
| Rule::MultipleStatementsOnOneLineSemicolon
|
||||
| Rule::TrailingCommaProhibited => &LintSource::Tokens,
|
||||
Rule::IOError => &LintSource::Io,
|
||||
|
|
|
@ -30,7 +30,6 @@ mod tests {
|
|||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402.py"))]
|
||||
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
||||
#[test_case(Rule::MultipleStatementsOnOneLineColon, Path::new("E70.py"))]
|
||||
#[test_case(Rule::MultipleStatementsOnOneLineDef, Path::new("E70.py"))]
|
||||
#[test_case(Rule::MultipleStatementsOnOneLineSemicolon, Path::new("E70.py"))]
|
||||
#[test_case(Rule::NoNewLineAtEndOfFile, Path::new("W292_0.py"))]
|
||||
#[test_case(Rule::NoNewLineAtEndOfFile, Path::new("W292_1.py"))]
|
||||
|
|
|
@ -36,21 +36,10 @@ impl Violation for UselessSemicolon {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct MultipleStatementsOnOneLineDef;
|
||||
);
|
||||
impl Violation for MultipleStatementsOnOneLineDef {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Multiple statements on one line (def)")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||
let mut diagnostics = vec![];
|
||||
|
||||
// Track the last seen instance of a variety of tokens.
|
||||
let mut def = None;
|
||||
let mut colon = None;
|
||||
let mut semi = None;
|
||||
let mut class = None;
|
||||
|
@ -103,7 +92,6 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
}
|
||||
|
||||
// Reset.
|
||||
def = None;
|
||||
colon = None;
|
||||
semi = None;
|
||||
class = None;
|
||||
|
@ -117,12 +105,8 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
while_ = None;
|
||||
with = None;
|
||||
}
|
||||
Tok::Def => {
|
||||
def = Some((start, end));
|
||||
}
|
||||
Tok::Colon => {
|
||||
if def.is_some()
|
||||
|| class.is_some()
|
||||
if class.is_some()
|
||||
|| elif.is_some()
|
||||
|| else_.is_some()
|
||||
|| except.is_some()
|
||||
|
@ -152,20 +136,12 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
}
|
||||
|
||||
if let Some((start, end)) = colon {
|
||||
if let Some((start, end)) = def {
|
||||
diagnostics.push(Diagnostic::new(
|
||||
MultipleStatementsOnOneLineDef,
|
||||
Range::new(start, end),
|
||||
));
|
||||
} else {
|
||||
diagnostics.push(Diagnostic::new(
|
||||
MultipleStatementsOnOneLineColon,
|
||||
Range::new(start, end),
|
||||
));
|
||||
}
|
||||
diagnostics.push(Diagnostic::new(
|
||||
MultipleStatementsOnOneLineColon,
|
||||
Range::new(start, end),
|
||||
));
|
||||
|
||||
// Reset.
|
||||
def = None;
|
||||
colon = None;
|
||||
class = None;
|
||||
elif = None;
|
||||
|
@ -184,7 +160,6 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
match tok {
|
||||
Tok::Lambda => {
|
||||
// Reset.
|
||||
def = None;
|
||||
colon = None;
|
||||
class = None;
|
||||
elif = None;
|
||||
|
|
|
@ -3,8 +3,8 @@ pub use ambiguous_function_name::{ambiguous_function_name, AmbiguousFunctionName
|
|||
pub use ambiguous_variable_name::{ambiguous_variable_name, AmbiguousVariableName};
|
||||
pub use bare_except::{bare_except, BareExcept};
|
||||
pub use compound_statements::{
|
||||
compound_statements, MultipleStatementsOnOneLineColon, MultipleStatementsOnOneLineDef,
|
||||
MultipleStatementsOnOneLineSemicolon, UselessSemicolon,
|
||||
compound_statements, MultipleStatementsOnOneLineColon, MultipleStatementsOnOneLineSemicolon,
|
||||
UselessSemicolon,
|
||||
};
|
||||
pub use doc_line_too_long::{doc_line_too_long, DocLineTooLong};
|
||||
pub use errors::{syntax_error, IOError, SyntaxError};
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/pycodestyle/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineDef: ~
|
||||
location:
|
||||
row: 14
|
||||
column: 0
|
||||
end_location:
|
||||
row: 14
|
||||
column: 3
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineDef: ~
|
||||
location:
|
||||
row: 16
|
||||
column: 6
|
||||
end_location:
|
||||
row: 16
|
||||
column: 9
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineDef: ~
|
||||
location:
|
||||
row: 18
|
||||
column: 7
|
||||
end_location:
|
||||
row: 18
|
||||
column: 10
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineDef: ~
|
||||
location:
|
||||
row: 20
|
||||
column: 0
|
||||
end_location:
|
||||
row: 20
|
||||
column: 3
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineDef: ~
|
||||
location:
|
||||
row: 23
|
||||
column: 4
|
||||
end_location:
|
||||
row: 23
|
||||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue