Download:
child 43:2e6ba4861557
parent 41:8d6436a284d2
42:06c224e8b052
Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 14:07:11 +0800
incoming: skip checking the whole line when it's linter output When a line starts with a certain pattern, it's recognized as linter output, but determining if it's an error or a warning was done looking at the whole string again multiple times. Let's save on regexes and look only on the important part.

1 файлов изменено, 26 вставок(+), 27 удалений(-) [+]
incoming.py file | annotate | diff | comparison | revisions
--- a/incoming.py Sun Jun 19 00:18:30 2016 +0800
+++ b/incoming.py Sun Jun 19 14:07:11 2016 +0800
@@ -44,34 +44,33 @@
cls = None
if state == 'checks':
- """
- m = re.match(r'^(.+):\d+:\d+: ')
+ m = re.match(r'^(.+):(\d+):\d+: ', line)
if m is not None:
- filename = m.group(1)
- """
- # pep8-specific E9xx
- # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
- if re.match(r'^.+:\d+:\d+: E9\d{2}', line) is not None:
- errors += 1
- cls = 'error'
- elif re.match(r'^.+:\d+:\d+: [EWFCN]\d{3}', line) is not None:
- warnings += 1
- cls = 'warning'
- elif re.match(r'^.+:\d+:\d+: \[error\]', line) is not None:
- errors += 1
- cls = 'error'
- elif re.match(r'^.+:\d+:\d+: \[warning\]', line) is not None:
- warnings += 1
- cls = 'warning'
- elif re.match(r'^.+:\d+:\d+: \(E\d{3}\)', line) is not None:
- errors += 1
- cls = 'error'
- elif re.match(r'^.+:\d+:\d+: \(W\d{3}\)', line) is not None:
- warnings += 1
- cls = 'warning'
- elif re.match(r'^.+:\d+:\d+: ', line) is not None:
- warnings += 1
- cls = 'warning'
+ rest = line[m.end():]
+
+ # pep8-specific E9xx
+ # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
+ if re.match(r'^E9\d{2}', rest) is not None:
+ errors += 1
+ cls = 'error'
+ elif re.match(r'^[EWFCN]\d{3}', rest) is not None:
+ warnings += 1
+ cls = 'warning'
+ elif re.match(r'^\[error\]', rest) is not None:
+ errors += 1
+ cls = 'error'
+ elif re.match(r'^\[warning\]', rest) is not None:
+ warnings += 1
+ cls = 'warning'
+ elif re.match(r'^\(E\d{3}\)', rest) is not None:
+ errors += 1
+ cls = 'error'
+ elif re.match(r'^\(W\d{3}\)', rest) is not None:
+ warnings += 1
+ cls = 'warning'
+ else:
+ warnings += 1
+ cls = 'warning'
if line.startswith(meta_prefix):
cls = 'meta'