How to use the dlint.linters.base.BaseLinter 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 / dlint / linters / twisted / yield_return_statement.py View on Github external
from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import ast
import sys

from .. import base
from ... import tree


class YieldReturnStatementLinter(base.BaseLinter):
    """This linter looks for inlineCallbacks functions that have
    non-empty return statements. Using a non-empty return statement and a
    yield statement in the same function is a syntax error.
    """
    off_by_default = False

    _code = 'DUO101'
    _error_tmpl = 'DUO101 "inlineCallbacks" function cannot have non-empty "return" statement'

    def visit_FunctionDef(self, node):
        self.generic_visit(node)

        # https://twistedmatrix.com/documents/17.1.0/api/twisted.internet.defer.inlineCallbacks.html
        is_python_3_3 = sys.version_info >= (3, 3)

        if (is_python_3_3
github duo-labs / dlint / dlint / linters / twisted / returnvalue_in_inlinecallbacks.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import ast

from .. import base
from ... import tree


class ReturnValueInInlineCallbacksLinter(base.BaseLinter):
    """This linter looks for returnValue calls that are in a function missing
    a inlineCallbacks decorator.
    """
    off_by_default = False

    _code = 'DUO114'
    _error_tmpl = 'DUO114 "returnValue" in function missing "inlineCallbacks" decorator'

    def visit_FunctionDef(self, node):
        self.generic_visit(node)

        if tree.function_has_inlinecallbacks_decorator(node):
            return

        results = []
github duo-labs / dlint / dlint / linters / helpers / bad_name_attribute_use.py View on Github external
import abc
import ast
import collections

from .. import base
from ... import tree
from ... import util

Assignment = collections.namedtuple(
    'Assignment',
    ['variable', 'module_path', 'lineno', 'col_offset']
)


class BadNameAttributeUseLinter(base.BaseLinter, util.ABC):
    """This abstract base class provides an simple interface for creating new
    lint rules that block bad attributes on a variable object.
    """

    @property
    @abc.abstractmethod
    def illegal_name_attributes(self):
        """Subclasses must implement this property to return a dictionary
        that looks like:

            {
                "object_attribute": [
                    "parent_module_name1.child_module_name1",
                    "parent_module_name2.child_module_name2",
                ]
            }
github duo-labs / dlint / dlint / linters / helpers / bad_module_attribute_use.py View on Github external
from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import abc

from .. import base
from ... import tree
from ... import util


class BadModuleAttributeUseLinter(base.BaseLinter, util.ABC):
    """This abstract base class provides an simple interface for creating new
    lint rules that block bad attributes within a module.
    """

    @property
    @abc.abstractmethod
    def illegal_module_attributes(self):
        """Subclasses must implement this property to return a dictionary
        that looks like:

            {
                "module_name": [
                    "attribute_name1",
                    "attribute_name2",
                ]
            }
github duo-labs / dlint / dlint / linters / base.py View on Github external
def __init__(self, *args, **kwargs):
        self.results = []
        self.namespace = None

        super(BaseLinter, self).__init__(*args, **kwargs)
github duo-labs / dlint / dlint / linters / helpers / bad_builtin_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import abc

from .. import base
from ... import util


class BadBuiltinUseLinter(base.BaseLinter, util.ABC):
    """This abstract base class provides an simple interface for creating new
    lint rules that block builtin functions.
    """
    @property
    @abc.abstractmethod
    def illegal_builtin(self):
        """Subclasses must implement this property to return a string of the
        builtin function name they'd like to blacklist.
        """

    def visit_Name(self, node):
        if (node.id == self.illegal_builtin
                and not self.namespace.name_imported(node.id)):
            self.results.append(
                base.Flake8Result(
                    lineno=node.lineno,
github duo-labs / dlint / dlint / linters / bad_random_generator_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import ast

from . import base


class BadRandomGeneratorUseLinter(base.BaseLinter):
    """This linter looks for any use of the Python "random" module EXCEPT
    SystemRandom.

    By default Python uses a Mersenne Twister[1] implementation to generate
    random values, and this is not suitable for cryptographic purposes.
    SystemRandom uses os.urandom to get random data, which is generally a
    much better choice.

    [1] https://en.wikipedia.org/wiki/Mersenne_twister
    """
    off_by_default = False

    _code = 'DUO102'
    _error_tmpl = 'DUO102 insecure use of "random" module, prefer "random.SystemRandom"'

    def visit_Attribute(self, node):
github duo-labs / dlint / dlint / linters / helpers / bad_module_use.py View on Github external
from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import abc

from .. import base
from ... import tree
from ... import util


class BadModuleUseLinter(base.BaseLinter, util.ABC):
    """This abstract base class provides an simple interface for creating new
    lint rules that block bad modules.
    """

    @property
    @abc.abstractmethod
    def illegal_modules(self):
        """Subclasses must implement this property to return a list that
        looks like:

            [
                "module_name1",
                "parent_module_name.module_name2",
            ]
        """
github duo-labs / dlint / dlint / linters / helpers / bad_kwarg_use.py View on Github external
from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import abc
import ast

from .. import base
from ... import tree
from ... import util


class BadKwargUseLinter(base.BaseLinter, util.ABC):
    """This abstract base class provides an simple interface for creating new
    lint rules that block bad kwarg use.
    """

    @property
    @abc.abstractmethod
    def kwargs(self):
        """Subclasses must implement this property to return a list that
        looks like:

            [
                {
                    "module_path": "mod1.mod2.name1",
                    "kwarg_name": "kwarg1",
                    "predicate": ,
                },
github duo-labs / dlint / dlint / linters / bad_input_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import sys

from . import base


class BadInputUseLinter(base.BaseLinter):
    """This linter looks for use of the Python "input" function. In Python 2
    this function is tantamount to eval(raw_input()), and thus should not be
    used. In Python 3 raw_input() functionality has been moved to input().
    """
    off_by_default = False

    _code = 'DUO108'
    _error_tmpl = 'DUO108 use of "input" is insecure'

    def __init__(self, *args, **kwargs):
        self.unsafe_input_import = True

        super(BadInputUseLinter, self).__init__(*args, **kwargs)

    def visit_Name(self, node):
        is_python_2 = sys.version_info < (3, 0)