Skip to content

Commit

Permalink
Fixes addition of new line at end of the file
Browse files Browse the repository at this point in the history
Previously a new line was appened at the end of the last line of the file even,
made it so that coala checks first if a new line is present
at the end of the file before appending the last line

Closes coala#6083
  • Loading branch information
PrasanthChettri committed Jun 4, 2021
1 parent 52b9d18 commit 5777a40
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions coalib/io/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ def lines(self):
"""
lines = self.string.splitlines()
if self._newline:
return tuple(line + '\n'
for line in lines)
line_list = []
for line in lines[:-1]:
line_list.append(line + '\n')

newline_end = self.string[-1] == '\n'
line_list.append(lines[-1]
+ '\n' if newline_end else '')

return tuple(line_list)

else:
return tuple(lines)

Expand Down

0 comments on commit 5777a40

Please sign in to comment.