--- a/incoming.py Sun Oct 08 10:01:43 2017 +0800
+++ b/incoming.py Sun Oct 08 10:33:32 2017 +0800
# 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'),
- (r'^\[error\] .* \(\S+\)$', 'error'),
- (r'^\[warning\] .* \(\S+\)$', 'warning'),
+ (r'^\[error\] .* \((\S+)\)$', 'error'),
+ (r'^\[warning\] .* \((\S+)\)$', 'warning'),
- (r'^\(E\d{3}\)', 'error'),
- (r'^\(W\d{3}\)', 'warning'),
+ (r'^\((E\d{3})\)', 'error'),
+ (r'^\((W\d{3})\)', 'warning'),
- (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.lastindex is not None:
+ item['code'] = m.group(m.lastindex)
--- 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
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'}
errors, warnings, extra = mlo('hello.py:42:1: W123 clowntown ahoy')
- 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
errors, warnings, extra = mlo('s p a c e.yml:07:01: [error] oops! (uh-oh)')
- 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
errors, warnings, extra = mlo('ham.lua:414:90: (E101) ham is stale')
- 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
errors, warnings, extra = mlo('backwards.js:9091:1: not perfect (W201)')
- 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
errors, warnings, extra = mlo('requirements.txt:5:1: PIL is obsolete.')
- 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