-
Notifications
You must be signed in to change notification settings - Fork 160
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
Support for json formatter and other test report formats #167
Comments
Thanks for the suggestion! I'm not opposed to adding JSON output, but I'd like to do it only if there are some projects that would actually benefit from this feature. Let's use this issue as a forum where people can discuss which report formats would be beneficial for them. Then we can make an informed decision about which formats to support and how to obtain them. |
I will wait for #161 to complete and use something flake8-json for getting the required json. |
I actually went ahead and tried writing a patch for it. It's actually non-trivial and looks like this: diff --git a/vulture/core.py b/vulture/core.py
index 86b1f4d..b647c89 100644
--- a/vulture/core.py
+++ b/vulture/core.py
@@ -28,6 +28,7 @@ from __future__ import print_function
import argparse
import ast
from fnmatch import fnmatch, fnmatchcase
+import json
import os.path
import pkgutil
import re
@@ -127,6 +128,19 @@ class Item(object):
utils.format_path(self.filename), self.first_lineno,
self.message, self.confidence, size_report)
+ def get_dict(self, add_size=False):
+ item = {
+ 'name': self.name,
+ 'typ': self.typ,
+ 'filename': self.filename,
+ 'first_lineno': self.first_lineno,
+ 'last_lineno': self.last_lineno,
+ 'confidence': self.confidence
+ }
+ if add_size:
+ item['size = self.size']
+ return item
+
def get_whitelist_string(self):
filename = utils.format_path(self.filename)
if self.typ == 'unreachable_code':
@@ -281,6 +295,15 @@ class Vulture(ast.NodeVisitor):
self.found_dead_code_or_error = True
return self.found_dead_code_or_error
+ def json_report(self, min_confidence=0, sort_by_size=False):
+ """
+ Return the results in a JSON format.
+ """
+ results = [
+ item.get_dict(sort_by_size) for item in self.get_unused_code(
+ min_confidence=min_confidence, sort_by_size=sort_by_size)]
+ return json.dumps(results)
+
@property
def unused_classes(self): But, it would be a lot of hassle to test and maintain this code, so I'd still recommend waiting for the flake8 plugin. |
Demand for this feature has shown to be low, so I'm closing this ticket. |
Currently vulture lags a json output and many other test report formats like TAP, JUnit, CheckstyleXML etc. I am happy to provide vulture with a json format and other test report formats will simply follow using coala-json.
coala-json is a python package developed by coala which coverts a json output into various test result formats. These test formats when linked with CIs can automatically produce various artifacts and test reports.
For more information you can visit: https://coala-json.readthedocs.io/en/latest/
Repository link: https://gitlab.com/coala/coala-json
The text was updated successfully, but these errors were encountered: