Skip to content

Commit

Permalink
Replace logical_lines feature with debug_assertions (astral-sh#3648)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Mar 21, 2023
1 parent 3b1709b commit 27903cd
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 93 deletions.
1 change: 0 additions & 1 deletion crates/ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ 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(feature = "logical_lines")]
#[cfg(debug_assertions)]
let should_fix = autofix.into() && settings.rules.should_fix(Rule::MissingWhitespace);

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

for diagnostic in missing_whitespace(&line.text, start_loc.row(), should_fix) {
Expand All @@ -179,11 +179,11 @@ pub fn check_logical_lines(
}

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

#[cfg(not(feature = "logical_lines"))]
#[cfg(not(debug_assertions))]
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(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E111") => Rule::IndentationWithInvalidMultiple,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E112") => Rule::NoIndentedBlock,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E113") => Rule::UnexpectedIndentation,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E114") => Rule::IndentationWithInvalidMultipleComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E115") => Rule::NoIndentedBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E116") => Rule::UnexpectedIndentationComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E117") => Rule::OverIndented,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E201") => Rule::WhitespaceAfterOpenBracket,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E202") => Rule::WhitespaceBeforeCloseBracket,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E203") => Rule::WhitespaceBeforePunctuation,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E211") => Rule::WhitespaceBeforeParameters,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E221") => Rule::MultipleSpacesBeforeOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E222") => Rule::MultipleSpacesAfterOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E223") => Rule::TabBeforeOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E224") => Rule::TabAfterOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E225") => Rule::MissingWhitespaceAroundOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E226") => Rule::MissingWhitespaceAroundArithmeticOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E227") => Rule::MissingWhitespaceAroundBitwiseOrShiftOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E228") => Rule::MissingWhitespaceAroundModuloOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E231") => Rule::MissingWhitespace,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E251") => Rule::UnexpectedSpacesAroundKeywordParameterEquals,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E252") => Rule::MissingWhitespaceAroundParameterEquals,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E261") => Rule::TooFewSpacesBeforeInlineComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E262") => Rule::NoSpaceAfterInlineComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E265") => Rule::NoSpaceAfterBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E266") => Rule::MultipleLeadingHashesForBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E271") => Rule::MultipleSpacesAfterKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E272") => Rule::MultipleSpacesBeforeKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E273") => Rule::TabAfterKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(Pycodestyle, "E274") => Rule::TabBeforeKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
(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(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::IndentationWithInvalidMultiple,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::NoIndentedBlock,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::UnexpectedIndentation,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::IndentationWithInvalidMultipleComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::NoIndentedBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::UnexpectedIndentationComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::OverIndented,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::WhitespaceAfterOpenBracket,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::WhitespaceBeforeCloseBracket,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::WhitespaceBeforePunctuation,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MultipleSpacesBeforeOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MultipleSpacesAfterOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::TabBeforeOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::TabAfterOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::TooFewSpacesBeforeInlineComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::NoSpaceAfterInlineComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::NoSpaceAfterBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MultipleLeadingHashesForBlockComment,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MultipleSpacesAfterKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespace,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAfterKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MultipleSpacesBeforeKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAroundOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAroundArithmeticOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAroundBitwiseOrShiftOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAroundModuloOperator,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::TabAfterKeyword,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::UnexpectedSpacesAroundKeywordParameterEquals,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::MissingWhitespaceAroundParameterEquals,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::WhitespaceBeforeParameters,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
rules::pycodestyle::rules::TabBeforeKeyword,
rules::pycodestyle::rules::MultipleImportsOnOneLine,
rules::pycodestyle::rules::ModuleImportNotAtTopOfFile,
Expand Down Expand Up @@ -884,7 +884,7 @@ impl Rule {
Rule::IOError => LintSource::Io,
Rule::UnsortedImports | Rule::MissingRequiredImport => LintSource::Imports,
Rule::ImplicitNamespacePackage | Rule::InvalidModuleName => LintSource::Filesystem,
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
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(feature = "logical_lines")]
#[cfg(debug_assertions)]
#[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(feature = "logical_lines")]
#[cfg(debug_assertions)]
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(feature = "logical_lines"))]
#[cfg(not(debug_assertions))]
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(feature = "logical_lines")]
#[cfg(debug_assertions)]
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(feature = "logical_lines"))]
#[cfg(not(debug_assertions))]
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 @@ -32,7 +32,7 @@ impl AlwaysAutofixableViolation for MissingWhitespace {
}

/// E231
#[cfg(feature = "logical_lines")]
#[cfg(debug_assertions)]
pub fn missing_whitespace(line: &str, row: usize, autofix: bool) -> Vec<Diagnostic> {
let mut diagnostics = vec![];
for (idx, char) in line.chars().enumerate() {
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn missing_whitespace(line: &str, row: usize, autofix: bool) -> Vec<Diagnost
diagnostics
}

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

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

0 comments on commit 27903cd

Please sign in to comment.