Python pylint.lint.PyLinter() Examples

The following are 20 code examples of pylint.lint.PyLinter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pylint.lint , or try the search function .
Example #1
Source File: test_functional.py    From shopify_python with MIT License 6 votes vote down vote up
def __init__(self, test_file):
        test_reporter = FunctionalTestReporter()
        self._linter = lint.PyLinter()

        google_styleguide.register_checkers(self._linter)
        shopify_styleguide.register_checkers(self._linter)

        self._linter.set_reporter(test_reporter)
        self._linter.config.persistent = 0
        checkers.initialize(self._linter)
        self._linter.disable('I')
        try:
            self._linter.read_config_file(test_file.option_file)
            self._linter.load_config_file()
        except NoFileError:
            pass
        self._test_file = test_file 
Example #2
Source File: conftest.py    From python-netsurv with MIT License 6 votes vote down vote up
def linter(checker, register, enable, disable, reporter):
    _linter = PyLinter()
    _linter.set_reporter(reporter())
    checkers.initialize(_linter)
    if register:
        register(_linter)
    if checker:
        _linter.register_checker(checker(_linter))
    if disable:
        for msg in disable:
            _linter.disable(msg)
    if enable:
        for msg in enable:
            _linter.enable(msg)
    os.environ.pop("PYLINTRC", None)
    return _linter 
Example #3
Source File: unittest_reporting.py    From python-netsurv with MIT License 6 votes vote down vote up
def test_parseable_output_regression():
    output = StringIO()
    with warnings.catch_warnings(record=True):
        linter = PyLinter(reporter=ParseableTextReporter())

    checkers.initialize(linter)
    linter.config.persistent = 0
    linter.reporter.set_output(output)
    linter.set_option("output-format", "parseable")
    linter.open()
    linter.set_current_module("0123")
    linter.add_message("line-too-long", line=1, args=(1, 2))
    assert (
        output.getvalue() == "************* Module 0123\n"
        "0123:1: [C0301(line-too-long), ] "
        "Line too long (1/2)\n"
    ) 
Example #4
Source File: conftest.py    From python-netsurv with MIT License 6 votes vote down vote up
def linter(checker, register, enable, disable, reporter):
    _linter = PyLinter()
    _linter.set_reporter(reporter())
    checkers.initialize(_linter)
    if register:
        register(_linter)
    if checker:
        _linter.register_checker(checker(_linter))
    if disable:
        for msg in disable:
            _linter.disable(msg)
    if enable:
        for msg in enable:
            _linter.enable(msg)
    os.environ.pop("PYLINTRC", None)
    return _linter 
Example #5
Source File: do_not_use_asserts.py    From airflow with Apache License 2.0 5 votes vote down vote up
def register(linter: PyLinter):
    linter.register_checker(DoNotUseAssertsChecker(linter)) 
Example #6
Source File: __init__.py    From shopify_python with MIT License 5 votes vote down vote up
def register(linter):  # type: (lint.PyLinter) -> None
    google_styleguide.register_checkers(linter)
    shopify_styleguide.register_checkers(linter) 
Example #7
Source File: unittest_reporters_json.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_simple_json_output():
    output = StringIO()

    reporter = JSONReporter()
    linter = PyLinter(reporter=reporter)
    checkers.initialize(linter)

    linter.config.persistent = 0
    linter.reporter.set_output(output)
    linter.open()
    linter.set_current_module("0123")
    linter.add_message("line-too-long", line=1, args=(1, 2))

    # we call this method because we didn't actually run the checkers
    reporter.display_messages(None)

    expected_result = [
        [
            ("column", 0),
            ("line", 1),
            ("message", "Line too long (1/2)"),
            ("message-id", "C0301"),
            ("module", "0123"),
            ("obj", ""),
            ("path", "0123"),
            ("symbol", "line-too-long"),
            ("type", "convention"),
        ]
    ]
    report_result = json.loads(output.getvalue())
    report_result = [sorted(report_result[0].items(), key=lambda item: item[0])]
    assert report_result == expected_result 
Example #8
Source File: unittest_lint.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_custom_should_analyze_file():
    """Check that we can write custom should_analyze_file that work
    even for arguments.
    """

    class CustomPyLinter(PyLinter):
        def should_analyze_file(self, modname, path, is_argument=False):
            if os.path.basename(path) == "wrong.py":
                return False

            return super(CustomPyLinter, self).should_analyze_file(
                modname, path, is_argument=is_argument
            )

    package_dir = os.path.join(HERE, "regrtest_data", "bad_package")
    wrong_file = os.path.join(package_dir, "wrong.py")

    for jobs in [1, 2]:
        reporter = testutils.TestReporter()
        linter = CustomPyLinter()
        linter.config.jobs = jobs
        linter.config.persistent = 0
        linter.open()
        linter.set_reporter(reporter)

        try:
            sys.path.append(os.path.dirname(package_dir))
            linter.check([package_dir, wrong_file])
        finally:
            sys.path.pop()

        messages = reporter.messages
        assert len(messages) == 1
        assert "invalid syntax" in messages[0] 
Example #9
Source File: test_functional.py    From python-netsurv with MIT License 5 votes vote down vote up
def __init__(self, test_file):
        test_reporter = FunctionalTestReporter()
        self._linter = lint.PyLinter()
        self._linter.set_reporter(test_reporter)
        self._linter.config.persistent = 0
        checkers.initialize(self._linter)
        self._linter.disable('I')
        try:
            self._linter.read_config_file(test_file.option_file)
            self._linter.load_config_file()
        except NoFileError:
            pass
        self._test_file = test_file 
Example #10
Source File: test_comparetozero.py    From python-netsurv with MIT License 5 votes vote down vote up
def setUpClass(cls):
        cls._linter = PyLinter()
        cls._linter.set_reporter(CompareToZeroTestReporter())
        checkers.initialize(cls._linter)
        cls._linter.register_checker(CompareToZeroChecker(cls._linter))
        cls._linter.disable('I') 
Example #11
Source File: test_import_graph.py    From python-netsurv with MIT License 5 votes vote down vote up
def linter():
    l = PyLinter(reporter=testutils.TestReporter())
    initialize(l)
    return l 
Example #12
Source File: unittest_checker_format.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_disable_global_option_end_of_line():
    """
    Test for issue with disabling tokenizer messages
    that extend beyond the scope of the ast tokens
    """
    file_ = tempfile.NamedTemporaryFile("w", delete=False)
    with file_:
        file_.write(
            """
mylist = [
    None
        ]
    """
        )
    try:
        linter = lint.PyLinter()
        checker = FormatChecker(linter)
        linter.register_checker(checker)
        args = linter.load_command_line_configuration(
            [file_.name, "-d", "bad-continuation"]
        )
        myreporter = reporters.CollectingReporter()
        linter.set_reporter(myreporter)
        linter.check(args)
        assert not myreporter.messages
    finally:
        os.remove(file_.name) 
Example #13
Source File: unittest_reporters_json.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_simple_json_output():
    output = StringIO()

    reporter = JSONReporter()
    linter = PyLinter(reporter=reporter)
    checkers.initialize(linter)

    linter.config.persistent = 0
    linter.reporter.set_output(output)
    linter.open()
    linter.set_current_module("0123")
    linter.add_message("line-too-long", line=1, args=(1, 2))

    # we call this method because we didn't actually run the checkers
    reporter.display_messages(None)

    expected_result = [
        [
            ("column", 0),
            ("line", 1),
            ("message", "Line too long (1/2)"),
            ("message-id", "C0301"),
            ("module", "0123"),
            ("obj", ""),
            ("path", "0123"),
            ("symbol", "line-too-long"),
            ("type", "convention"),
        ]
    ]
    report_result = json.loads(output.getvalue())
    report_result = [sorted(report_result[0].items(), key=lambda item: item[0])]
    assert report_result == expected_result 
Example #14
Source File: unittest_lint.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_custom_should_analyze_file():
    """Check that we can write custom should_analyze_file that work
    even for arguments.
    """

    class CustomPyLinter(PyLinter):
        def should_analyze_file(self, modname, path, is_argument=False):
            if os.path.basename(path) == "wrong.py":
                return False

            return super(CustomPyLinter, self).should_analyze_file(
                modname, path, is_argument=is_argument
            )

    package_dir = os.path.join(HERE, "regrtest_data", "bad_package")
    wrong_file = os.path.join(package_dir, "wrong.py")

    for jobs in [1, 2]:
        reporter = testutils.TestReporter()
        linter = CustomPyLinter()
        linter.config.jobs = jobs
        linter.config.persistent = 0
        linter.open()
        linter.set_reporter(reporter)

        try:
            sys.path.append(os.path.dirname(package_dir))
            linter.check([package_dir, wrong_file])
        finally:
            sys.path.pop()

        messages = reporter.messages
        assert len(messages) == 1
        assert "invalid syntax" in messages[0] 
Example #15
Source File: test_comparetozero.py    From python-netsurv with MIT License 5 votes vote down vote up
def setUpClass(cls):
        cls._linter = PyLinter()
        cls._linter.set_reporter(CompareToZeroTestReporter())
        checkers.initialize(cls._linter)
        cls._linter.register_checker(CompareToZeroChecker(cls._linter))
        cls._linter.disable('I') 
Example #16
Source File: test_import_graph.py    From python-netsurv with MIT License 5 votes vote down vote up
def linter():
    l = PyLinter(reporter=testutils.TestReporter())
    initialize(l)
    return l 
Example #17
Source File: unittest_checker_format.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_disable_global_option_end_of_line():
    """
    Test for issue with disabling tokenizer messages
    that extend beyond the scope of the ast tokens
    """
    file_ = tempfile.NamedTemporaryFile("w", delete=False)
    with file_:
        file_.write(
            """
mylist = [
    None
        ]
    """
        )
    try:
        linter = lint.PyLinter()
        checker = FormatChecker(linter)
        linter.register_checker(checker)
        args = linter.load_command_line_configuration(
            [file_.name, "-d", "bad-continuation"]
        )
        myreporter = reporters.CollectingReporter()
        linter.set_reporter(myreporter)
        linter.check(args)
        assert not myreporter.messages
    finally:
        os.remove(file_.name) 
Example #18
Source File: monolith_checker.py    From Penny-Dreadful-Tools with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, linter: Optional[PyLinter] = None) -> None:
        BaseChecker.__init__(self, linter)
        self.isort_obj = isort.SortImports(
            file_contents='',
        ) 
Example #19
Source File: l18n_check.py    From Penny-Dreadful-Tools with GNU General Public License v3.0 5 votes vote down vote up
def register_checkers(linter: PyLinter) -> None:
    """Register checkers."""
    linter.register_checker(TranslationStringConstantsChecker(linter)) 
Example #20
Source File: __init__.py    From Penny-Dreadful-Tools with GNU General Public License v3.0 5 votes vote down vote up
def register(linter: PyLinter) -> None:
    """Required method to auto register this checker.

    Args:
        linter: Main interface object for Pylint plugins.
    """
    linter.register_checker(MonolithChecker(linter))
    linter.register_checker(TranslationStringConstantsChecker(linter))
    linter.register_checker(AsyncAwaitChecker(linter))