Skip to content

Instantly share code, notes, and snippets.

@boris-42
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save boris-42/d3ad63e517e1ef8cec77 to your computer and use it in GitHub Desktop.

Select an option

Save boris-42/d3ad63e517e1ef8cec77 to your computer and use it in GitHub Desktop.
def check_quotes(logical_line):
"""Raise lint error when using ' instead of " """
# if there is no double quote sign there's nothing to do
if not logical_line or logical_line.strip().startswith("#"):
return
in_string = False
single_quotas_are_used = False
i = 0
while i < len(logical_line):
char = logical_line[i]
if in_string:
if char == "\"":
in_string = False
if char == "\\":
i += 1 # ignore next char
elif char == "#":
break
elif char == "'":
single_quotas_are_used = True
break
i += 1
if single_quotas_are_used:
yield (i, "Q000 Remove Single quotes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment