Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtains desired result output #4

merged 1 commit into from May 18, 2019
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

Obtains desired result output

  • Loading branch information...
RohanVB committed May 18, 2019
commit 04f288ebe7e94aa9d06208d92a84f77730bc2e08
@@ -8,10 +8,12 @@
import os
import io
from contextlib import redirect_stdout

import json
from coalib import coala
import pickle

class use_coala(object):
class UseCoala(object):

def log(*args, **kwargs):
return print(*args, file=sys.stderr, **kwargs), sys.stderr.flush()
@@ -27,12 +29,56 @@ def specific_file(working_dir, file):
output = None
if retval == 1:
output = f.getvalue()
if output:
use_coala.log('Output =', output)
use_coala.log('No results for the file')
elif retval == 0:
use_coala.log('No issues found')
use_coala.log('Exited with:', retval)
return output

def output_to_diagnostics():
Turn output to diagnostics.
output = UseCoala.specific_file(None, '')
if output is None:
return None
output_json = json.loads(output)['results']
res = []
for key, problems in output_json.items():
# section = key
for problem in problems:
message = problem['message']
origin = problem['origin']
real_message = '[{}: {}]'.format(origin, message)
for code in problem['affected_code']:
filename = code['start']['file']

def convert_offset(x):
return x - 1 if x else x

start_line = convert_offset(code['start']['line'])
start_char = convert_offset(code['start']['column'])
end_line = convert_offset(code['end']['line'])
end_char = convert_offset(code['end']['column'])

if start_char is None or end_char is None:
start_char = 0
end_line = start_line + 1
end_char = 0

'file_name': filename,
'range': {
'start': {
'line': start_line,
'character': start_char
'end': {
'line': end_line,
'character': end_char
'message': real_message # contains origin and message
return res

# with open('/Users/rohan/.spyder-py3-dev/coala.results', 'wb') as fp:
# pickle.dump(UseCoala.output_to_diagnostics(), fp)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.