How to use the dlint.tree 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_helpers / test_bad_kwarg_use.py View on Github external
def test_kwargs_same_name_different_kwarg(self):
        python_node = self.get_ast_node(
            """
            import foo

            foo.bar(kwarg2="test")
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.bar",
                    "kwarg_name": "kwarg1",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected
github duo-labs / dlint / tests / test_tree.py View on Github external
def test_decorator_name_unknown_type(self):
        unknown_type = None

        with pytest.raises(TypeError):
            dlint.tree.decorator_name(unknown_type)
github duo-labs / dlint / dlint / linters / helpers / bad_module_use.py View on Github external
def visit_ImportFrom(self, node):
        if not node.module:
            # Relative imports, e.g. 'from .' or 'from ..'
            return

        from_import_names = [
            node.module + "." + alias.name
            for alias in node.names
            if node.module + "." + alias.name not in self.whitelisted_modules
        ]

        bad_from_import = any(
            tree.same_modules(illegal_module, name)
            for illegal_module in self.illegal_modules
            for name in from_import_names
        )

        if bad_from_import:
            self.results.append(
                base.Flake8Result(
                    lineno=node.lineno,
                    col_offset=node.col_offset,
                    message=self._error_tmpl
                )
github duo-labs / dlint / dlint / linters / bad_defusedxml_use.py View on Github external
"predicate": tree.kwarg_not_present,
            },
            {
                "module_path": "defusedxml.lxml.iterparse",
                "kwarg_name": "forbid_dtd",
                "predicate": tree.kwarg_not_present,
            },
            {
                "module_path": "defusedxml.lxml.parse",
                "kwarg_name": "forbid_dtd",
                "predicate": tree.kwarg_not_present,
            },
            {
                "module_path": "defusedxml.lxml.fromstring",
                "kwarg_name": "forbid_entities",
                "predicate": tree.kwarg_false,
            },
            {
                "module_path": "defusedxml.lxml.iterparse",
                "kwarg_name": "forbid_entities",
                "predicate": tree.kwarg_false,
            },
            {
                "module_path": "defusedxml.lxml.parse",
                "kwarg_name": "forbid_entities",
                "predicate": tree.kwarg_false,
            },
            {
                "module_path": "defusedxml.lxml.fromstring",
                "kwarg_name": "forbid_external",
                "predicate": tree.kwarg_false,
            },
github duo-labs / dlint / dlint / linters / bad_onelogin_kwarg_use.py View on Github external
def missing_or_string(s, call, kwarg_name):
            return (
                tree.kwarg_not_present(call, kwarg_name)
                or tree.kwarg_str(call, kwarg_name, s)
            )
github duo-labs / dlint / dlint / linters / bad_urllib3_kwarg_use.py View on Github external
def unverified_cert_reqs(call, kwarg_name):
            return tree.kwarg_any([
                functools.partial(
                    tree.kwarg_str,
                    call,
                    kwarg_name,
                    "CERT_NONE"
                ),
                functools.partial(
                    tree.kwarg_str,
                    call,
                    kwarg_name,
                    "NONE"
                ),
                functools.partial(
                    tree.kwarg_module_path,
                    call,
                    kwarg_name,
github duo-labs / dlint / dlint / linters / bad_xmlrpc_use.py View on Github external
def kwargs(self):
        return [
            {
                "module_path": "SimpleXMLRPCServer.register_instance",
                "kwarg_name": "allow_dotted_names",
                "predicate": tree.kwarg_true,
            },