diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index ab0269011c0d6..2e2f1773a271b 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -1,5 +1,12 @@ # 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 ### Ruff's public `check` method was removed ([#2709](https://github.com/charliermarsh/ruff/pull/2709)) diff --git a/crates/ruff/src/checkers/tokens.rs b/crates/ruff/src/checkers/tokens.rs index fb917e29256e7..d717cad113168 100644 --- a/crates/ruff/src/checkers/tokens.rs +++ b/crates/ruff/src/checkers/tokens.rs @@ -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) diff --git a/crates/ruff/src/flake8_to_ruff/parser.rs b/crates/ruff/src/flake8_to_ruff/parser.rs index ea5df04e7c826..7086a28b33c0c 100644 --- a/crates/ruff/src/flake8_to_ruff/parser.rs +++ b/crates/ruff/src/flake8_to_ruff/parser.rs @@ -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); diff --git a/crates/ruff/src/registry.rs b/crates/ruff/src/registry.rs index b0defef7dc368..62a0ffddf2827 100644 --- a/crates/ruff/src/registry.rs +++ b/crates/ruff/src/registry.rs @@ -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, diff --git a/crates/ruff/src/rules/pycodestyle/mod.rs b/crates/ruff/src/rules/pycodestyle/mod.rs index b327146363735..29ff7b1f49bae 100644 --- a/crates/ruff/src/rules/pycodestyle/mod.rs +++ b/crates/ruff/src/rules/pycodestyle/mod.rs @@ -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"))] diff --git a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs index acee1acc70194..dc2b0e14cb721 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs @@ -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 { 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 { } // Reset. - def = None; colon = None; semi = None; class = None; @@ -117,12 +105,8 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec { 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 { } 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 { match tok { Tok::Lambda => { // Reset. - def = None; colon = None; class = None; elif = None; diff --git a/crates/ruff/src/rules/pycodestyle/rules/mod.rs b/crates/ruff/src/rules/pycodestyle/rules/mod.rs index 7508295813361..fac841d18f583 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/mod.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/mod.rs @@ -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}; diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E704_E70.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E704_E70.py.snap deleted file mode 100644 index af2e1ee93402f..0000000000000 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E704_E70.py.snap +++ /dev/null @@ -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: ~ -