forked from timelesslounge/timelessis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timelesslounge#74 Enhancing the DoubleQuotesOnly rules
- Loading branch information
Showing
5 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Scripts to enforce certain code style rules. | ||
""" | ||
import glob | ||
import re | ||
import sys | ||
|
||
|
||
def double_qoutes_only(): | ||
""" DoubleQuotesOnly; Forbid usage of single-quoted strings """ | ||
for filename in glob.iglob("./timeless/**/*.py", recursive=True): | ||
with open(filename, "r+") as f: | ||
data = f.read() | ||
pattern = "['](?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)" | ||
prev_line = -1 | ||
prev_offset = 0 | ||
match_found = False | ||
for m in re.finditer(pattern, data): | ||
if not match_found: | ||
print("Single-quotes are forbidden in .py files!") | ||
match_found = True | ||
start = m.start() | ||
lineno = data.count('\n', 0, start) + 1 | ||
offset = start - data.rfind('\n', 0, start) | ||
word = m.group(0) | ||
if prev_line == lineno: | ||
print("%s(%s,%s-%s): %s" % | ||
(f.name, lineno, prev_offset, offset, word)) | ||
prev_line = lineno | ||
prev_offset = offset | ||
if match_found: | ||
sys.exit(2) | ||
|
||
double_qoutes_only() |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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