How to use the pylint.reporters.text.TextReporter function in pylint

To help you get started, we’ve selected a few pylint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Devoxin / Lavalink.py / run_tests.py View on Github external
def test_pylint():
    stdout = StringIO()
    reporter = text.TextReporter(stdout)
    opts = ['--max-line-length=150', '--score=no', '--disable=missing-docstring, wildcard-import, '
                                                   'attribute-defined-outside-init, too-few-public-methods, '
                                                   'old-style-class,import-error,invalid-name,no-init,'
                                                   'too-many-instance-attributes,protected-access,too-many-arguments,'
                                                   'too-many-public-methods,logging-format-interpolation,'
                                                   'too-many-branches', 'lavalink']
    pylint.Run(opts, reporter=reporter, do_exit=False)
    out = reporter.out.getvalue()

    msg = 'OK' if not out else out
    print(msg)
github PyCQA / pylint / test / unittest_lint.py View on Github external
def test_lint_ext_module_with_file_output(self):
        self.linter.set_reporter(text.TextReporter())
        if sys.version_info < (3, 0):
            strio = 'StringIO'
        else:
            strio = 'io'
        self.linter.config.files_output = True
        pylint_strio = 'pylint_%s.txt' % strio
        files = [pylint_strio, 'pylint_global.txt']
        for file in files:
            self.addCleanup(remove, file)

        self.linter.check(strio)
        self.linter.generate_reports()
        for f in files:
            self.assertTrue(os.path.exists(f))
github glenpp / py-hole / tests / test_pylint.py View on Github external
import pylint.lint
import pylint.reporters.text


# config required
CODEQUALITY = 7.0
EXCLUDE = [
    'tests/'
]
INCLUDE = [
    'py-hole-bind9RPZ',
]


# see https://github.com/PyCQA/pylint/blob/master/pylint/reporters/text.py
class ErrorsOnlyReporter(pylint.reporters.text.TextReporter):
    """Errors-only Reporter

    If we exclude checks in pylint then we also don't get those in code quality ratings.
    This allows all checks to be run and ignore messages which are not vital.
    """
    def handle_message(self, msg):
        if msg.C not in 'EF':
            return
        # do the usual display things this methoud would normally do
        super().handle_message(msg)


class UnitTestPylint(unittest.TestCase):
    """pylint wrapper for unit tests
    """
    def setUp(self):
github ethz-asl / linter / run_checks.py View on Github external
return self.content

  # Parse each pylint output line individualy and searches
  # for errors in the code.
  pylint_errors = []
  for changed_file in staged_files:
    if re.search(r'\.py$', changed_file):

      print "Running pylint on " + repo_root + "/" + changed_file
      pylint_output = WritableObject()
      pylint_args = ["--rcfile=" + repo_root + "/devtools/pylint.rc",
                     "-rn",
                     repo_root + "/" + changed_file]
      from pylint.reporters.text import TextReporter
      pylint.lint.Run(pylint_args,
                      reporter=TextReporter(pylint_output),
                      exit=False)

      for output_line in pylint_output.read():
        if re.search(r'^(E|C|W):', output_line):
          print changed_file + ": " + output_line
          pylint_errors.append(output_line)

  if len(pylint_errors) > 0:
    print "Pylint found errors. Terminating."
    exit(len(pylint_errors))
github raymondbutcher / perfectpython / pylib / pylint / lint.py View on Github external
from pylint.utils import (PyLintASTWalker, UnknownMessage, MessagesHandlerMixIn,
                          ReportsHandlerMixIn, MSG_TYPES, expand_modules)
from pylint.interfaces import ILinter, IRawChecker, IASTNGChecker
from pylint.checkers import (BaseRawChecker, EmptyReport,
                             table_lines_from_stats)
from pylint.reporters.text import (TextReporter, ParseableTextReporter,
                                   VSTextReporter, ColorizedTextReporter)
from pylint.reporters.html import HTMLReporter
from pylint import config

from pylint.__pkginfo__ import version


OPTION_RGX = re.compile(r'\s*#.*\bpylint:(.*)')
REPORTER_OPT_MAP = {'text': TextReporter,
                    'parseable': ParseableTextReporter,
                    'msvs': VSTextReporter,
                    'colorized': ColorizedTextReporter,
                    'html': HTMLReporter,}


def _get_python_path(filepath):
    dirname = os.path.dirname(os.path.realpath(
            os.path.expanduser(filepath)))
    while True:
        if not os.path.exists(os.path.join(dirname, "__init__.py")):
            return dirname
        old_dirname = dirname
        dirname = os.path.dirname(dirname)
        if old_dirname == dirname:
            return os.getcwd()
github OpenTSDB / tcollector / pylint-runner.py View on Github external
def run_pylint(filename, options):
    "run pylint on the given file"
    ARGS = ["--rcfile=./.pylintrc"]  # put your own here
    if not options.show_all:
        ARGS.append("-E")
    pylint_output = WritableObject()
    from pylint import lint
    from pylint.reporters.text import TextReporter
    lint.Run([filename]+ARGS, reporter=TextReporter(pylint_output), exit=False)
    return pylint_output.read()
github openstack / trove / tools / trove-pylint.py View on Github external
return check()
    elif sys.argv[1] == "rebuild":
        return rebuild()
    elif sys.argv[1] == "initialize":
        return initialize()
    else:
        return usage()

def usage():
    print("Usage: %s [check|rebuild]" % sys.argv[0])
    print("\tUse this tool to perform a lint check of the trove project.")
    print("\t   check: perform the lint check.")
    print("\t   rebuild: rebuild the list of exceptions to ignore.")
    return 0

class ParseableTextReporter(text.TextReporter):
    name = 'parseable'
    line_format = '{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'

    # that's it folks


class LintRunner(object):
    def __init__(self):
        self.config = Config()
        self.idline = re.compile("^[*]* Module .*")
        self.detail = re.compile(r"(\S+):(\d+): \[(\S+)\((\S+)\),"
                                 r" (\S+)?] (.*)")

    def dolint(self, filename):
        exceptions = set()
github gtt116 / vimrc / vim / bundle / python-mode / pylibs / pylint / lint.py View on Github external
ReportsHandlerMixIn.__init__(self)
        BaseRawChecker.__init__(self)
        # provided reports
        self.reports = (('RP0001', 'Messages by category',
                         report_total_messages_stats),
                        ('RP0002', '% errors / warnings by module',
                         report_messages_by_module_stats),
                        ('RP0003', 'Messages',
                         report_messages_stats),
                        ('RP0004', 'Global evaluation',
                         self.report_evaluation),
                        )
        self.register_checker(self)
        self._dynamic_plugins = []
        self.load_provider_defaults()
        self.set_reporter(reporter or TextReporter(sys.stdout))
github openstack / manila / tools / lintstack.py View on Github external
def run_pylint():
    buff = six.StringIO()
    reporter = text.TextReporter(output=buff)
    args = [
        "--msg-template='{path}:{line}: [{msg_id}i({symbol}), {obj}] {msg}'",
        "-E", "manila"]
    lint.Run(args, reporter=reporter, exit=False)
    val = buff.getvalue()
    buff.close()
    return val
github openstack / python-cinderclient / tools / lintstack.py View on Github external
def run_pylint():
    buff = StringIO()
    reporter = text.TextReporter(output=buff)
    args = [
        "--msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'",
        "-E", "cinderclient"]
    lint.Run(args, reporter=reporter, exit=False)
    val = buff.getvalue()
    buff.close()
    return val