コード例 #1
0
class GoErrCheckBear:
    """
    Checks the code for all function calls that have unchecked errors.
    GoErrCheckBear runs ``errcheck`` over each file to find such functions.

    For more information on the analysis visit
    <https://github.com/kisielk/errcheck>.
    """
    LANGUAGES = {"Go"}
    REQUIREMENTS = {
        GoRequirement(package='github.com/kisielk/errcheck', flag='-u')
    }
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    ASCIINEMA_URL = 'https://asciinema.org/a/46834'
    CAN_DETECT = {'Syntax'}

    @staticmethod
    def create_arguments(filename,
                         file,
                         config_file,
                         ignore: typed_list(str) = [],
                         ignorepkg: typed_list(str) = [],
                         asserts: bool = False,
                         blank: bool = False):
        """
        Bear configuration arguments.

        :param ignore:       Comma-separated list of pairs of the
                             form package:regex. For each package, the regex
                             describes which functions to ignore within that
                             package. The package may be omitted to have the
                             regex apply to all packages.
        :param ignorepkg:    Takes a comma-separated list of package
                             import paths to ignore.
        :param asserts:      Enables checking for ignored type assertion
                             results.
        :param blank:        Enables checking for assignments of errors to
                             the blank identifier.

        """
        args = ()
        if ignore:
            args += ('-ignore', ','.join(part.strip() for part in ignore))
        if ignorepkg:
            args += ('-ignorepkg', ','.join(part.strip()
                                            for part in ignorepkg))
        if blank:
            args += ("-blank", )
        if asserts:
            args += ("-asserts", )
        return args + (filename, )
コード例 #2
0
class GoImportsBear:
    """
    Adds/Removes imports to Go code for missing imports.
    """
    LANGUAGES = {'Go'}
    REQUIREMENTS = {GoRequirement(
        package='golang.org/x/tools/cmd/goimports', flag='-u')}
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    CAN_FIX = {'Missing import'}

    @staticmethod
    def create_arguments(filename, file, config_file):
        return ()
コード例 #3
0
class GoReturnsBear:
    """
    Proposes corrections of Go code using ``goreturns``.
    """
    LANGUAGES = {'Go'}
    REQUIREMENTS = {
        GoRequirement(package='sourcegraph.com/sqs/goreturns', flag='-u')
    }
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    CAN_FIX = {'Security'}

    @staticmethod
    def create_arguments(filename, file, config_file):
        return ()
コード例 #4
0
ファイル: GoTypeBear.py プロジェクト: srk97/coala-bears
class GoTypeBear:
    """
    Checks the code using ``gotype``. This will run ``gotype`` over each file
    separately.
    """
    LANGUAGES = {'Go'}
    REQUIREMENTS = {
        GoRequirement(package='golang.org/x/tools/cmd/gotype', flag='-u')
    }
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    ASCIINEMA_URL = 'https://asciinema.org/a/40055'
    CAN_DETECT = {'Syntax'}

    @staticmethod
    def create_arguments(filename, file, config_file):
        return '-e', filename
コード例 #5
0
ファイル: GofmtBear.py プロジェクト: cs360f16/coala-bears
class GofmtBear:
    """
    Suggest better formatting options in Go code. Basic checks like alignment,
    indentation, and redundant parentheses are provided.

    This is done using the ``gofmt`` utility. For more information visit
    <https://golang.org/cmd/gofmt/>.
    """
    LANGUAGES = {'Go'}
    REQUIREMENTS = {GoRequirement(package='golang.org/cmd/gofmt', flag='-u')}
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    CAN_FIX = {'Formatting'}

    @staticmethod
    def create_arguments(filename, file, config_file):
        return ()
コード例 #6
0
ファイル: GoVetBear.py プロジェクト: srk97/coala-bears
class GoVetBear:
    """
    Analyze Go code and raise suspicious constructs, such as printf calls
    whose arguments do not correctly match the format string, useless
    assignments, common mistakes about boolean operations, unreachable code,
    etc.

    This is done using the ``vet`` command. For more information visit
    <https://golang.org/cmd/vet/>.
    """
    LANGUAGES = {'Go'}
    REQUIREMENTS = {GoRequirement(package='golang.org/cmd/vet', flag='-u')}
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    CAN_DETECT = {'Unused Code', 'Smell', 'Unreachable Code'}

    @staticmethod
    def create_arguments(filename, file, config_file):
        return 'vet', filename
コード例 #7
0
ファイル: GoLintBear.py プロジェクト: zharkovav/coala-bears
class GoLintBear:
    """
    Checks the code using ``golint``. This will run golint over each file
    separately.
    """
    LANGUAGES = {"Go"}
    REQUIREMENTS = {GoRequirement(
        package='github.com/golang/lint/golint', flag='-u')}
    AUTHORS = {'The coala developers'}
    AUTHORS_EMAILS = {'*****@*****.**'}
    LICENSE = 'AGPL-3.0'
    CAN_DETECT = {'Formatting'}

    @staticmethod
    def create_arguments(filename, file, config_file,
                         golint_cli_options: str=''):
        """
        :param golint_cli_options: Any other flags you wish to pass to golint.
        """
        args = ()
        if golint_cli_options:
            args += tuple(shlex.split(golint_cli_options))
        return args + (filename,)
コード例 #8
0
 def test_installed_requirement(self):
     self.assertTrue(GoRequirement('fmt').is_installed())
コード例 #9
0
 def test_not_installed_requirement(self):
     self.assertFalse(GoRequirement('some_bad_package').is_installed())