Last active
August 29, 2015 14:17
-
-
Save boris-42/d3ad63e517e1ef8cec77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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