Skip to content

Commit

Permalink
Revert "Replace logical_lines feature with debug_assertions (#3648)…
Browse files Browse the repository at this point in the history
…" (#3708)
  • Loading branch information
JonathanPlasse authored Mar 24, 2023
1 parent efc6e8c commit 1bac206
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 89 deletions.
1 change: 1 addition & 0 deletions crates/ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ test-case = { workspace = true }

[features]
default = []
logical_lines = []
jupyter_notebook = []
8 changes: 4 additions & 4 deletions crates/ruff/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ pub fn check_logical_lines(
}
}

#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
let should_fix = autofix.into() && settings.rules.should_fix(Rule::MissingWhitespace);

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
let should_fix = false;

for diagnostic in
Expand All @@ -181,11 +181,11 @@ pub fn check_logical_lines(
}

if line.flags.contains(TokenFlags::BRACKET) {
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
let should_fix =
autofix.into() && settings.rules.should_fix(Rule::WhitespaceBeforeParameters);

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
let should_fix = false;

for diagnostic in whitespace_before_parameters(&line.tokens, should_fix) {
Expand Down
62 changes: 31 additions & 31 deletions crates/ruff/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,67 +26,67 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
Some(match (linter, code) {
// pycodestyle errors
(Pycodestyle, "E101") => Rule::MixedSpacesAndTabs,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E111") => Rule::IndentationWithInvalidMultiple,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E112") => Rule::NoIndentedBlock,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E113") => Rule::UnexpectedIndentation,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E114") => Rule::IndentationWithInvalidMultipleComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E115") => Rule::NoIndentedBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E116") => Rule::UnexpectedIndentationComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E117") => Rule::OverIndented,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E201") => Rule::WhitespaceAfterOpenBracket,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E202") => Rule::WhitespaceBeforeCloseBracket,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E203") => Rule::WhitespaceBeforePunctuation,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E211") => Rule::WhitespaceBeforeParameters,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E221") => Rule::MultipleSpacesBeforeOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E222") => Rule::MultipleSpacesAfterOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E223") => Rule::TabBeforeOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E224") => Rule::TabAfterOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E225") => Rule::MissingWhitespaceAroundOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E226") => Rule::MissingWhitespaceAroundArithmeticOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E227") => Rule::MissingWhitespaceAroundBitwiseOrShiftOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E228") => Rule::MissingWhitespaceAroundModuloOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E231") => Rule::MissingWhitespace,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E251") => Rule::UnexpectedSpacesAroundKeywordParameterEquals,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E252") => Rule::MissingWhitespaceAroundParameterEquals,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E261") => Rule::TooFewSpacesBeforeInlineComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E262") => Rule::NoSpaceAfterInlineComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E265") => Rule::NoSpaceAfterBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E266") => Rule::MultipleLeadingHashesForBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E271") => Rule::MultipleSpacesAfterKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E272") => Rule::MultipleSpacesBeforeKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E273") => Rule::TabAfterKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E274") => Rule::TabBeforeKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
(Pycodestyle, "E275") => Rule::MissingWhitespaceAfterKeyword,
(Pycodestyle, "E401") => Rule::MultipleImportsOnOneLine,
(Pycodestyle, "E402") => Rule::ModuleImportNotAtTopOfFile,
Expand Down
64 changes: 32 additions & 32 deletions crates/ruff/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,67 @@ pub use rule_set::{RuleSet, RuleSetIterator};
ruff_macros::register_rules!(
// pycodestyle errors
rules::pycodestyle::rules::MixedSpacesAndTabs,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::IndentationWithInvalidMultiple,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::NoIndentedBlock,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::UnexpectedIndentation,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::IndentationWithInvalidMultipleComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::NoIndentedBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::UnexpectedIndentationComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::OverIndented,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::WhitespaceAfterOpenBracket,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::WhitespaceBeforeCloseBracket,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::WhitespaceBeforePunctuation,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MultipleSpacesBeforeOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MultipleSpacesAfterOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::TabBeforeOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::TabAfterOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::TooFewSpacesBeforeInlineComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::NoSpaceAfterInlineComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::NoSpaceAfterBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MultipleLeadingHashesForBlockComment,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MultipleSpacesAfterKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespace,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAfterKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MultipleSpacesBeforeKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAroundOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAroundArithmeticOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAroundBitwiseOrShiftOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAroundModuloOperator,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::TabAfterKeyword,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::UnexpectedSpacesAroundKeywordParameterEquals,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::MissingWhitespaceAroundParameterEquals,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::WhitespaceBeforeParameters,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
rules::pycodestyle::rules::TabBeforeKeyword,
rules::pycodestyle::rules::MultipleImportsOnOneLine,
rules::pycodestyle::rules::ModuleImportNotAtTopOfFile,
Expand Down Expand Up @@ -906,7 +906,7 @@ impl Rule {
Rule::IOError => LintSource::Io,
Rule::UnsortedImports | Rule::MissingRequiredImport => LintSource::Imports,
Rule::ImplicitNamespacePackage | Rule::InvalidModuleName => LintSource::Filesystem,
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
Rule::IndentationWithInvalidMultiple
| Rule::IndentationWithInvalidMultipleComment
| Rule::MissingWhitespace
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
Ok(())
}

#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
#[test_case(Rule::IndentationWithInvalidMultiple, Path::new("E11.py"))]
#[test_case(Rule::IndentationWithInvalidMultipleComment, Path::new("E11.py"))]
#[test_case(Rule::MultipleLeadingHashesForBlockComment, Path::new("E26.py"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static EXTRANEOUS_WHITESPACE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"([\[({][ \t]|[ \t][]}),;:])").unwrap());

/// E201, E202, E203
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn extraneous_whitespace(line: &str) -> Vec<(usize, DiagnosticKind)> {
let mut diagnostics = vec![];
for line_match in EXTRANEOUS_WHITESPACE_REGEX.captures_iter(line) {
Expand All @@ -127,7 +127,7 @@ pub fn extraneous_whitespace(line: &str) -> Vec<(usize, DiagnosticKind)> {
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn extraneous_whitespace(_line: &str) -> Vec<(usize, DiagnosticKind)> {
vec![]
}
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pycodestyle/rules/indentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Violation for OverIndented {
}

/// E111, E114, E112, E113, E115, E116, E117
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn indentation(
logical_line: &LogicalLine,
prev_logical_line: Option<&LogicalLine>,
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn indentation(
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn indentation(
_logical_line: &LogicalLine,
_prev_logical_line: Option<&LogicalLine>,
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pycodestyle/rules/missing_whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl AlwaysAutofixableViolation for MissingWhitespace {
}

/// E231
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn missing_whitespace(
line: &str,
row: usize,
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn missing_whitespace(
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn missing_whitespace(
_line: &str,
_row: usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Violation for MissingWhitespaceAfterKeyword {
}

/// E275
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn missing_whitespace_after_keyword(
tokens: &[(Location, &Tok, Location)],
) -> Vec<(Location, DiagnosticKind)> {
Expand All @@ -43,7 +43,7 @@ pub fn missing_whitespace_after_keyword(
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn missing_whitespace_after_keyword(
_tokens: &[(Location, &Tok, Location)],
) -> Vec<(Location, DiagnosticKind)> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Violation for MissingWhitespaceAroundModuloOperator {
}

/// E225, E226, E227, E228
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
#[allow(clippy::if_same_then_else)]
pub fn missing_whitespace_around_operator(
tokens: &[(Location, &Tok, Location)],
Expand Down Expand Up @@ -188,7 +188,7 @@ pub fn missing_whitespace_around_operator(
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn missing_whitespace_around_operator(
_tokens: &[(Location, &Tok, Location)],
) -> Vec<(Location, DiagnosticKind)> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static OPERATOR_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"[^,\s](\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)").unwrap());

/// E221, E222, E223, E224
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn space_around_operator(line: &str) -> Vec<(usize, DiagnosticKind)> {
let mut diagnostics = vec![];
for line_match in OPERATOR_REGEX.captures_iter(line) {
Expand All @@ -149,7 +149,7 @@ pub fn space_around_operator(line: &str) -> Vec<(usize, DiagnosticKind)> {
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn space_around_operator(_line: &str) -> Vec<(usize, DiagnosticKind)> {
vec![]
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static KEYWORD_REGEX: Lazy<Regex> = Lazy::new(|| {
});

/// E271, E272, E273, E274
#[cfg(debug_assertions)]
#[cfg(feature = "logical_lines")]
pub fn whitespace_around_keywords(line: &str) -> Vec<(usize, DiagnosticKind)> {
let mut diagnostics = vec![];
for line_match in KEYWORD_REGEX.captures_iter(line) {
Expand All @@ -137,7 +137,7 @@ pub fn whitespace_around_keywords(line: &str) -> Vec<(usize, DiagnosticKind)> {
diagnostics
}

#[cfg(not(debug_assertions))]
#[cfg(not(feature = "logical_lines"))]
pub fn whitespace_around_keywords(_line: &str) -> Vec<(usize, DiagnosticKind)> {
vec![]
}
Loading

0 comments on commit 1bac206

Please sign in to comment.