Skip to content

Commit

Permalink
timelesslounge#74 Fixing PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bkuzmic committed Feb 9, 2019
1 parent b1ccc00 commit 7c53b0c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions checkstyle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Scripts to enforce certain code style rules.
Methods to enforce certain code style rules.
"""
import glob
import re
Expand All @@ -8,27 +8,28 @@

def double_qoutes_only():
""" DoubleQuotesOnly; Forbid usage of single-quoted strings """
pattern = "['](?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)"
for filename in glob.iglob("./timeless/**/*.py", recursive=True):
with open(filename, "r+") as f:
# read file as string containing all the lines divided by \n
data = f.read()
pattern = "['](?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)"
prev_line = -1
prev_line = 0
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
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
# count number of \n chars from 0 to start to get line number
current_line = data.count("\n", 0, start) + 1
# find position of single qoute in line
offset = start - data.rfind("\n", 0, start)
if prev_line == current_line:
print(f"Found single-qoutes: {f.name}({current_line},"
f"{prev_offset}-{offset})")
prev_line = current_line
prev_offset = offset
if match_found:
sys.exit(2)

double_qoutes_only()
if __name__ == "__main__":
double_qoutes_only()

0 comments on commit 7c53b0c

Please sign in to comment.