Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP bears/go: Add GoMetaLinterBear #1933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a list ? (enabling more than 1 linter)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gometalinter_config: str=''):
"""
:param gometalinter_disable:
Disable a linter.
:param gometalinter_enable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should list the supported linters for our users to know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the user will need to install all the linters first ?

Copy link
Member Author

@Vamshi99 Vamshi99 Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yash-nisar Yeah, we should mention about all supported linters. Should I list them in the documentation section? Also I will add command to install all the linters.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be like :

from coalib.testing.LocalBearTestHelper import verify_local_bear

from bears.go.GoMetaLinterBear import GoMetaLinterBear

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason? I think many of the tests are not written in that pattern 🤔

Copy link
Member

@yash-nisar yash-nisar Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we need to correct them, see PEP8 imports for more information.

from coalib.testing.LocalBearTestHelper import verify_local_bear

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 lines before the code begins 😄

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a test with a config_file ?