pronto-golang 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78838b2b1bf653434084571dc636c643944b67111bda54cea5fce92301f7c8f4
4
- data.tar.gz: df2744fb7b735d9290ecd3db3518b17d483bc4313e571eaf15b03170eb9b46e7
3
+ metadata.gz: 120d00f5e921b115909bfc11916d9ee23230182ac4a34f95f86c468e9f9328b0
4
+ data.tar.gz: 1f33e54b1290fc68f0048fc34be88734f9717f998dd7d13705e688a7a52aba24
5
5
  SHA512:
6
- metadata.gz: efc448f0df3114c77c86f7527b6d27cbd2b31eb9f18ecac2ec73dec53e6a43d471bcaf2a1ba618519ee319dcfc04efdc819ee263093269ffb577348c56161619
7
- data.tar.gz: b5d98cb7367a6ac5644183936c08fc876d4af79cde4c025f88e1eaf1ec5898ed78eac98fd23233d3b8740505bcb109d995fc251d4ea506dfffb5201edeb371d5
6
+ metadata.gz: c62f9f498b04990ebe48b1ada3f9498cc3db39ab785f748c3a18863f80081ad7dec60bd6bf7426eeb26353c7c581ff4c33810af0da9de0bfa30e7acdece57ce3
7
+ data.tar.gz: 184a6a107c0442ae979f591f894af8e130c292d6f58059528a35e3f77b8dd0ee7860ff50d19a627de068bd3d7b850bcb7e0ddf6b6075db39a156b1a041202ee2
data/README.md CHANGED
@@ -45,7 +45,7 @@ It is expected that it reponds to the following methods:
45
45
  | `command(file_path)` | Executes the command and receives the file_path to allow checking only the current file |
46
46
  | `self.base_command` | Returns the name/basic command that will be invoked. Is also used for enabling and disabling it via `.golangtools.yml` |
47
47
  | `available?` | Returns true if the tool can be found, e.g. through `which #{base_command}` |
48
- | `parse_line(line)` | Receives the line returned from the tool for parsing. Returns `absolute_path`, `line_number`, `level`, `message text` |
48
+ | `process_output(output)` | Receives the output returned from the tool for parsing. Returns an array of `Output` with `absolute_path`, `line_number`, `level`, `message text` |
49
49
 
50
50
  It is possible to inherit from `Pronto::GolangTools::Base`, in which case only `self.base_command` and `parse_line` need to be implemented.
51
51
 
@@ -0,0 +1,12 @@
1
+ module Pronto
2
+ module GolangSupport
3
+
4
+ Output = Struct.new(
5
+ :file_path,
6
+ :line_number,
7
+ :level,
8
+ :message,
9
+ )
10
+
11
+ end
12
+ end
@@ -1,3 +1,5 @@
1
+ require_relative '../output'
2
+
1
3
  module Pronto
2
4
  module GolangTools
3
5
  class Base
@@ -14,13 +16,17 @@ module Pronto
14
16
  end
15
17
 
16
18
  def command(file_path)
17
- "cd #{directory} && #{base_command} #{parameters} #{file_path}"
19
+ "cd #{directory} && #{base_command} #{default_parameters} #{parameters} #{file_path}"
18
20
  end
19
21
 
20
22
  def directory(default = '.')
21
23
  @config.fetch('execution_directory', default)
22
24
  end
23
25
 
26
+ def default_parameters
27
+ '' # blank, can be overwritten for tools
28
+ end
29
+
24
30
  def parameters
25
31
  @config.fetch('parameters', '') # Default to '' if the key is not configured
26
32
  end
@@ -48,8 +54,8 @@ module Pronto
48
54
  'file'
49
55
  end
50
56
 
51
- def parse_line(line)
52
- elements = line.split(':')
57
+ def process_output(output)
58
+ elements = output.split(':')
53
59
  file_path = elements[0]
54
60
  line_number = elements[1]
55
61
 
@@ -72,7 +78,9 @@ module Pronto
72
78
  file_path = File.join(dir, file_path)
73
79
  end
74
80
 
75
- return file_path, line_number, :warning, message.to_s.strip
81
+ return [
82
+ Pronto::GolangSupport::Output.new(file_path, line_number, :warning, message.to_s.strip),
83
+ ]
76
84
  end
77
85
  end
78
86
  end
@@ -1,3 +1,7 @@
1
+ require 'json'
2
+
3
+ require_relative '../output'
4
+
1
5
  module Pronto
2
6
  module GolangTools
3
7
  class GolangCiLint < Base
@@ -8,6 +12,31 @@ module Pronto
8
12
  def execution_mode
9
13
  'project'
10
14
  end
15
+
16
+ def default_parameters
17
+ 'run --out-format=json'
18
+ end
19
+
20
+ def process_output(output)
21
+ issues = JSON.parse(output).fetch('Issues')
22
+
23
+ dir = directory('')
24
+
25
+ return issues.map do |issue|
26
+ file_path = issue.fetch('Pos').fetch('Filename')
27
+
28
+ if dir != ''
29
+ file_path = File.join(dir, file_path)
30
+ end
31
+
32
+ Pronto::GolangSupport::Output.new(
33
+ file_path,
34
+ issue.fetch('Pos').fetch('Line'),
35
+ :warning,
36
+ "#{issue.fetch('Text')} (#{issue.fetch('FromLinter')})",
37
+ )
38
+ end
39
+ end
11
40
  end
12
41
  end
13
42
  end
@@ -1,3 +1,5 @@
1
+ require_relative '../output'
2
+
1
3
  module Pronto
2
4
  module GolangTools
3
5
  class Golint < Base
@@ -5,15 +7,17 @@ module Pronto
5
7
  'golint'
6
8
  end
7
9
 
8
- def parse_line(line)
9
- path, line_number, _, message = line.split(':')
10
+ def process_output(output)
11
+ path, line_number, _, message = output.split(':')
10
12
 
11
13
  absolute_path = Pathname.new(path)
12
14
  working_directory = Pathname.new(Dir.pwd)
13
15
 
14
16
  file_path = absolute_path.relative_path_from(working_directory).to_s
15
17
 
16
- return file_path, line_number, :warning, message.to_s.strip
18
+ return [
19
+ Pronto::GolangSupport::Output.new(file_path, line_number, :warning, message.to_s.strip),
20
+ ]
17
21
  end
18
22
  end
19
23
  end
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
3
  require_relative '../errors'
4
+ require_relative '../output'
4
5
 
5
6
  module Pronto
6
7
  module GolangTools
@@ -20,7 +21,7 @@ module Pronto
20
21
  "#{base_command} #{parameters} #{File.dirname(file_path)}"
21
22
  end
22
23
 
23
- def parse_line(line)
24
+ def process_output(line)
24
25
  line = line.gsub(ANSI_COLOR_CODING_PATTERN, '')
25
26
 
26
27
  if !GOSEC_LINE_PATTERN.match(line)
@@ -36,7 +37,9 @@ module Pronto
36
37
 
37
38
  file_path = absolute_path.relative_path_from(working_directory)
38
39
 
39
- return file_path.to_s, line_number, :warning, message
40
+ return [
41
+ Pronto::GolangSupport::Output.new(file_path.to_s, line_number, :warning, message),
42
+ ]
40
43
  end
41
44
  end
42
45
  end
@@ -1,3 +1,5 @@
1
+ require_relative '../output'
2
+
1
3
  module Pronto
2
4
  module GolangTools
3
5
  class Staticcheck < Base
@@ -5,10 +7,12 @@ module Pronto
5
7
  'staticcheck'
6
8
  end
7
9
 
8
- def parse_line(line)
9
- file_path, line_number, _, message = line.split(':')
10
+ def process_output(output)
11
+ file_path, line_number, _, message = output.split(':')
10
12
 
11
- return file_path, line_number, :warning, message.to_s.strip
13
+ return [
14
+ Pronto::GolangSupport::Output.new(file_path, line_number, :warning, message.to_s.strip),
15
+ ]
12
16
  end
13
17
  end
14
18
  end
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module GolangVersion
3
- VERSION = '0.0.16'.freeze
3
+ VERSION = '0.0.17'.freeze
4
4
  end
5
5
  end
data/lib/pronto/golang.rb CHANGED
@@ -83,16 +83,16 @@ module Pronto
83
83
  next if output_line.strip == 'exit status 1'
84
84
 
85
85
  collected_findings << {
86
- line: output_line,
87
- tool: tool,
86
+ output: output_line,
87
+ tool: tool,
88
88
  }
89
89
  end
90
90
  end
91
91
 
92
92
  while output_line = stderr.gets
93
93
  collected_findings << {
94
- line: output_line,
95
- tool: tool,
94
+ output: output_line,
95
+ tool: tool,
96
96
  }
97
97
  end
98
98
  end
@@ -104,34 +104,43 @@ module Pronto
104
104
  messages = []
105
105
 
106
106
  findings.each do |finding|
107
- messages << process_line(patch, finding[:tool], finding[:line])
107
+ messages += process_line(patch, finding[:tool], finding[:output])
108
108
  end
109
109
 
110
110
  return messages
111
111
  end
112
112
 
113
- def process_line(patch, tool, output_line)
114
- return nil if output_line =~ /^#/
113
+ def process_line(patch, tool, output)
114
+ return [] if output =~ /^#/
115
115
 
116
116
  begin
117
- file_path, line_number, level, message = tool.parse_line(output_line)
117
+ messages = []
118
118
 
119
- patch.added_lines.each do |line|
120
- if line_number.to_s == line.new_lineno.to_s &&
121
- patch.new_file_full_path.to_s == File.expand_path(file_path)
119
+ parsed_outputs = tool.process_output(output)
122
120
 
123
- prefix_message = "#{tool.base_command}: #{message}"
121
+ parsed_outputs.each do |parsed_output|
122
+ patch.added_lines.each do |line|
124
123
 
125
- return Message.new(
126
- file_path, line, level, prefix_message, line.commit_sha, self.class
127
- )
124
+ next if parsed_output.line_number.to_s != line.new_lineno.to_s ||
125
+ patch.new_file_full_path.to_s != File.expand_path(parsed_output.file_path)
126
+
127
+ prefix_message = "#{tool.base_command}: #{parsed_output.message}"
128
+
129
+ messages << Message.new(
130
+ parsed_output.file_path,
131
+ line,
132
+ parsed_output.level,
133
+ prefix_message,
134
+ line.commit_sha,
135
+ self.class,
136
+ )
128
137
  end
129
138
  end
130
139
  rescue ::Pronto::GolangSupport::UnprocessableLine
131
140
  # Do nothing if the line is not processable
132
141
  end
133
142
 
134
- return nil
143
+ return messages
135
144
  end
136
145
 
137
146
  def available_tools
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-golang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-11 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto
@@ -71,6 +71,7 @@ files:
71
71
  - lib/pronto/golang.rb
72
72
  - lib/pronto/golang/errors.rb
73
73
  - lib/pronto/golang/file_finder.rb
74
+ - lib/pronto/golang/output.rb
74
75
  - lib/pronto/golang/tools.rb
75
76
  - lib/pronto/golang/tools/base.rb
76
77
  - lib/pronto/golang/tools/golangci_lint.rb