Avoid E231 if comma is at end-of-line (#6747)

## Summary

I don't know how this could come up in valid Python, but anyway...

Closes https://github.com/astral-sh/ruff/issues/6738.
This commit is contained in:
Charlie Marsh 2023-08-21 20:47:20 -04:00 committed by GitHub
parent 37f4920e1e
commit abc5065fc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -28,3 +28,6 @@ mdtypes_template = {
'tag_full': [('mdtype', 'u4'), ('byte_count', 'u4')], 'tag_full': [('mdtype', 'u4'), ('byte_count', 'u4')],
'tag_smalldata':[('byte_count_mdtype', 'u4'), ('data', 'S4')], 'tag_smalldata':[('byte_count_mdtype', 'u4'), ('data', 'S4')],
} }
#: Okay
a = (1,

View file

@ -81,10 +81,10 @@ pub(crate) fn missing_whitespace(
TokenKind::Comma | TokenKind::Semi | TokenKind::Colon => { TokenKind::Comma | TokenKind::Semi | TokenKind::Colon => {
let after = line.text_after(token); let after = line.text_after(token);
if !after if after
.chars() .chars()
.next() .next()
.is_some_and(|c| char::is_whitespace(c) || c == '\\') .is_some_and(|c| !(char::is_whitespace(c) || c == '\\'))
{ {
if let Some(next_token) = iter.peek() { if let Some(next_token) = iter.peek() {
match (kind, next_token.kind()) { match (kind, next_token.kind()) {

View file

@ -98,5 +98,7 @@ E23.py:29:20: E231 [*] Missing whitespace after ':'
29 |- 'tag_smalldata':[('byte_count_mdtype', 'u4'), ('data', 'S4')], 29 |- 'tag_smalldata':[('byte_count_mdtype', 'u4'), ('data', 'S4')],
29 |+ 'tag_smalldata': [('byte_count_mdtype', 'u4'), ('data', 'S4')], 29 |+ 'tag_smalldata': [('byte_count_mdtype', 'u4'), ('data', 'S4')],
30 30 | } 30 30 | }
31 31 |
32 32 | #: Okay