Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit 92bb75b

Browse files
committed
Fix ResourceWarning on unclosed file.
1 parent 30c8b03 commit 92bb75b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

cpplint_junit.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ def parse_cpplint(file_name):
4141
Raises:
4242
FileNotFoundError: File does not exist.
4343
"""
44-
lines = open(file_name, mode='rt').readlines()
45-
46-
errors = collections.defaultdict(list)
47-
for line in lines:
48-
line = line.rstrip()
49-
50-
match = re.search(r'(\S+):(\d+):\s+(.+)', line)
51-
if match is not None:
52-
error = CpplintError(file=match.group(1),
53-
line=int(match.group(2)),
54-
message=match.group(3))
55-
errors[error.file].append(error)
56-
return errors
44+
with open(file_name, 'rt') as file:
45+
lines = file.readlines()
46+
47+
errors = collections.defaultdict(list)
48+
for line in lines:
49+
line = line.rstrip()
50+
51+
match = re.search(r'(\S+):(\d+):\s+(.+)', line)
52+
if match is not None:
53+
error = CpplintError(file=match.group(1),
54+
line=int(match.group(2)),
55+
message=match.group(3))
56+
errors[error.file].append(error)
57+
return errors
5758

5859

5960
def generate_test_suite(errors, output_file):

0 commit comments

Comments
 (0)