How to use the dlint.linters.base.Flake8Result 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_module_attribute_use.py View on Github external
linter = get_bad_module_attribute_use_implementation({
            'm1.m2.m3.m4': ['bad_attribute'],
            'm2.m3.m4': ['bad_attribute'],
            'm3.m4': ['bad_attribute'],
            'm4': ['bad_attribute'],
        })
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_bad_attribute_usage(self):
        python_node = self.get_ast_node(
            """
            import random

            var = random.random()
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_twisted / test_yield_return_statement.py View on Github external
python_node = self.get_ast_node(
            """
            from twisted.internet.defer import inlineCallbacks

            @inlineCallbacks
            def func(arg):
                return arg
            """
        )

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

        result = linter.get_results()
        expected = [] if IS_PYTHON_3_3 else [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=4,
                message=dlint.linters.YieldReturnStatementLinter._error_tmpl
            )
        ]

        assert result == expected
github duo-labs / dlint / tests / test_helpers / test_bad_module_attribute_use.py View on Github external
python_node = self.get_ast_node(
            """
            import foo

            var = 'echo "TEST"'

            foo.bar(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation({'foo': ['bar']})
        linter.visit(python_node)

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_onelogin_kwarg_use.py View on Github external
OneLogin_Saml2_Utils.validate_node_sign()
            OneLogin_Saml2_Utils.validate_node_sign(fingerprintalg="sha1")
            OneLogin_Saml2_Utils.validate_node_sign(fingerprintalg="sha256", validatecert=False)

            OneLogin_Saml2_Utils.validate_binary_sign()
            OneLogin_Saml2_Utils.validate_binary_sign(algorithm=OneLogin_Saml2_Constants.RSA_SHA1)
            OneLogin_Saml2_Utils.validate_binary_sign(algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1")
            """
        )

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

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=5,
                col_offset=0,
                message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
github duo-labs / dlint / tests / test_bad_exec_use.py View on Github external
def test_bad_exec_usage(self):
        python_node = self.get_ast_node(
            """
            var = 1

            exec('print var + 1')
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_os_use.py View on Github external
dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=11,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=12,
                col_offset=0,
                message=dlint.linters.BadOSUseLinter._error_tmpl
            ),
        ]
github duo-labs / dlint / dlint / linters / helpers / bad_module_use.py View on Github external
def visit_Import(self, node):
        import_names = [
            alias.name for alias in node.names
            if alias.name not in self.whitelisted_modules
        ]

        bad_import = any(
            tree.same_modules(illegal_module, name)
            for illegal_module in self.illegal_modules
            for name in import_names
        )

        if bad_import:
            self.results.append(
                base.Flake8Result(
                    lineno=node.lineno,
                    col_offset=node.col_offset,
                    message=self._error_tmpl
                )
github duo-labs / dlint / dlint / linters / helpers / bad_name_attribute_use.py View on Github external
target for target in targets
                        if target.variable == variable
                    ],
                    key=lambda target: (target.lineno, target.col_offset)
                )
            except ValueError:
                # No variable name matches
                return

            if latest_variable_assignment in illegal_calls:
                results.append(inner_node)

        tree.walk_callback_same_scope(node, attribute_use_callback)

        self.results.extend([
            base.Flake8Result(
                lineno=result.lineno,
                col_offset=result.col_offset,
                message=self._error_tmpl
            )
            for result in results
        ])