-
Notifications
You must be signed in to change notification settings - Fork 581
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the user will need to install all the linters first ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from bears.go.GoMetaLinterBear import GoMetaLinterBear | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imports should be like :
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a test with a |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listing doesn't work here.
https://github.com/alecthomas/gometalinter#whats-the-best-way-to-use-gometalinter-in-ci