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
@@ -0,0 +1,26 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base"
3
+ require "rubycritic/turbulence"
4
+
5
+ module Rubycritic
6
+ module Generator
7
+
8
+ class Overview < Base
9
+ TEMPLATE = erb_template("overview.html.erb")
10
+
11
+ def initialize(analysed_files)
12
+ @turbulence_data = Turbulence.new(analysed_files).data
13
+ end
14
+
15
+ def file_name
16
+ "overview.html"
17
+ end
18
+
19
+ def render
20
+ index_body = TEMPLATE.result(get_binding)
21
+ LAYOUT_TEMPLATE.result(get_binding { index_body })
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base"
3
+
4
+ module Rubycritic
5
+ module Generator
6
+
7
+ class SmellsIndex < Base
8
+ TEMPLATE = erb_template("smells_index.html.erb")
9
+
10
+ def initialize(smells)
11
+ @smells = smells
12
+ end
13
+
14
+ def file_name
15
+ "smells_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
+ end
23
+
24
+ end
25
+ end
@@ -1,7 +1,7 @@
1
1
  <div class="file-header">
2
- <h2 class="file-name"><%= analysed_file_name(@pathname) %></h2>
2
+ <h2 class="file-name"><%= @analysed_file.name %></h2>
3
3
 
4
- <% if file_has_smells? %>
4
+ <% if @analysed_file.has_smells? %>
5
5
  <button id="js-toggle-smells" class="smells-toggle-button button">Toggle Smells</button>
6
6
  <% end %>
7
7
  </div>
@@ -6,12 +6,12 @@
6
6
  </tr>
7
7
  </thead>
8
8
  <tbody>
9
- <% @source_pathnames.each do |pathname| %>
9
+ <% @analysed_files.each do |analysed_file| %>
10
10
  <tr>
11
11
  <td class="first-cell">
12
- <a href="<%= file_path(pathname) %>"><%= analysed_file_name(pathname) %></a>
12
+ <a href="<%= file_path(analysed_file.pathname) %>"><%= analysed_file.name %></a>
13
13
  </td>
14
- <td><%= smells_count(pathname) %></td>
14
+ <td><%= analysed_file.smells.length %></td>
15
15
  </tr>
16
16
  <% end %>
17
17
  </tbody>
@@ -1,4 +1,4 @@
1
- <table class="analysis-index-table">
1
+ <table id="js-code-table" class="analysis-index-table sortable-table">
2
2
  <thead>
3
3
  <tr>
4
4
  <th class="first-cell">Smell</th>
@@ -33,10 +33,6 @@ module Rubycritic
33
33
  def root_directory
34
34
  ::Rubycritic.configuration.root
35
35
  end
36
-
37
- def analysed_file_name(pathname)
38
- pathname.basename.sub_ext("")
39
- end
40
36
  end
41
37
 
42
38
  end
@@ -0,0 +1,55 @@
1
+ require "rubycritic/report_generators/overview"
2
+ require "rubycritic/report_generators/smells_index"
3
+ require "rubycritic/report_generators/code_index"
4
+ require "rubycritic/report_generators/code_file"
5
+ require "fileutils"
6
+
7
+ module Rubycritic
8
+ module Reporter
9
+
10
+ class Main
11
+ ASSETS_DIR = File.expand_path("../../report_generators/assets", __FILE__)
12
+
13
+ def initialize(analysed_files, smells)
14
+ @analysed_files = analysed_files
15
+ @smells = smells
16
+ end
17
+
18
+ def generate_report
19
+ generators.each do |generator|
20
+ FileUtils.mkdir_p(generator.file_directory)
21
+ File.open(generator.file_pathname, "w+") do |file|
22
+ file.write(generator.render)
23
+ end
24
+ end
25
+ FileUtils.cp_r(ASSETS_DIR, ::Rubycritic.configuration.root)
26
+ overview_generator.file_href
27
+ end
28
+
29
+ private
30
+
31
+ def generators
32
+ [overview_generator, code_index_generator, smells_index_generator] + file_generators
33
+ end
34
+
35
+ def overview_generator
36
+ @overview_generator ||= Generator::Overview.new(@analysed_files)
37
+ end
38
+
39
+ def code_index_generator
40
+ Generator::CodeIndex.new(@analysed_files)
41
+ end
42
+
43
+ def smells_index_generator
44
+ Generator::SmellsIndex.new(@smells)
45
+ end
46
+
47
+ def file_generators
48
+ @analysed_files.map do |analysed_file|
49
+ Generator::CodeFile.new(analysed_file)
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ require "rubycritic/report_generators/code_file"
2
+ require "fileutils"
3
+
4
+ module Rubycritic
5
+ module Reporter
6
+
7
+ class Mini
8
+ ASSETS_DIR = File.expand_path("../../report_generators/assets", __FILE__)
9
+
10
+ def initialize(analysed_file)
11
+ @analysed_file = analysed_file
12
+ end
13
+
14
+ def generate_report
15
+ file_generator = Generator::CodeFile.new(@analysed_file)
16
+ FileUtils.mkdir_p(file_generator.file_directory)
17
+ File.open(file_generator.file_pathname, "w+") do |file|
18
+ file.write(file_generator.render)
19
+ end
20
+ FileUtils.cp_r(ASSETS_DIR, ::Rubycritic.configuration.root)
21
+ file_generator.file_href
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -26,7 +26,7 @@ module Rubycritic
26
26
  else
27
27
  smells = nil
28
28
  @source_control_system.travel_to_head do
29
- smells = AnalysersRunner.new(paths_of_tracked_files).run
29
+ smells = AnalysersRunner.new(paths_of_tracked_files).smells
30
30
  end
31
31
  serializer.dump(smells)
32
32
  smells
@@ -10,14 +10,14 @@ module Rubycritic
10
10
  @initial_paths = paths
11
11
  end
12
12
 
13
- def pathnames
14
- @pathnames ||= expand_paths
15
- end
16
-
17
13
  def paths
18
14
  @paths ||= pathnames.map(&:to_s)
19
15
  end
20
16
 
17
+ def pathnames
18
+ @pathnames ||= expand_paths
19
+ end
20
+
21
21
  private
22
22
 
23
23
  def expand_paths
@@ -1,30 +1,20 @@
1
- require "rubycritic/analysers/churn"
2
- require "rubycritic/adapters/complexity/flog"
1
+ require "json"
3
2
 
4
3
  module Rubycritic
5
4
 
6
5
  class Turbulence
7
- def initialize(paths, source_control_system)
8
- @paths = paths
9
- @source_control_system = source_control_system
6
+ def initialize(analysed_files)
7
+ @analysed_files = analysed_files
10
8
  end
11
9
 
12
10
  def data
13
- @paths.zip(churn, complexity).map do |path_info|
11
+ @analysed_files.map do |analysed_file|
14
12
  {
15
- :name => path_info[0],
16
- :x => path_info[1],
17
- :y => path_info[2]
13
+ :name => analysed_file.pathname,
14
+ :x => analysed_file.churn,
15
+ :y => analysed_file.complexity
18
16
  }
19
- end
20
- end
21
-
22
- def churn
23
- @churn ||= Analyser::Churn.new(@paths, @source_control_system).churn
24
- end
25
-
26
- def complexity
27
- @complexity ||= QualityAdapter::Flog.new(@paths).complexity
17
+ end.to_json
28
18
  end
29
19
  end
30
20
 
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -2,10 +2,10 @@ require "test_helper"
2
2
  require "rubycritic/analysers/flog"
3
3
  require "rubycritic/adapters/complexity/flog"
4
4
 
5
- describe Rubycritic::QualityAdapter::Flog do
5
+ describe Rubycritic::ComplexityAdapter::Flog do
6
6
  before do
7
7
  sample_paths = ["test/samples/flog/smelly.rb", "test/samples/flog/smelly2.rb"]
8
- @adapter = Rubycritic::QualityAdapter::Flog.new(sample_paths)
8
+ @adapter = Rubycritic::ComplexityAdapter::Flog.new(sample_paths)
9
9
  end
10
10
 
11
11
  describe "#complexity" do
@@ -13,10 +13,10 @@ describe Rubycritic::SmellAdapter::Flay do
13
13
 
14
14
  it "has smells with messages" do
15
15
  smell = @adapter.smells.first
16
- smell.message.must_equal "found in 2 nodes"
16
+ smell.message.must_be_instance_of String
17
17
  end
18
18
 
19
- it "has smells with messages" do
19
+ it "has smells with scores" do
20
20
  smell = @adapter.smells.first
21
21
  smell.score.must_be_kind_of Numeric
22
22
  end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+ require "rubycritic/analysed_files_builder"
3
+
4
+ describe Rubycritic::AnalysedFilesBuilder do
5
+ describe "analysed_files" do
6
+ before do
7
+ @pathnames = [Pathname.new("./foo"), Pathname.new("./bar")]
8
+ @smells = [SmellDouble.new]
9
+ @churn = [1, 2]
10
+ @complexity = [3, 4]
11
+ @builder = Rubycritic::AnalysedFilesBuilder.new(@pathnames, @smells, @churn, @complexity)
12
+ end
13
+
14
+ it "returns an array of AnalysedFiles" do
15
+ analysed_files = @builder.analysed_files
16
+ first = analysed_files.first
17
+ last = analysed_files.last
18
+
19
+ first.pathname.must_equal Pathname.new("./foo")
20
+ first.smells.must_equal @smells
21
+ first.churn.must_equal @churn.first
22
+ first.complexity.must_equal @complexity.first
23
+
24
+ last.pathname.must_equal Pathname.new("./bar")
25
+ last.smells.must_equal @smells
26
+ last.churn.must_equal @churn.last
27
+ last.complexity.must_equal @complexity.last
28
+ end
29
+ end
30
+ end
31
+
32
+ class SmellDouble
33
+ def at_pathname?(other_pathname)
34
+ true
35
+ end
36
+ end
@@ -2,9 +2,9 @@ require "test_helper"
2
2
  require "rubycritic/analysers_runner"
3
3
 
4
4
  describe Rubycritic::AnalysersRunner do
5
- describe "#run" do
5
+ describe "#smells" do
6
6
  it "returns the smells found by various analysers" do
7
- smells = Rubycritic::AnalysersRunner.new("test/samples/analysers_runner/empty.rb").run
7
+ smells = Rubycritic::AnalysersRunner.new("test/samples/analysers_runner/empty.rb").smells
8
8
  smells.must_be_instance_of Array
9
9
  end
10
10
  end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+ require "rubycritic/core/analysed_file"
3
+
4
+ describe Rubycritic::AnalysedFile do
5
+ describe "attribute readers" do
6
+ before do
7
+ @pathname = Pathname.new("./foo")
8
+ @smells = []
9
+ @churn = 1
10
+ @complexity = 2
11
+ @smell = Rubycritic::AnalysedFile.new(
12
+ :pathname => @pathname,
13
+ :smells => @smells,
14
+ :churn => @churn,
15
+ :complexity => @complexity
16
+ )
17
+ end
18
+
19
+ it "has a pathname reader" do
20
+ @smell.pathname.must_equal @pathname
21
+ end
22
+
23
+ it "has a smells reader" do
24
+ @smell.smells.must_equal @smells
25
+ end
26
+
27
+ it "has a churn reader" do
28
+ @smell.churn.must_equal @churn
29
+ end
30
+
31
+ it "has a complexity reader" do
32
+ @smell.complexity.must_equal @complexity
33
+ end
34
+ end
35
+
36
+ describe "#name" do
37
+ it "returns the name of the file" do
38
+ analysed_file = Rubycritic::AnalysedFile.new(:pathname => Pathname.new("foo/bar.rb"))
39
+ analysed_file.name.must_equal "bar"
40
+ end
41
+ end
42
+
43
+ describe "#has_smells?" do
44
+ it "returns true if the analysed_file has at least one smell" do
45
+ analysed_file = Rubycritic::AnalysedFile.new(:smells => [SmellDouble.new])
46
+ analysed_file.has_smells?.must_equal true
47
+ end
48
+ end
49
+ end
50
+
51
+ class SmellDouble; end
@@ -1,5 +1,5 @@
1
1
  require "test_helper"
2
- require "rubycritic/location"
2
+ require "rubycritic/core/location"
3
3
 
4
4
  describe Rubycritic::Location do
5
5
  describe "attribute readers" do
@@ -0,0 +1,80 @@
1
+ require "test_helper"
2
+ require "rubycritic/core/smell"
3
+
4
+ describe Rubycritic::Smell do
5
+ describe "attribute readers" do
6
+ before do
7
+ @locations = [Rubycritic::Location.new("./foo", "42")]
8
+ @context = "#bar"
9
+ @message = "This smells"
10
+ @score = 0
11
+ @type = :complexity
12
+ @smell = Rubycritic::Smell.new(
13
+ :locations => @locations,
14
+ :context => @context,
15
+ :message => @message,
16
+ :score => @score,
17
+ :type => @type
18
+ )
19
+ end
20
+
21
+ it "has a context reader" do
22
+ @smell.context.must_equal @context
23
+ end
24
+
25
+ it "has a locations reader" do
26
+ @smell.locations.must_equal @locations
27
+ end
28
+
29
+ it "has a message reader" do
30
+ @smell.message.must_equal @message
31
+ end
32
+
33
+ it "has a score reader" do
34
+ @smell.score.must_equal @score
35
+ end
36
+
37
+ it "has a type reader" do
38
+ @smell.type.must_equal @type
39
+ end
40
+ end
41
+
42
+ describe "#at_location?" do
43
+ it "returns true if the smell has a location that matches the location passed as argument" do
44
+ location = Rubycritic::Location.new("./foo", "42")
45
+ smell = Rubycritic::Smell.new(:locations => [location])
46
+ smell.at_location?(location).must_equal true
47
+ end
48
+ end
49
+
50
+ describe "#at_pathname?" do
51
+ it "returns true if the smell has a pathname that matches the pathname passed as argument" do
52
+ path = "./foo"
53
+ pathname = Pathname.new(path)
54
+ location = Rubycritic::Location.new(path, "42")
55
+ smell = Rubycritic::Smell.new(:locations => [location])
56
+ smell.at_pathname?(pathname).must_equal true
57
+ end
58
+ end
59
+
60
+ describe "#has_multiple_locations?" do
61
+ it "returns true if the smell has more than one location" do
62
+ location1 = Rubycritic::Location.new("./foo", "42")
63
+ location2 = Rubycritic::Location.new("./foo", "23")
64
+ smell = Rubycritic::Smell.new(:locations => [location1, location2])
65
+ smell.has_multiple_locations?.must_equal true
66
+ end
67
+ end
68
+
69
+ it "is comparable" do
70
+ attributes = {
71
+ :context => "#bar",
72
+ :message => "This smells",
73
+ :score => 0,
74
+ :type => :complexity
75
+ }
76
+ smell1 = Rubycritic::Smell.new(attributes)
77
+ smell2 = Rubycritic::Smell.new(attributes)
78
+ smell1.must_equal smell2
79
+ end
80
+ end