Skip to content

Commit

Permalink
Merge pull request #166 from lfrodrigues/master
Browse files Browse the repository at this point in the history
Added vscode formater and updated docs.
  • Loading branch information
carlio committed May 29, 2016
2 parents f016717 + 81cf89f commit b822989
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The default output format of ``prospector`` is designed to be human readable. Yo
+=============+============================================================================+
| ``emacs`` | | Support for emacs compilation output mode, see `issue_16`_. |
+-------------+----------------------------------------------------------------------------+
| ``vscode`` | | Support for vscode python plugin |
+-------------+----------------------------------------------------------------------------+
| ``grouped`` | | Similar to ``text``, but groups all message on the same line together |
| | | rather than having a separate entry per message. |
+-------------+----------------------------------------------------------------------------+
Expand All @@ -43,6 +45,8 @@ The default output format of ``prospector`` is designed to be human readable. Yo
+-------------+----------------------------------------------------------------------------+
| ``yaml`` | | Same as JSON except produces YAML output. |
+-------------+----------------------------------------------------------------------------+
| ``xunit`` | | Same as JSON except produces xunit compatile XML output. |
+-------------+----------------------------------------------------------------------------+
| ``text`` | | The default output format, a simple human readable format. |
+-------------+----------------------------------------------------------------------------+

Expand Down
3 changes: 2 additions & 1 deletion prospector/formatters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from prospector.formatters import json, text, grouped, emacs, yaml, pylint, xunit
from prospector.formatters import json, text, grouped, emacs, yaml, pylint, xunit, vscode


__all__ = (
Expand All @@ -14,4 +14,5 @@
'yaml': yaml.YamlFormatter,
'pylint': pylint.PylintFormatter,
'xunit': xunit.XunitFormatter,
'vscode': vscode.VSCodeFormatter,
}
36 changes: 36 additions & 0 deletions prospector/formatters/vscode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import re
from prospector.formatters.base import Formatter


class VSCodeFormatter(Formatter):

"""
This formatter outputs messages in the same way as vscode prospector linter expects.
"""

def render(self, summary=True, messages=True, profile=False):
# this formatter will always ignore the summary and profile
cur_loc = None
output = []

for message in sorted(self.messages):

if cur_loc != message.location.path:
cur_loc = message.location.path
module_name = message.location.path.replace(os.path.sep, '.')
module_name = re.sub(r'(\.__init__)?\.py$', '', module_name)

header = '************* Module %s' % module_name
output.append(header)

template = '%(line)s,%(character)s,%(code)s,%(code)s:%(source)s %(message)s'
output.append(template % {
'line': message.location.line,
'character': message.location.character,
'source': message.source,
'code': message.code,
'message': message.message.strip()
})

return '\n'.join(output)

0 comments on commit b822989

Please sign in to comment.