Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multiple-statements-on-one-line-def (E704) #2773

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
7 changes: 2 additions & 5 deletions crates/ruff/src/checkers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions crates/ruff/src/flake8_to_ruff/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions crates/ruff/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -774,7 +773,6 @@ impl Rule {
| Rule::TrailingCommaOnBareTupleProhibited
| Rule::MultipleStatementsOnOneLineColon
| Rule::UselessSemicolon
| Rule::MultipleStatementsOnOneLineDef
| Rule::MultipleStatementsOnOneLineSemicolon
| Rule::TrailingCommaProhibited => &LintSource::Tokens,
Rule::IOError => &LintSource::Io,
Expand Down
1 change: 0 additions & 1 deletion crates/ruff/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
35 changes: 5 additions & 30 deletions crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +92,6 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
}

// Reset.
def = None;
colon = None;
semi = None;
class = None;
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pycodestyle/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

This file was deleted.