Download:
child 317:fce877c8a1cc
parent 315:b3c5f2cf42fb
316:c8c41a411b36
Anton Shestakov <av6@dwimlabs.net>, Sun, 08 Oct 2017 10:33:32 +0800
incoming: extract error/warning codes for stats

2 файлов изменено, 20 вставок(+), 14 удалений(-) [+]
incoming.py file | annotate | diff | comparison | revisions
tests/test_incoming.py file | annotate | diff | comparison | revisions
--- a/incoming.py Sun Oct 08 10:01:43 2017 +0800
+++ b/incoming.py Sun Oct 08 10:33:32 2017 +0800
@@ -44,26 +44,28 @@
patterns = (
# pep8-specific E9xx
# https://pep8.readthedocs.io/en/latest/intro.html#error-codes
- (r'^E9\d{2}', 'error'),
- (r'^[EWFCN]\d{3}', 'warning'),
+ (r'^(E9\d{2})', 'error'),
+ (r'^([EWFCN]\d{3})', 'warning'),
# yamllint
- (r'^\[error\] .* \(\S+\)$', 'error'),
- (r'^\[warning\] .* \(\S+\)$', 'warning'),
+ (r'^\[error\] .* \((\S+)\)$', 'error'),
+ (r'^\[warning\] .* \((\S+)\)$', 'warning'),
# luacheck
- (r'^\(E\d{3}\)', 'error'),
- (r'^\(W\d{3}\)', 'warning'),
+ (r'^\((E\d{3})\)', 'error'),
+ (r'^\((W\d{3})\)', 'warning'),
# jshint
- (r'.* \(E\d{3}\)$', 'error'),
- (r'.* \(W\d{3}\)$', 'warning'),
+ (r'.* \((E\d{3})\)$', 'error'),
+ (r'.* \((W\d{3})\)$', 'warning'),
)
for regex, cls in patterns:
m = re.match(regex, rest)
if m is not None:
item['cls'] = cls
+ if m.lastindex is not None:
+ item['code'] = m.group(m.lastindex)
if cls == 'error':
errors += 1
elif cls == 'warning':
--- a/tests/test_incoming.py Sun Oct 08 10:01:43 2017 +0800
+++ b/tests/test_incoming.py Sun Oct 08 10:33:32 2017 +0800
@@ -3,14 +3,15 @@
def test_match_linter_output():
mlo = match_linter_output
- usual_keys = ['cls', 'filename', 'line_number', 'link_end', 'link_start']
+ usual_keys = {'cls', 'filename', 'line_number', 'link_end', 'link_start'}
# flake8
errors, warnings, extra = mlo('hello.py:42:1: W123 clowntown ahoy')
assert errors == 0
assert warnings == 1
- assert sorted(extra.keys()) == usual_keys
+ assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'warning'
+ assert extra['code'] == 'W123'
assert extra['filename'] == 'hello.py'
assert extra['line_number'] == 42
assert extra['link_start'] == 0
@@ -20,8 +21,9 @@
errors, warnings, extra = mlo('s p a c e.yml:07:01: [error] oops! (uh-oh)')
assert errors == 1
assert warnings == 0
- assert sorted(extra.keys()) == usual_keys
+ assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'error'
+ assert extra['code'] == 'uh-oh'
assert extra['filename'] == 's p a c e.yml'
assert extra['line_number'] == 7
assert extra['link_start'] == 0
@@ -31,8 +33,9 @@
errors, warnings, extra = mlo('ham.lua:414:90: (E101) ham is stale')
assert errors == 1
assert warnings == 0
- assert sorted(extra.keys()) == usual_keys
+ assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'error'
+ assert extra['code'] == 'E101'
assert extra['filename'] == 'ham.lua'
assert extra['line_number'] == 414
assert extra['link_start'] == 0
@@ -42,8 +45,9 @@
errors, warnings, extra = mlo('backwards.js:9091:1: not perfect (W201)')
assert errors == 0
assert warnings == 1
- assert sorted(extra.keys()) == usual_keys
+ assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'warning'
+ assert extra['code'] == 'W201'
assert extra['filename'] == 'backwards.js'
assert extra['line_number'] == 9091
assert extra['link_start'] == 0
@@ -53,7 +57,7 @@
errors, warnings, extra = mlo('requirements.txt:5:1: PIL is obsolete.')
assert errors == 0
assert warnings == 1
- assert sorted(extra.keys()) == usual_keys
+ assert set(extra) == usual_keys
assert extra['cls'] == 'warning'
assert extra['filename'] == 'requirements.txt'
assert extra['line_number'] == 5