Skip to content

Commit

Permalink
modified function for no space around math operators
Browse files Browse the repository at this point in the history
changed regex so that a minus symbol before a number is not flagged (as in x = -1). This is very common when using negatives and shouldn't be a bad practice
  • Loading branch information
luisesanmartin committed Mar 9, 2023
1 parent 14b5391 commit 6a953f3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/stata_linter_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ def no_space_before_symbol(line):

line = line.split('///')[0]
groups = line.split('"')
pattern = r"(?:[a-z]|[A-Z]|[0-9]|_|\)|')(?:<|>|=|\+|-|\*|\^)"

for i, group in enumerate(groups):

if i % 2 == 0:
if re.search(r"(?:[a-z]|[A-Z]|[0-9]|_|\)|')(?:<|>|=|\+|-|\*|\^)", group):
if re.search(pattern, group):
return True

return False
Expand All @@ -260,11 +261,12 @@ def no_space_after_symbol(line):

line = line.split('///')[0]
groups = line.split('"')
pattern = r"(?:(?:<|>|=|\+|-|\*|\^)(?:[a-z]|[A-Z]|_|\(|`|\.|$))|(?:(?:<|>|=|\+|\*|\^)(?:[0-9]))"

for i, group in enumerate(groups):

if i % 2 == 0:
if re.search(r"(?:<|>|=|\+|-|\*|\^)(?:[a-z]|[A-Z]|[0-9]|_|\(|`|\.|$)", group):
if re.search(pattern, group):
return True

return False
Expand Down

0 comments on commit 6a953f3

Please sign in to comment.