kolekti_radon 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ module Kolekti
2
+ module Radon
3
+ module Parser
4
+ class Base < Kolekti::Parser
5
+ attr_reader :metric_configurations, :persistence_strategy, :logger
6
+
7
+ def initialize(metric_configurations, persistence_strategy, logger)
8
+ @metric_configurations = metric_configurations
9
+ @persistence_strategy = persistence_strategy
10
+ @logger = logger
11
+ end
12
+
13
+ def command; raise NotImplementedError; end
14
+
15
+ # Default implementation is somewhat naive, but works for both Raw and
16
+ # Maintainability Index - it just expects keys named the same as the
17
+ # code for each metric configuration.
18
+ def parse(raw_output)
19
+ raw_output.each do |file_name, result_hash|
20
+ module_name = self.class.parse_file_name(file_name)
21
+
22
+ @metric_configurations.each do |metric_configuration|
23
+ value = result_hash[metric_configuration.metric.code] unless result_hash.key?('error')
24
+ value ||= self.class.default_value
25
+
26
+ @persistence_strategy.create_tree_metric_result(
27
+ metric_configuration, module_name, value.to_f,
28
+ KalibroClient::Entities::Miscellaneous::Granularity::PACKAGE)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,94 @@
1
+ require 'logger'
2
+
3
+ module Kolekti
4
+ module Radon
5
+ module Parser
6
+ class Cyclomatic < Base
7
+ def self.default_value
8
+ 1.0
9
+ end
10
+
11
+ def command
12
+ 'cc'
13
+ end
14
+
15
+ def parse(cc_output)
16
+ metric_configuration = metric_configurations.first
17
+
18
+ parse_output(cc_output) do |module_name, result, granularity|
19
+ value = result['complexity'].to_f
20
+ persistence_strategy.create_tree_metric_result(
21
+ metric_configuration, module_name, value, granularity)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # This method checks for errors found by Radon, switches the valid results between METHOD and FUNCTION
28
+ # Calls the passed block multiple times with (module_name, result, granularity)
29
+ def parse_output(cc_output, &block)
30
+ cc_output.each do |file_name, entries|
31
+ # If Radon couldn't parse the file we don't want to continue since the output is a error message
32
+ next if has_error?(file_name, entries)
33
+
34
+ file_module_name = self.class.parse_file_name(file_name)
35
+ functions = []
36
+ classes = []
37
+
38
+ entries.each do |entry|
39
+ if entry['type'] == 'class'
40
+ classes << entry
41
+ elsif entry['type'] == 'method'
42
+ # These entries are duplicated on Radon's output
43
+ next
44
+ else
45
+ functions << entry
46
+ end
47
+ end
48
+
49
+ parse_entries(functions, file_module_name,
50
+ KalibroClient::Entities::Miscellaneous::Granularity::FUNCTION, &block)
51
+
52
+ parse_entries(classes, file_module_name) do |class_module_name, class_entry, _|
53
+ parse_entries(class_entry['methods'], class_module_name,
54
+ KalibroClient::Entities::Miscellaneous::Granularity::METHOD, &block)
55
+ end
56
+ end
57
+ end
58
+
59
+ def parse_entries(entries, base_module_name, granularity=nil)
60
+ # It's possible for multiple methods to be declared with the same name,
61
+ # even though they'll never be assigned to the same slots at runtime, such
62
+ # as when declaring properties in classes.
63
+ # Radon will produce the same name in those cases, so deal with them by
64
+ # appending the line number to any methods with the same module name
65
+ entries.group_by { |entry| entry['name'] }.each do |name, module_entries|
66
+ if module_entries.size == 1
67
+ module_name = "#{base_module_name}.#{name}"
68
+ yield module_name, module_entries.first, granularity
69
+ else
70
+ module_entries.each do |entry|
71
+ module_name = "#{base_module_name}.#{name}:#{entry['lineno']}"
72
+ yield module_name, entry, granularity
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ def has_error?(file_name, results)
79
+ if results.is_a?(Array)
80
+ false
81
+ else
82
+ error = results['error'] if results.is_a?(Hash)
83
+ error ||= 'Unknown error'
84
+
85
+ # This debug print has been kept in order that if there is some non-fatal error it does not get ignored
86
+ logger.debug("error parsing file #{file_name}: #{error}")
87
+
88
+ true
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,15 @@
1
+ module Kolekti
2
+ module Radon
3
+ module Parser
4
+ class Maintainability < Base
5
+ def self.default_value
6
+ 100.0
7
+ end
8
+
9
+ def command
10
+ 'mi'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Kolekti
2
+ module Radon
3
+ module Parser
4
+ class Raw < Base
5
+ def self.default_value
6
+ 0.0
7
+ end
8
+
9
+ def command
10
+ 'raw'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Kolekti
2
+ module Radon
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kolekti_radon
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Diego Araújo
8
+ - Daniel Miranda
9
+ - Rafael Reggiani Manzo
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2018-03-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.11'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: cucumber
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.1'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.1'
71
+ - !ruby/object:Gem::Dependency
72
+ name: simplecov
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: codeclimate-test-reporter
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "<"
90
+ - !ruby/object:Gem::Version
91
+ version: 1.0.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: 1.0.0
99
+ - !ruby/object:Gem::Dependency
100
+ name: factory_girl
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: byebug
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: kolekti
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ description:
142
+ email:
143
+ - diegoamc@protonmail.ch
144
+ - danielkza2@gmail.com
145
+ - rr.manzo@protonmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".config/cucumber.yml"
151
+ - ".gitignore"
152
+ - ".rspec"
153
+ - ".ruby-gemset"
154
+ - ".ruby-version"
155
+ - ".travis.yml"
156
+ - CHANGELOG.md
157
+ - COPYING
158
+ - COPYING.LESSER
159
+ - Gemfile
160
+ - README.md
161
+ - Rakefile
162
+ - bin/console
163
+ - bin/setup
164
+ - gem_tasks/cucumber.rake
165
+ - kolekti_radon.gemspec
166
+ - lib/kolekti/radon.rb
167
+ - lib/kolekti/radon/collector.rb
168
+ - lib/kolekti/radon/metrics.yml
169
+ - lib/kolekti/radon/parser.rb
170
+ - lib/kolekti/radon/parser/base.rb
171
+ - lib/kolekti/radon/parser/cyclomatic.rb
172
+ - lib/kolekti/radon/parser/maintainability.rb
173
+ - lib/kolekti/radon/parser/raw.rb
174
+ - lib/kolekti/radon/version.rb
175
+ homepage: https://gitlab.com/mezuro/mezuro/tree/master/kalibro/kolekti_radon.git
176
+ licenses: []
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.11
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Metric collecting support for Python that serves Kolekti.
198
+ test_files: []