Skip to content

Commit

Permalink
timelesslounge#74 Enhancing the DoubleQuotesOnly rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Kuzmic authored and bkuzmic committed Feb 9, 2019
1 parent 21c27c8 commit b1ccc00
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ install: |-
./install_db.sh
merge:
script: |-
chmod +x ./checkstyle.sh
./checkstyle.sh
python checkstyle.py
python check_pylint.py
pytest -vv
pdd -f /dev/null -v
Expand Down
34 changes: 34 additions & 0 deletions checkstyle.py
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()
10 changes: 0 additions & 10 deletions checkstyle.sh

This file was deleted.

3 changes: 0 additions & 3 deletions timeless/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""This file contains all functions needed to create
a new Flask app for timeless
@todo #69:30min Enhance the "DoubleQuotesOnly" rule from checkstyle.sh,
to allow single-quoted strings as long as they are contained within
another double-quoted String.
"""

import os
Expand Down
4 changes: 2 additions & 2 deletions timeless/restaurants/floors/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create():
""" Create new floor """
if request.method == "POST":
flash("Create not yet implemented")
action = 'create'
action = "create"
return render_template(
"restaurants/floors/create_edit.html",
action=action
Expand All @@ -44,7 +44,7 @@ def edit(id):
""" Edit floor with id """
if request.method == "POST":
flash("Edit not yet implemented")
action = 'edit'
action = "edit"
return render_template(
"restaurants/floors/create_edit.html",
action=action
Expand Down

0 comments on commit b1ccc00

Please sign in to comment.