class GoLintBear: """ Checks the code using ``golint``. This will run golint over each file separately. """ LANGUAGES = {'Go'} REQUIREMENTS = { GoRequirement(package='godoc.org/golang.org/x/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, )
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', 'Code Simplification'} ASCIINEMA_URL = 'https://asciinema.org/a/94812' @staticmethod def create_arguments( filename, file, config_file, simplify: bool = False, ): """ :param simplify: Tries to simplify code """ args = () if simplify: args += ('-s', ) return args
class GoErrCheckBear: # pragma nt: no cover """ 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, )
class GoImportsBear: # pragma nt: no cover """ 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 ()
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 ()
class GoTypeBear: # pragma nt: no cover """ 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
class TOMLBear: # pragma nt: no cover """ Checks the code for formatting in ``TOML`` documents and prints each key's type. This is done using ``tomlv`` utility. """ LANGUAGES = {'TOML'} REQUIREMENTS = { GoRequirement('github.com/BurntSushi/toml/cmd/tomlv'), } AUTHORS = {'The coala developers'} AUTHORS_EMAILS = {'*****@*****.**'} LICENSE = 'AGPL-3.0' CAN_DETECT = {'Formatting', 'Syntax'} SEE_MORE = 'https://github.com/BurntSushi/toml/tree/master/cmd/tomlv' @staticmethod def create_arguments(filename, file, config_file): return (filename, )
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