How to use the dlint.linters.base function in dlint

To help you get started, we’ve selected a few dlint 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 duo-labs / dlint / tests / test_bad_compile_use.py View on Github external
def test_bad_compile_usage(self):
        python_node = self.get_ast_node(
            """
            var = 1

            result = compile('var + 1', '', 'eval')
            """
        )

        linter = dlint.linters.BadCompileUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=9,
                message=dlint.linters.BadCompileUseLinter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_helpers / test_bad_module_use.py View on Github external
import foo
            import bar
            """
        )

        linter = get_bad_module_use_implementation(["foo", "bar"])
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=3,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_bad_pickle_use.py View on Github external
linter = dlint.linters.BadPickleUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=dlint.linters.BadPickleUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=4,
                message=dlint.linters.BadPickleUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=9,
                message=dlint.linters.BadPickleUseLinter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_bad_dl_use.py View on Github external
def test_bad_dl_usage(self):
        python_node = self.get_ast_node(
            """
            import dl
            """
        )

        linter = dlint.linters.BadDlUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
                message=dlint.linters.BadDlUseLinter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
"""
            import random

            _generator = random.SystemRandom()

            var1 = _generator.randint(256)
            var2 = random.randint(256)
            """
        )

        linter = dlint.linters.BadRandomGeneratorUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=7,
                message=dlint.linters.BadRandomGeneratorUseLinter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_bad_urllib3_module_attribute_use.py View on Github external
def test_bad_urllib3_module_attribute_usage_from_import(self):
        python_node = self.get_ast_node(
            """
            from urllib3 import disable_warnings
            disable_warnings()
            """
        )

        linter = dlint.linters.BadUrllib3ModuleAttributeUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=3,
                col_offset=0,
                message=dlint.linters.BadUrllib3ModuleAttributeUseLinter._error_tmpl
            ),
        ]

        assert result == expected
github duo-labs / dlint / tests / test_bad_duo_client_use.py View on Github external
dlint.linters.base.Flake8Result(
                lineno=13,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=14,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=15,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=16,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=17,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=18,
                col_offset=0,
                message=dlint.linters.BadDuoClientUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=19,
github duo-labs / dlint / dlint / linters / helpers / bad_module_attribute_use.py View on Github external
def get_results(self):

        return [
            base.Flake8Result(
                lineno=node.lineno,
                col_offset=node.col_offset,
                message=self._error_tmpl
            )
            for node in self.bad_nodes
        ]