pronto-golang 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/lib/pronto/golang.rb +101 -0
- data/lib/pronto/golang/tools.rb +11 -0
- data/lib/pronto/golang/tools/errcheck.rb +27 -0
- data/lib/pronto/golang/tools/golint.rb +23 -0
- data/lib/pronto/golang/tools/gosimple.rb +23 -0
- data/lib/pronto/golang/tools/govet.rb +23 -0
- data/lib/pronto/golang/tools/unparam.rb +23 -0
- data/lib/pronto/golang/tools/unused.rb +23 -0
- data/lib/pronto/golang/version.rb +5 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85e017e9fa5d4b0b5ac4ae463c6e0a7bfe18e1c6
|
4
|
+
data.tar.gz: 670a418d1c9090b2baed18a9a365a55d4677d941
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2490baa9b58080974e677abe5f5ce152442c04b86b2cfaa416f75d5fff81c4e912e201526b92530c64f36f0a58b74fa5f4dbc719cca7848a74b61879fc848ef6
|
7
|
+
data.tar.gz: 2ffaaeed2fa0806eb2fb943b61dcac3855519236b4a3a33301f965adb3aa60149b8d2fc45c1b1a3643574bb408eba070f85becd06fac2484b81ae924aaf929f7
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Cash Payment Solutions GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Pronto runner for Golang
|
2
|
+
|
3
|
+
Pronto runner for [Golang](https://golang.org) tools
|
4
|
+
|
5
|
+
## Tools
|
6
|
+
|
7
|
+
| Tool | Install |
|
8
|
+
|----------|----------|
|
9
|
+
| golint | go get -u github.com/golang/lint/golint |
|
10
|
+
| gosimple | go get -u honnef.co/go/tools/cmd/gosimple |
|
11
|
+
| go vet | - |
|
12
|
+
| unused | go get -u honnef.co/go/tools/cmd/unused |
|
13
|
+
| unparam | go get -u mvdan.cc/unparam |
|
14
|
+
| errcheck | go get -u github.com/kisielk/errcheck |
|
15
|
+
|
16
|
+
## Enabling only certain tools
|
17
|
+
|
18
|
+
In order to only enable certain tools for execution it is possible to provide a `.golangtools.yml` file in the directory of execution.
|
19
|
+
|
20
|
+
It looks as follows:
|
21
|
+
```yaml
|
22
|
+
enabled_tools:
|
23
|
+
- errcheck
|
24
|
+
- gosimple
|
25
|
+
# ...
|
26
|
+
```
|
27
|
+
|
28
|
+
If the `enabled_tools` is available only the tools in the list will be executed. Note that the tool in question should match the value returned by `base_command`.
|
29
|
+
|
30
|
+
## Implementing additional tools
|
31
|
+
|
32
|
+
It is possible to add additional tools by adding a new class in the `Pronto::GolangTools` namespace.
|
33
|
+
|
34
|
+
It is expected that it reponds to the following methods:
|
35
|
+
|
36
|
+
| Method | Description |
|
37
|
+
|--------|-------------|
|
38
|
+
| `command(file_path)` | Executes the command and receives the file_path to allow checking only the current file |
|
39
|
+
| `base_command` | Returns the name/basic command that will be invoked. Is also used for enabling and disabling it via `.golangtools.yml` |
|
40
|
+
| `installed?` | Returns true if the tool can be found, e.g. through `which #{base_command}` |
|
41
|
+
| `parse_line(line)` | Receives the line returned from the tool for parsing. REturns `absolute_path`, `line_number`, `level`, `message text` |
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'pronto'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require_relative './golang/tools'
|
6
|
+
|
7
|
+
module Pronto
|
8
|
+
class Golang < Runner
|
9
|
+
CONFIG_FILE = '.golangtools.yml'
|
10
|
+
GOLANG_FILE_EXTENSIONS = ['.go'].freeze
|
11
|
+
|
12
|
+
def run
|
13
|
+
return [] unless @patches
|
14
|
+
|
15
|
+
@patches
|
16
|
+
.select { |patch| valid_patch?(patch) }
|
17
|
+
.map { |patch| inspect(patch) }
|
18
|
+
.flatten
|
19
|
+
.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_patch?(patch)
|
23
|
+
patch.additions > 0 && go_file?(patch.new_file_full_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect(patch)
|
27
|
+
escaped_path = Shellwords.escape(patch.new_file_full_path.to_s)
|
28
|
+
|
29
|
+
messages = []
|
30
|
+
|
31
|
+
available_tools.each do |tool|
|
32
|
+
Open3.popen3("#{tool.command(escaped_path)}") do |stdin, stdout, stderr, wait_thr|
|
33
|
+
[stdout, stderr].each do |result_text|
|
34
|
+
while output_line = result_text.gets
|
35
|
+
next if output_line.strip == 'exit status 1'
|
36
|
+
|
37
|
+
messages << process_line(patch, tool, output_line)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
while output_line = stderr.gets
|
44
|
+
process_line(patch, tool, output_line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
return messages
|
50
|
+
end
|
51
|
+
|
52
|
+
def process_line(patch, tool, output_line)
|
53
|
+
file_path, line_number, severity, message = tool.parse_line(output_line)
|
54
|
+
|
55
|
+
patch.added_lines.each do |line|
|
56
|
+
if line_number.to_s == line.new_lineno.to_s &&
|
57
|
+
patch.new_file_full_path.to_s == file_path
|
58
|
+
|
59
|
+
return Message.new(
|
60
|
+
file_path, line, severity, message, line.commit_sha, self.class
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def available_tools
|
69
|
+
if @tools == nil
|
70
|
+
config = dotconfig
|
71
|
+
|
72
|
+
@tools = GolangTools.constants.map do |constant|
|
73
|
+
tool = Object.const_get("Pronto::GolangTools::#{constant}").new
|
74
|
+
|
75
|
+
if tool.installed? &&
|
76
|
+
(!config.key?('enabled_tools') ||
|
77
|
+
config['enabled_tools'].include?(tool.base_command))
|
78
|
+
|
79
|
+
tool
|
80
|
+
else
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end.compact
|
84
|
+
end
|
85
|
+
|
86
|
+
return @tools
|
87
|
+
end
|
88
|
+
|
89
|
+
def dotconfig
|
90
|
+
if File.exist?(CONFIG_FILE)
|
91
|
+
return YAML.load_file(CONFIG_FILE)
|
92
|
+
end
|
93
|
+
|
94
|
+
return {}
|
95
|
+
end
|
96
|
+
|
97
|
+
def go_file?(path)
|
98
|
+
GOLANG_FILE_EXTENSIONS.include?(File.extname(path))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require_relative './tools/errcheck'
|
7
|
+
require_relative './tools/golint'
|
8
|
+
require_relative './tools/gosimple'
|
9
|
+
require_relative './tools/govet'
|
10
|
+
require_relative './tools/unparam'
|
11
|
+
require_relative './tools/unused'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Errcheck
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'errcheck'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
`which #{base_command}` != ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, _, _ = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message
|
20
|
+
end
|
21
|
+
|
22
|
+
def message
|
23
|
+
'Error response given but not checked'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Golint
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'golint'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
`which #{base_command}` != ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, _, message = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Gosimple
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'gosimple'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
`which #{base_command}` != ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, _, message = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Govet
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'go vet'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, message = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Unparam
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'unparam'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
`which #{base_command}` != ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, _, message = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pronto
|
2
|
+
module GolangTools
|
3
|
+
class Unused
|
4
|
+
def command(file_path)
|
5
|
+
"#{base_command} ./..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_command
|
9
|
+
'unused'
|
10
|
+
end
|
11
|
+
|
12
|
+
def installed?
|
13
|
+
`which #{base_command}` != ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_line(line)
|
17
|
+
file_path, line_number, _, message = line.split(':')
|
18
|
+
|
19
|
+
return File.expand_path(file_path), line_number, :warning, message.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-golang
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Schoknecht
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description:
|
56
|
+
email: tobias.schoknecht@barzahlen.de
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/pronto/golang.rb
|
66
|
+
- lib/pronto/golang/tools.rb
|
67
|
+
- lib/pronto/golang/tools/errcheck.rb
|
68
|
+
- lib/pronto/golang/tools/golint.rb
|
69
|
+
- lib/pronto/golang/tools/gosimple.rb
|
70
|
+
- lib/pronto/golang/tools/govet.rb
|
71
|
+
- lib/pronto/golang/tools/unparam.rb
|
72
|
+
- lib/pronto/golang/tools/unused.rb
|
73
|
+
- lib/pronto/golang/version.rb
|
74
|
+
homepage: https://github.com/Barzahlen/pronto-golang
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.0.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Pronto runner for golang tools
|
98
|
+
test_files: []
|