Skip to content

Commit

Permalink
try bypass visual indent check
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande committed May 16, 2024
1 parent 0642d07 commit 50ba417
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def f():

# OK
def f():
# comment
x = ((
(
)
Expand Down Expand Up @@ -184,7 +185,7 @@ def target(
WHERE type = 'local'
"""

# # Ok
# OK
[21,
21,
21]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ruff_python_index::Indexer;
use ruff_python_parser::TokenKind;
use ruff_source_file::Locator;
use ruff_text_size::{Ranged, TextRange, TextSize};
use rustc_hash::FxHashMap;

/// ## What it does
/// Checks for continuation lines without enough indentation.
Expand Down Expand Up @@ -48,16 +47,6 @@ struct TokenInfo {
token_end_within_physical_line: i64,
}

#[derive(Debug, Clone)]
enum IndentFlag {
/// The pycodestyle's True
Standard,
/// The pycodestyle's text (str instance)
Token(TokenKind),
/// The pycodestyle's str class
StringOrComment,
}

/// Compute the `TokenInfo` of each token.
fn get_token_infos<'a>(
logical_line: &LogicalLine,
Expand Down Expand Up @@ -253,9 +242,7 @@ pub(crate) fn continuation_lines(
let mut hang: i64 = 0;
let mut hanging_indent: bool = false;
// Visual indents
let mut indent_chances: FxHashMap<i64, IndentFlag> = FxHashMap::default();
let mut last_indent = start_indent_level;
let mut visual_indent;
let mut last_token_multiline = false;
// For each depth, record the visual indent column.
let mut indent = Vec::with_capacity(max_depth + 1);
Expand Down Expand Up @@ -298,42 +285,17 @@ pub(crate) fn continuation_lines(
hanging_indent = hang == depth_hang;
}

// Is there any chance of visual indent ?
visual_indent = if !is_closing_bracket && hang > 0 {
indent_chances
.get(&token_info.token_start_within_physical_line)
.cloned()
} else {
None
};

if (is_closing_bracket && (indent[depth] != 0 || hang == 0))
|| (indent[depth] != 0
&& token_info.token_start_within_physical_line < indent[depth])
{
} else if hanging_indent || (indent_next && rel_indent[row] == (2 * indent_size)) {
hangs[depth] = Some(hang);
} else {
match visual_indent {
Some(IndentFlag::Standard) => {
// Visual indent is verified.
indent[depth] = token_info.token_start_within_physical_line;
}
Some(IndentFlag::StringOrComment) => {
// Ignore token lined up with matching one from a previous line.
}
Some(IndentFlag::Token(t)) if t == token.kind => {
// Ignore token lined up with matching one from a previous line.
}
_ => {
// Indent is broken.
if hang <= 0 {
// E122.
let diagnostic =
Diagnostic::new(MissingOrOutdentedIndentation, token.range);
context.push_diagnostic(diagnostic);
}
}
if hang <= 0 {
// E122.
let diagnostic = Diagnostic::new(MissingOrOutdentedIndentation, token.range);
context.push_diagnostic(diagnostic);
}
}
}
Expand All @@ -347,36 +309,9 @@ pub(crate) fn continuation_lines(
&& indent[depth] == 0
{
indent[depth] = token_info.token_start_within_physical_line;
indent_chances.insert(
token_info.token_start_within_physical_line,
IndentFlag::Standard,
);
}
// Deal with implicit string concatenation.
else if matches!(token.kind, TokenKind::Comment | TokenKind::String) {
indent_chances.insert(
token_info.token_start_within_physical_line,
IndentFlag::StringOrComment,
);
}
// Visual indent after assert/raise/with.
else if (row == 0
&& depth == 0
&& matches!(
token.kind,
TokenKind::Assert | TokenKind::Raise | TokenKind::With
))
// Special case for the "if" statement because "if (".len() == 4
|| (indent_chances.is_empty()
&& row == 0
&& depth == 0
&& matches!(token.kind, TokenKind::If))
{
indent_chances.insert(
token_info.token_end_within_physical_line + 1,
IndentFlag::Standard,
);
} else if matches!(token.kind, TokenKind::Colon)

if matches!(token.kind, TokenKind::Colon)
&& locator.full_lines(token.range)[usize::try_from(
token_info.token_end_within_physical_line,
)
Expand Down Expand Up @@ -420,17 +355,10 @@ pub(crate) fn continuation_lines(
*ind = 0;
}
}
indent_chances.retain(|&ind, _| ind < prev_indent);
open_rows.truncate(depth);
depth -= 1;
if depth > 0 {
indent_chances.insert(indent[depth], IndentFlag::Standard);
}
brackets_opened = brackets_opened.saturating_sub(1);
}
indent_chances
.entry(token_info.token_start_within_physical_line)
.or_insert(IndentFlag::Token(token.kind));
}

last_token_multiline =
Expand Down

0 comments on commit 50ba417

Please sign in to comment.