Skip to content

Conversation

@cdce8p
Copy link
Member

@cdce8p cdce8p commented Oct 13, 2021

Second attempt after #990

I've improved the default MATCH_CASE_REGEX, especially the lookahead part.

- (?=.*\:)
+ (?=.*\S.*\:(?=\s*$|\s*#))

It now requires at least one non-whitespace char to be present between case and :. Furthermore it matches end of line or begin of comment.

To account for case statements written inline, I've added fallback logic. That uses the tokenizer to check the : isn't inside any brackets.

match 0:
    case _: print('hi')
    case {"x": 42}: pass
    case "Hello: World": pass

Comment on lines +510 to +494
match = MATCH_CASE_REGEX.match(logical_line)
if match:
if match[1] == ' ':
return
if match[1] == '':
yield match.start(1), "E275 missing whitespace after keyword"
elif '\t' in match[1]:
yield match.start(1), "E273 tab after keyword"
else:
yield match.start(1), "E271 multiple spaces after keyword"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very match.

@cdce8p
Copy link
Member Author

cdce8p commented Aug 15, 2023

Closing this as there doesn't seem to be interest to implement it. Please feel free to reuse the code as you see fit.

@cdce8p cdce8p closed this Aug 15, 2023
@cdce8p cdce8p deleted the whitespace-match-case-2 branch August 15, 2023 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants