-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GometalinterBear which replaces some of existing bears like errcheck, vet etc Closes #972
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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'(.*):(\d*):(\d*):(.*) \((\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: typed_list(str)=None, | ||
gometalinter_enable: typed_list(str)=None, | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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)) |