Skip to content

Commit

Permalink
bears/go: Add GoMetaLinterBear
Browse files Browse the repository at this point in the history
Add GometalinterBear which replaces some of existing bears
like errcheck, vet etc

Closes #972
  • Loading branch information
Vamshi99 committed Jul 21, 2017
1 parent c9be1bf commit 40278a3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go get -u sourcegraph.com/sqs/goreturns
go get -u golang.org/x/tools/cmd/gotype
go get -u github.com/kisielk/errcheck
go get -u github.com/BurntSushi/toml/cmd/tomlv
go get -u gopkg.in/alecthomas/gometalinter.v1

# Ruby commands
bundle install --path=vendor/bundle --binstubs=vendor/bin --jobs=8 --retry=3
Expand Down
45 changes: 45 additions & 0 deletions bears/go/GoMetaLinterBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.GoRequirement import GoRequirement


@linter(executable='gometalinter.v1',
use_stdout=True,
output_format='regex',
output_regex=r'(.*):(?P<line>\d*):(?P<column>\d*):'
'(?P<message>.*) \((?:\w*)\)')
class GoMetaLinterBear:
"""
Checks the ``go`` code using ``gometalinter``. This will run
some set of golang linters over each file separately.
"""
LANGUAGES = {'Go'}
REQUIREMENTS = {GoRequirement(
package='gopkg.in/alecthomas/gometalinter.v1', flag='-u')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting', 'Syntax', 'Missing import',
'Unused Code', 'Smell', 'Unreachable Code', 'Security'}
SEE_MORE = 'https://github.com/alecthomas/gometalinter'

@staticmethod
def create_arguments(filename, file, config_file,
gometalinter_disable: str='',
gometalinter_enable: str='',
gometalinter_config: str=''):
"""
:param gometalinter_disable:
Disable a linter.
:param gometalinter_enable:
Enable a linter.
:param gometalinter_config:
Path to a custom configuration file.
"""
args = ()
if gometalinter_disable:
args += ('--disable=' + gometalinter_disable,)
if gometalinter_enable:
args += ('--enable=' + gometalinter_enable,)
if gometalinter_config:
args += ('--config=' + gometalinter_config,)
return args
40 changes: 40 additions & 0 deletions tests/go/GoMetaLinterBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from bears.go.GoMetaLinterBear import GoMetaLinterBear
from coalib.testing.LocalBearTestHelper import verify_local_bear

good_file_errcheck = """package main
import "fmt"
func main() {
fmt.Println("Hello, Arch!")
}
"""

bad_file_errcheck = """package main
import "os"
func main() {
f, _ := os.Open("foo")
f.Write([]byte("Hello, world."))
f.Close()
}
"""

good_file_imports = """package main
import "os"
func main() {
\tf, _ := os.Open("foo")
}"""

bad_file_imports = """package main
func main() {
\tf, _ := os.Open("foo")
}"""


GoMetaLinterBearTest = verify_local_bear(GoMetaLinterBear,
valid_files=(good_file_errcheck,
bad_file_imports),
invalid_files=(bad_file_errcheck,
good_file_imports))

0 comments on commit 40278a3

Please sign in to comment.