mirror of https://github.com/astral-sh/ruff
Remove multiple-statements-on-one-line-def (E704) (#2773)
This commit is contained in:
parent
43b7ee215c
commit
ffb4e89a98
|
|
@ -1,5 +1,12 @@
|
||||||
# Breaking Changes
|
# Breaking Changes
|
||||||
|
|
||||||
|
## 0.0.246
|
||||||
|
|
||||||
|
### `multiple-statements-on-one-line-def` (`E704`) was removed ([#2773](https://github.com/charliermarsh/ruff/pull/2773))
|
||||||
|
|
||||||
|
This rule was introduced in v0.0.245. However, it turns out that pycodestyle and Flake8 ignore this
|
||||||
|
rule by default, as it is not part of PEP 8. As such, we've removed it from Ruff.
|
||||||
|
|
||||||
## 0.0.245
|
## 0.0.245
|
||||||
|
|
||||||
### Ruff's public `check` method was removed ([#2709](https://github.com/charliermarsh/ruff/pull/2709))
|
### Ruff's public `check` method was removed ([#2709](https://github.com/charliermarsh/ruff/pull/2709))
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,7 @@ pub fn check_tokens(
|
||||||
|| settings
|
|| settings
|
||||||
.rules
|
.rules
|
||||||
.enabled(&Rule::MultipleStatementsOnOneLineSemicolon)
|
.enabled(&Rule::MultipleStatementsOnOneLineSemicolon)
|
||||||
|| settings.rules.enabled(&Rule::UselessSemicolon)
|
|| settings.rules.enabled(&Rule::UselessSemicolon);
|
||||||
|| settings
|
|
||||||
.rules
|
|
||||||
.enabled(&Rule::MultipleStatementsOnOneLineDef);
|
|
||||||
let enforce_invalid_escape_sequence = settings.rules.enabled(&Rule::InvalidEscapeSequence);
|
let enforce_invalid_escape_sequence = settings.rules.enabled(&Rule::InvalidEscapeSequence);
|
||||||
let enforce_implicit_string_concatenation = settings
|
let enforce_implicit_string_concatenation = settings
|
||||||
.rules
|
.rules
|
||||||
|
|
@ -117,7 +114,7 @@ pub fn check_tokens(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// E701, E702, E703, E704
|
// E701, E702, E703
|
||||||
if enforce_compound_statements {
|
if enforce_compound_statements {
|
||||||
diagnostics.extend(
|
diagnostics.extend(
|
||||||
pycodestyle::rules::compound_statements(tokens)
|
pycodestyle::rules::compound_statements(tokens)
|
||||||
|
|
|
||||||
|
|
@ -282,10 +282,6 @@ mod tests {
|
||||||
pattern: "examples/*".to_string(),
|
pattern: "examples/*".to_string(),
|
||||||
prefix: RuleCodePrefix::F841.into(),
|
prefix: RuleCodePrefix::F841.into(),
|
||||||
},
|
},
|
||||||
PatternPrefixPair {
|
|
||||||
pattern: "*.pyi".to_string(),
|
|
||||||
prefix: RuleCodePrefix::E704.into(),
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ ruff_macros::define_rule_mapping!(
|
||||||
E701 => rules::pycodestyle::rules::MultipleStatementsOnOneLineColon,
|
E701 => rules::pycodestyle::rules::MultipleStatementsOnOneLineColon,
|
||||||
E702 => rules::pycodestyle::rules::MultipleStatementsOnOneLineSemicolon,
|
E702 => rules::pycodestyle::rules::MultipleStatementsOnOneLineSemicolon,
|
||||||
E703 => rules::pycodestyle::rules::UselessSemicolon,
|
E703 => rules::pycodestyle::rules::UselessSemicolon,
|
||||||
E704 => rules::pycodestyle::rules::MultipleStatementsOnOneLineDef,
|
|
||||||
E711 => rules::pycodestyle::rules::NoneComparison,
|
E711 => rules::pycodestyle::rules::NoneComparison,
|
||||||
E712 => rules::pycodestyle::rules::TrueFalseComparison,
|
E712 => rules::pycodestyle::rules::TrueFalseComparison,
|
||||||
E713 => rules::pycodestyle::rules::NotInTest,
|
E713 => rules::pycodestyle::rules::NotInTest,
|
||||||
|
|
@ -774,7 +773,6 @@ impl Rule {
|
||||||
| Rule::TrailingCommaOnBareTupleProhibited
|
| Rule::TrailingCommaOnBareTupleProhibited
|
||||||
| Rule::MultipleStatementsOnOneLineColon
|
| Rule::MultipleStatementsOnOneLineColon
|
||||||
| Rule::UselessSemicolon
|
| Rule::UselessSemicolon
|
||||||
| Rule::MultipleStatementsOnOneLineDef
|
|
||||||
| Rule::MultipleStatementsOnOneLineSemicolon
|
| Rule::MultipleStatementsOnOneLineSemicolon
|
||||||
| Rule::TrailingCommaProhibited => &LintSource::Tokens,
|
| Rule::TrailingCommaProhibited => &LintSource::Tokens,
|
||||||
Rule::IOError => &LintSource::Io,
|
Rule::IOError => &LintSource::Io,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ mod tests {
|
||||||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402.py"))]
|
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402.py"))]
|
||||||
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
||||||
#[test_case(Rule::MultipleStatementsOnOneLineColon, Path::new("E70.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::MultipleStatementsOnOneLineSemicolon, Path::new("E70.py"))]
|
||||||
#[test_case(Rule::NoNewLineAtEndOfFile, Path::new("W292_0.py"))]
|
#[test_case(Rule::NoNewLineAtEndOfFile, Path::new("W292_0.py"))]
|
||||||
#[test_case(Rule::NoNewLineAtEndOfFile, Path::new("W292_1.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> {
|
pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
let mut diagnostics = vec![];
|
let mut diagnostics = vec![];
|
||||||
|
|
||||||
// Track the last seen instance of a variety of tokens.
|
// Track the last seen instance of a variety of tokens.
|
||||||
let mut def = None;
|
|
||||||
let mut colon = None;
|
let mut colon = None;
|
||||||
let mut semi = None;
|
let mut semi = None;
|
||||||
let mut class = None;
|
let mut class = None;
|
||||||
|
|
@ -103,7 +92,6 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset.
|
// Reset.
|
||||||
def = None;
|
|
||||||
colon = None;
|
colon = None;
|
||||||
semi = None;
|
semi = None;
|
||||||
class = None;
|
class = None;
|
||||||
|
|
@ -117,12 +105,8 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
while_ = None;
|
while_ = None;
|
||||||
with = None;
|
with = None;
|
||||||
}
|
}
|
||||||
Tok::Def => {
|
|
||||||
def = Some((start, end));
|
|
||||||
}
|
|
||||||
Tok::Colon => {
|
Tok::Colon => {
|
||||||
if def.is_some()
|
if class.is_some()
|
||||||
|| class.is_some()
|
|
||||||
|| elif.is_some()
|
|| elif.is_some()
|
||||||
|| else_.is_some()
|
|| else_.is_some()
|
||||||
|| except.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)) = colon {
|
||||||
if let Some((start, end)) = def {
|
|
||||||
diagnostics.push(Diagnostic::new(
|
|
||||||
MultipleStatementsOnOneLineDef,
|
|
||||||
Range::new(start, end),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
diagnostics.push(Diagnostic::new(
|
diagnostics.push(Diagnostic::new(
|
||||||
MultipleStatementsOnOneLineColon,
|
MultipleStatementsOnOneLineColon,
|
||||||
Range::new(start, end),
|
Range::new(start, end),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
// Reset.
|
// Reset.
|
||||||
def = None;
|
|
||||||
colon = None;
|
colon = None;
|
||||||
class = None;
|
class = None;
|
||||||
elif = None;
|
elif = None;
|
||||||
|
|
@ -184,7 +160,6 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
match tok {
|
match tok {
|
||||||
Tok::Lambda => {
|
Tok::Lambda => {
|
||||||
// Reset.
|
// Reset.
|
||||||
def = None;
|
|
||||||
colon = None;
|
colon = None;
|
||||||
class = None;
|
class = None;
|
||||||
elif = 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 ambiguous_variable_name::{ambiguous_variable_name, AmbiguousVariableName};
|
||||||
pub use bare_except::{bare_except, BareExcept};
|
pub use bare_except::{bare_except, BareExcept};
|
||||||
pub use compound_statements::{
|
pub use compound_statements::{
|
||||||
compound_statements, MultipleStatementsOnOneLineColon, MultipleStatementsOnOneLineDef,
|
compound_statements, MultipleStatementsOnOneLineColon, MultipleStatementsOnOneLineSemicolon,
|
||||||
MultipleStatementsOnOneLineSemicolon, UselessSemicolon,
|
UselessSemicolon,
|
||||||
};
|
};
|
||||||
pub use doc_line_too_long::{doc_line_too_long, DocLineTooLong};
|
pub use doc_line_too_long::{doc_line_too_long, DocLineTooLong};
|
||||||
pub use errors::{syntax_error, IOError, SyntaxError};
|
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…
Reference in New Issue