Skip to content

Commit

Permalink
Merge pull request #4 from cs50/develop
Browse files Browse the repository at this point in the history
Fix ending newline bug
  • Loading branch information
cmlsharp authored Aug 11, 2017
2 parents d032a72 + 4fc0e04 commit 472b714
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"console_scripts": ["style50=style50.__main__:main"],
},
url="https://github.com/cs50/style50",
version="2.1.0"
version="2.1.1"
)
16 changes: 14 additions & 2 deletions style50/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,28 @@ def _check(self, file):
_, extension = os.path.splitext(file)
try:
check = self.extension_map[extension[1:]]

with open(file) as f:
code = f.read()

except (OSError, IOError) as e:
if e.errno == errno.ENOENT:
raise Error("file \"{}\" not found".format(file))
else:
raise
except KeyError:
except (KeyError, IndexError):
raise Error("unknown file type \"{}\", skipping...".format(file))

# Ensure file ends in a trailing newline for consistency
try:
if code[-1] != "\n":
code += "\n"
except IndexError:
raise Error("file is empty")
else:
return check(code)


@staticmethod
def split_diff(old, new):
"""
Expand All @@ -205,7 +215,7 @@ def html_diff(self, old, new):
"""
def fmt_html(content, dtype):
content = cgi.escape(content, quote=True)
return content if dtype == " " else "<{1}><{0}></{1}>".format(content, "ins" if dtype == "+" else "del")
return content if dtype == " " else "<{1}>{0}</{1}>".format(content, "ins" if dtype == "+" else "del")

return self._char_diff(old, new, fmt_html)

Expand All @@ -215,6 +225,7 @@ def char_diff(self, old, new):
"""
def fmt_color(content, dtype):
return termcolor.colored(content, None, "on_green" if dtype == "+" else "on_red" if dtype == "-" else None)

return self._char_diff(old, new, fmt_color)

@staticmethod
Expand Down Expand Up @@ -273,6 +284,7 @@ class StyleCheck(object):

def __init__(self, code):
self.original = code

comments = self.count_comments(code)

try:
Expand Down

0 comments on commit 472b714

Please sign in to comment.