rubycritic 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubycritic.rb +3 -22
  3. data/lib/rubycritic/adapters/complexity/flog.rb +1 -1
  4. data/lib/rubycritic/adapters/smell/flay.rb +1 -1
  5. data/lib/rubycritic/adapters/smell/flog.rb +1 -1
  6. data/lib/rubycritic/adapters/smell/reek.rb +1 -1
  7. data/lib/rubycritic/analysed_files_builder.rb +36 -0
  8. data/lib/rubycritic/analysers/config.reek +6 -2
  9. data/lib/rubycritic/analysers_runner.rb +2 -2
  10. data/lib/rubycritic/cli.rb +2 -1
  11. data/lib/rubycritic/core/analysed_file.rb +22 -0
  12. data/lib/rubycritic/{location.rb → core/location.rb} +0 -0
  13. data/lib/rubycritic/{smell.rb → core/smell.rb} +10 -4
  14. data/lib/rubycritic/orchestrators/base.rb +27 -0
  15. data/lib/rubycritic/orchestrators/main.rb +14 -0
  16. data/lib/rubycritic/orchestrators/mini.rb +14 -0
  17. data/lib/rubycritic/report_generators/assets/javascripts/application.js +2 -9
  18. data/lib/rubycritic/report_generators/base.rb +43 -0
  19. data/lib/rubycritic/report_generators/code_file.rb +40 -0
  20. data/lib/rubycritic/report_generators/code_index.rb +29 -0
  21. data/lib/rubycritic/report_generators/line.rb +29 -0
  22. data/lib/rubycritic/report_generators/overview.rb +26 -0
  23. data/lib/rubycritic/report_generators/smells_index.rb +25 -0
  24. data/lib/rubycritic/report_generators/templates/{file.html.erb → code_file.html.erb} +2 -2
  25. data/lib/rubycritic/report_generators/templates/code_index.html.erb +3 -3
  26. data/lib/rubycritic/report_generators/templates/smells_index.html.erb +1 -1
  27. data/lib/rubycritic/report_generators/view_helpers.rb +0 -4
  28. data/lib/rubycritic/reporters/main.rb +55 -0
  29. data/lib/rubycritic/reporters/mini.rb +26 -0
  30. data/lib/rubycritic/revision_comparator.rb +1 -1
  31. data/lib/rubycritic/source_locator.rb +4 -4
  32. data/lib/rubycritic/turbulence.rb +8 -18
  33. data/lib/rubycritic/version.rb +1 -1
  34. data/test/lib/rubycritic/{quality_adapters → adapters/complexity}/flog_test.rb +2 -2
  35. data/test/lib/rubycritic/{smell_adapters → adapters/smell}/flay_test.rb +2 -2
  36. data/test/lib/rubycritic/{smell_adapters → adapters/smell}/flog_test.rb +0 -0
  37. data/test/lib/rubycritic/{smell_adapters → adapters/smell}/reek_test.rb +0 -0
  38. data/test/lib/rubycritic/analysed_files_builder_test.rb +36 -0
  39. data/test/lib/rubycritic/analysers_runner_test.rb +2 -2
  40. data/test/lib/rubycritic/core/analysed_file_test.rb +51 -0
  41. data/test/lib/rubycritic/{location_test.rb → core/location_test.rb} +1 -1
  42. data/test/lib/rubycritic/core/smell_test.rb +80 -0
  43. data/test/lib/rubycritic/{smells_array_test.rb → core/smells_array_test.rb} +1 -1
  44. data/test/lib/rubycritic/smells_status_setter_test.rb +1 -1
  45. data/test/lib/rubycritic/turbulence_test.rb +9 -18
  46. data/test/samples/reek/not_smelly.rb +10 -1
  47. metadata +36 -26
  48. data/lib/rubycritic/report_generators/base_generator.rb +0 -41
  49. data/lib/rubycritic/report_generators/code_index_generator.rb +0 -32
  50. data/lib/rubycritic/report_generators/file_generator.rb +0 -41
  51. data/lib/rubycritic/report_generators/line_generator.rb +0 -27
  52. data/lib/rubycritic/report_generators/overview_generator.rb +0 -24
  53. data/lib/rubycritic/report_generators/reporter.rb +0 -67
  54. data/lib/rubycritic/report_generators/smells_index_generator.rb +0 -23
  55. data/test/lib/rubycritic/smell_test.rb +0 -71
@@ -1,5 +1,5 @@
1
1
  require "test_helper"
2
- require "rubycritic/smell"
2
+ require "rubycritic/core/smell"
3
3
 
4
4
  describe "Array of Smells" do
5
5
  it "is sortable" do
@@ -1,5 +1,5 @@
1
1
  require "test_helper"
2
- require "rubycritic/smell"
2
+ require "rubycritic/core/smell"
3
3
  require "rubycritic/smells_status_setter"
4
4
 
5
5
  describe Rubycritic::SmellsStatusSetter do
@@ -1,27 +1,18 @@
1
1
  require "test_helper"
2
2
  require "rubycritic/turbulence"
3
- require "rubycritic/source_control_systems/source_control_system"
3
+ require "ostruct"
4
4
 
5
5
  describe Rubycritic::Turbulence do
6
- before do
7
- @sample_path = "test/samples/flog/smelly.rb"
8
- @sample_paths = [@sample_path]
9
- @source_control_system = SourceControlSystemDouble.new
10
- end
11
-
12
6
  describe "#data" do
13
- it "returns an array of hashes containing the path, churn and complexity of each file" do
14
- data = Rubycritic::Turbulence.new(@sample_paths, @source_control_system).data
15
- data_instance = data.first
16
- data_instance[:name].must_equal @sample_path
17
- data_instance[:x].must_equal 1 # churn
18
- data_instance[:y].must_be_kind_of Numeric # complexity
7
+ it "returns json data that maps pathname, churn and complexity to name, x and y" do
8
+ files = [AnalysedFileDouble.new(:pathname => "./foo.rb", :churn => 1, :complexity => 2)]
9
+ turbulence_data = Rubycritic::Turbulence.new(files).data
10
+ instance_parsed_json = JSON.parse(turbulence_data).first
11
+ instance_parsed_json["name"].must_equal "./foo.rb"
12
+ instance_parsed_json["x"].must_equal 1
13
+ instance_parsed_json["y"].must_equal 2
19
14
  end
20
15
  end
21
16
  end
22
17
 
23
- class SourceControlSystemDouble < Rubycritic::SourceControlSystem
24
- def revisions_count(file)
25
- 1 # churn
26
- end
27
- end
18
+ class AnalysedFileDouble < OpenStruct; end
@@ -5,10 +5,19 @@ class Perfume
5
5
  oneVariable = oneParameter
6
6
  end
7
7
 
8
- def allowNestingIteratorsTwoLevelsDeep
8
+ def allow_nesting_iterators_two_levels_deep
9
9
  loop do
10
10
  loop do
11
11
  end
12
12
  end
13
13
  end
14
+
15
+ def method_with_too_many_statements
16
+ do_something
17
+ do_something
18
+ do_something
19
+ do_something
20
+ do_something
21
+ do_something
22
+ end
14
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Simoes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -145,6 +145,7 @@ files:
145
145
  - lib/rubycritic/adapters/smell/flay.rb
146
146
  - lib/rubycritic/adapters/smell/flog.rb
147
147
  - lib/rubycritic/adapters/smell/reek.rb
148
+ - lib/rubycritic/analysed_files_builder.rb
148
149
  - lib/rubycritic/analysers/churn.rb
149
150
  - lib/rubycritic/analysers/config.reek
150
151
  - lib/rubycritic/analysers/flay.rb
@@ -153,7 +154,12 @@ files:
153
154
  - lib/rubycritic/analysers_runner.rb
154
155
  - lib/rubycritic/cli.rb
155
156
  - lib/rubycritic/configuration.rb
156
- - lib/rubycritic/location.rb
157
+ - lib/rubycritic/core/analysed_file.rb
158
+ - lib/rubycritic/core/location.rb
159
+ - lib/rubycritic/core/smell.rb
160
+ - lib/rubycritic/orchestrators/base.rb
161
+ - lib/rubycritic/orchestrators/main.rb
162
+ - lib/rubycritic/orchestrators/mini.rb
157
163
  - lib/rubycritic/report_generators/assets/javascripts/application.js
158
164
  - lib/rubycritic/report_generators/assets/javascripts/highcharts.src-4.0.1.js
159
165
  - lib/rubycritic/report_generators/assets/javascripts/jquery-2.1.0.js
@@ -162,23 +168,23 @@ files:
162
168
  - lib/rubycritic/report_generators/assets/javascripts/prettify-4-Mar-2013.js
163
169
  - lib/rubycritic/report_generators/assets/stylesheets/application.css
164
170
  - lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css
165
- - lib/rubycritic/report_generators/base_generator.rb
166
- - lib/rubycritic/report_generators/code_index_generator.rb
167
- - lib/rubycritic/report_generators/file_generator.rb
168
- - lib/rubycritic/report_generators/line_generator.rb
169
- - lib/rubycritic/report_generators/overview_generator.rb
170
- - lib/rubycritic/report_generators/reporter.rb
171
- - lib/rubycritic/report_generators/smells_index_generator.rb
171
+ - lib/rubycritic/report_generators/base.rb
172
+ - lib/rubycritic/report_generators/code_file.rb
173
+ - lib/rubycritic/report_generators/code_index.rb
174
+ - lib/rubycritic/report_generators/line.rb
175
+ - lib/rubycritic/report_generators/overview.rb
176
+ - lib/rubycritic/report_generators/smells_index.rb
177
+ - lib/rubycritic/report_generators/templates/code_file.html.erb
172
178
  - lib/rubycritic/report_generators/templates/code_index.html.erb
173
- - lib/rubycritic/report_generators/templates/file.html.erb
174
179
  - lib/rubycritic/report_generators/templates/layouts/application.html.erb
175
180
  - lib/rubycritic/report_generators/templates/line.html.erb
176
181
  - lib/rubycritic/report_generators/templates/overview.html.erb
177
182
  - lib/rubycritic/report_generators/templates/smells_index.html.erb
178
183
  - lib/rubycritic/report_generators/templates/smelly_line.html.erb
179
184
  - lib/rubycritic/report_generators/view_helpers.rb
185
+ - lib/rubycritic/reporters/main.rb
186
+ - lib/rubycritic/reporters/mini.rb
180
187
  - lib/rubycritic/revision_comparator.rb
181
- - lib/rubycritic/smell.rb
182
188
  - lib/rubycritic/smells_serializer.rb
183
189
  - lib/rubycritic/smells_status_setter.rb
184
190
  - lib/rubycritic/source_control_systems/git.rb
@@ -187,16 +193,18 @@ files:
187
193
  - lib/rubycritic/turbulence.rb
188
194
  - lib/rubycritic/version.rb
189
195
  - rubycritic.gemspec
196
+ - test/lib/rubycritic/adapters/complexity/flog_test.rb
197
+ - test/lib/rubycritic/adapters/smell/flay_test.rb
198
+ - test/lib/rubycritic/adapters/smell/flog_test.rb
199
+ - test/lib/rubycritic/adapters/smell/reek_test.rb
200
+ - test/lib/rubycritic/analysed_files_builder_test.rb
190
201
  - test/lib/rubycritic/analysers/churn_test.rb
191
202
  - test/lib/rubycritic/analysers_runner_test.rb
192
203
  - test/lib/rubycritic/configuration_test.rb
193
- - test/lib/rubycritic/location_test.rb
194
- - test/lib/rubycritic/quality_adapters/flog_test.rb
195
- - test/lib/rubycritic/smell_adapters/flay_test.rb
196
- - test/lib/rubycritic/smell_adapters/flog_test.rb
197
- - test/lib/rubycritic/smell_adapters/reek_test.rb
198
- - test/lib/rubycritic/smell_test.rb
199
- - test/lib/rubycritic/smells_array_test.rb
204
+ - test/lib/rubycritic/core/analysed_file_test.rb
205
+ - test/lib/rubycritic/core/location_test.rb
206
+ - test/lib/rubycritic/core/smell_test.rb
207
+ - test/lib/rubycritic/core/smells_array_test.rb
200
208
  - test/lib/rubycritic/smells_status_setter_test.rb
201
209
  - test/lib/rubycritic/source_control_systems/source_control_system_test.rb
202
210
  - test/lib/rubycritic/source_locator_test.rb
@@ -238,16 +246,18 @@ signing_key:
238
246
  specification_version: 4
239
247
  summary: Ruby code smell detector
240
248
  test_files:
249
+ - test/lib/rubycritic/adapters/complexity/flog_test.rb
250
+ - test/lib/rubycritic/adapters/smell/flay_test.rb
251
+ - test/lib/rubycritic/adapters/smell/flog_test.rb
252
+ - test/lib/rubycritic/adapters/smell/reek_test.rb
253
+ - test/lib/rubycritic/analysed_files_builder_test.rb
241
254
  - test/lib/rubycritic/analysers/churn_test.rb
242
255
  - test/lib/rubycritic/analysers_runner_test.rb
243
256
  - test/lib/rubycritic/configuration_test.rb
244
- - test/lib/rubycritic/location_test.rb
245
- - test/lib/rubycritic/quality_adapters/flog_test.rb
246
- - test/lib/rubycritic/smell_adapters/flay_test.rb
247
- - test/lib/rubycritic/smell_adapters/flog_test.rb
248
- - test/lib/rubycritic/smell_adapters/reek_test.rb
249
- - test/lib/rubycritic/smell_test.rb
250
- - test/lib/rubycritic/smells_array_test.rb
257
+ - test/lib/rubycritic/core/analysed_file_test.rb
258
+ - test/lib/rubycritic/core/location_test.rb
259
+ - test/lib/rubycritic/core/smell_test.rb
260
+ - test/lib/rubycritic/core/smells_array_test.rb
251
261
  - test/lib/rubycritic/smells_status_setter_test.rb
252
262
  - test/lib/rubycritic/source_control_systems/source_control_system_test.rb
253
263
  - test/lib/rubycritic/source_locator_test.rb
@@ -1,41 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/view_helpers"
3
-
4
- module Rubycritic
5
-
6
- class BaseGenerator
7
- def self.erb_template(template_path)
8
- ERB.new(File.read(File.join(TEMPLATES_DIR, template_path)))
9
- end
10
-
11
- TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
12
- LAYOUT_TEMPLATE = erb_template(File.join("layouts", "application.html.erb"))
13
-
14
- include ViewHelpers
15
-
16
- def file_href
17
- "file://#{file_pathname}"
18
- end
19
-
20
- def file_pathname
21
- File.join(file_directory, file_name)
22
- end
23
-
24
- def file_directory
25
- root_directory
26
- end
27
-
28
- def file_name
29
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
30
- end
31
-
32
- def render
33
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
34
- end
35
-
36
- def get_binding
37
- binding
38
- end
39
- end
40
-
41
- end
@@ -1,32 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/base_generator"
3
-
4
- module Rubycritic
5
-
6
- class CodeIndexGenerator < BaseGenerator
7
- TEMPLATE = erb_template("code_index.html.erb")
8
-
9
- def initialize(source_pathnames, smelly_pathnames)
10
- @source_pathnames = source_pathnames
11
- @smelly_pathnames = smelly_pathnames
12
- end
13
-
14
- def file_name
15
- "code_index.html"
16
- end
17
-
18
- def render
19
- index_body = TEMPLATE.result(get_binding)
20
- LAYOUT_TEMPLATE.result(get_binding { index_body })
21
- end
22
-
23
- def file_path(path)
24
- File.join(root_directory, path.sub_ext(".html"))
25
- end
26
-
27
- def smells_count(pathname)
28
- (@smelly_pathnames[pathname] || []).length
29
- end
30
- end
31
-
32
- end
@@ -1,41 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/base_generator"
3
- require "rubycritic/report_generators/line_generator"
4
-
5
- module Rubycritic
6
-
7
- class FileGenerator < BaseGenerator
8
- LINE_NUMBER_OFFSET = 1
9
- TEMPLATE = erb_template("file.html.erb")
10
-
11
- def initialize(pathname, smells)
12
- @pathname = pathname
13
- @smells = smells
14
- end
15
-
16
- def file_directory
17
- File.join(root_directory, @pathname.dirname)
18
- end
19
-
20
- def file_name
21
- @pathname.basename.sub_ext(".html")
22
- end
23
-
24
- def render
25
- file_code = ""
26
- File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
27
- location = Location.new(@pathname, line_number)
28
- line_smells = @smells.select { |smell| smell.located_in?(location) }
29
- file_code << LineGenerator.new(line_text, line_smells).render
30
- end
31
-
32
- file_body = TEMPLATE.result(get_binding { file_code })
33
- LAYOUT_TEMPLATE.result(get_binding { file_body })
34
- end
35
-
36
- def file_has_smells?
37
- !@smells.empty?
38
- end
39
- end
40
-
41
- end
@@ -1,27 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/base_generator"
3
- require "cgi"
4
-
5
- module Rubycritic
6
-
7
- class LineGenerator < BaseGenerator
8
- NORMAL_TEMPLATE = erb_template("line.html.erb")
9
- SMELLY_TEMPLATE = erb_template("smelly_line.html.erb")
10
-
11
- def initialize(text, smells)
12
- @text = CGI::escapeHTML(text.chomp)
13
- @smells = smells
14
- @template =
15
- if @smells.empty?
16
- NORMAL_TEMPLATE
17
- else
18
- SMELLY_TEMPLATE
19
- end
20
- end
21
-
22
- def render
23
- @template.result(binding).delete("\n") + "\n"
24
- end
25
- end
26
-
27
- end
@@ -1,24 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/base_generator"
3
- require "json"
4
-
5
- module Rubycritic
6
-
7
- class OverviewGenerator < BaseGenerator
8
- TEMPLATE = erb_template("overview.html.erb")
9
-
10
- def initialize(turbulence_data)
11
- @turbulence_data = turbulence_data.to_json
12
- end
13
-
14
- def file_name
15
- "overview.html"
16
- end
17
-
18
- def render
19
- index_body = TEMPLATE.result(get_binding)
20
- LAYOUT_TEMPLATE.result(get_binding { index_body })
21
- end
22
- end
23
-
24
- end
@@ -1,67 +0,0 @@
1
- require "rubycritic/report_generators/base_generator"
2
- require "rubycritic/report_generators/file_generator"
3
- require "rubycritic/report_generators/overview_generator"
4
- require "rubycritic/report_generators/code_index_generator"
5
- require "rubycritic/report_generators/smells_index_generator"
6
- require "fileutils"
7
-
8
- module Rubycritic
9
-
10
- class Reporter
11
- ASSETS_DIR = File.expand_path("../assets", __FILE__)
12
-
13
- def initialize(source_pathnames, smells, turbulence_data)
14
- @source_pathnames = source_pathnames
15
- @smells = smells
16
- @turbulence_data = turbulence_data
17
- @smelly_pathnames = pathnames_to_files_with_smells
18
- end
19
-
20
- def generate_report
21
- generators.each do |generator|
22
- FileUtils.mkdir_p(generator.file_directory)
23
- File.open(generator.file_pathname, "w+") do |file|
24
- file.write(generator.render)
25
- end
26
- end
27
- FileUtils.cp_r(ASSETS_DIR, ::Rubycritic.configuration.root)
28
- overview_generator.file_href
29
- end
30
-
31
- private
32
-
33
- def generators
34
- [overview_generator, code_index_generator, smells_index_generator] + file_generators
35
- end
36
-
37
- def overview_generator
38
- @overview_generator ||= OverviewGenerator.new(@turbulence_data)
39
- end
40
-
41
- def code_index_generator
42
- @code_index_generator ||= CodeIndexGenerator.new(@source_pathnames, @smelly_pathnames)
43
- end
44
-
45
- def smells_index_generator
46
- @smells_index_generator ||= SmellsIndexGenerator.new(@smells)
47
- end
48
-
49
- def file_generators
50
- @file_generators ||= @source_pathnames.map do |file_pathname|
51
- file_smells = @smelly_pathnames[file_pathname]
52
- FileGenerator.new(file_pathname, file_smells)
53
- end
54
- end
55
-
56
- def pathnames_to_files_with_smells
57
- pathnames = Hash.new { |hash, key| hash[key] = [] }
58
- @smells.each do |smell|
59
- smell.pathnames.each do |pathname|
60
- pathnames[pathname] << smell
61
- end
62
- end
63
- pathnames
64
- end
65
- end
66
-
67
- end
@@ -1,23 +0,0 @@
1
- require "erb"
2
- require "rubycritic/report_generators/base_generator"
3
-
4
- module Rubycritic
5
-
6
- class SmellsIndexGenerator < BaseGenerator
7
- TEMPLATE = erb_template("smells_index.html.erb")
8
-
9
- def initialize(smells)
10
- @smells = smells.sort { |a, b| a.type <=> b.type }
11
- end
12
-
13
- def file_name
14
- "smells_index.html"
15
- end
16
-
17
- def render
18
- index_body = TEMPLATE.result(get_binding)
19
- LAYOUT_TEMPLATE.result(get_binding { index_body })
20
- end
21
- end
22
-
23
- end