Bug 1303646 - Escape backslashes when processing flake8 output. r=ahal
authorBryce Van Dyk <bvandyk@mozilla.com>
Tue, 20 Sep 2016 08:41:09 +1200
changeset 314421 3edde45c1ee780de06b5bde61cfebf39e7a45ace
parent 314420 ee364270d3e60a036a5767bae738e9ee6cae5e81
child 314422 150e2a3f3b1e3320eee926ae33f548689de7fa07
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1303646
milestone51.0a1
Bug 1303646 - Escape backslashes when processing flake8 output. r=ahal During process_line each line is loaded into JSON. As it stands it is possible to attempt loads on lines containing single backslashes. This will fail the load as these characters are invalid in JSON. This is particularly noticeable on Windows, where all paths will contain these characters. This changeset escapes any back slashes in the lines. It also adds logging to the error case for the JSON loading, so failures aren't silently swallowed. *** Fix issues brought up in review, silly mistakes in last changeset. - Update log message upon encountering non JSON linter output that cannot be handled by json.loads. - Correct typo: formate -> format. - Correct replace string. Was using r'\\\\', which will evaluate to 3 slashes, now using '\\\\', which evaluates to 2. Opting not to use a raw string here because of the confusion over the final backslash interaction (final one still needs to be escaped even in a raw string). MozReview-Commit-ID: Hfa0jSdnege
tools/lint/flake8.lint
--- a/tools/lint/flake8.lint
+++ b/tools/lint/flake8.lint
@@ -45,19 +45,22 @@ The offset is of the form (lineno_offset
 to the lineoffset property of `ResultContainer`.
 """
 
 EXTENSIONS = ['.py', '.lint']
 results = []
 
 
 def process_line(line):
+    # Escape slashes otherwise JSON conversion will not work
+    line = line.replace('\\', '\\\\')
     try:
         res = json.loads(line)
     except ValueError:
+        print('Non JSON output from linter, will not be processed: {}'.format(line))
         return
 
     if 'code' in res:
         if res['code'].startswith('W'):
             res['level'] = 'warning'
 
         if res['code'] in LINE_OFFSETS:
             res['lineoffset'] = LINE_OFFSETS[res['code']]