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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4ffd32168812c62fcc6df57e4be70945ec2f596
4
- data.tar.gz: a6255f8b72f25cf2c73e9f20a9738543c24cf9f4
3
+ metadata.gz: b4f79955ca6f3dab8dccacc5dca7c2b994db9cc7
4
+ data.tar.gz: 51bb696eca3c5caa072c1e20a0fb67c1d18c113f
5
5
  SHA512:
6
- metadata.gz: 3e0a4d3522db7f8a2565a003928b8cf6dd1a50ec0b8ed4f9680b6ff40723e7d80a4d54d339bae4bd938b35373dae375555c7936ff400913302599aec4aadae2c
7
- data.tar.gz: 973ed3d59c5f67032df4f5a35379692f1d9b07abf2f8fe84379df9a40f1b1f574d480150f9c0999aaff7a6b3db430ff0df54a6bb3b5b3b367f958675c990c283
6
+ metadata.gz: 0794412b39af6196e6d9e70ab55c634744778acf6a9102538ea34a2bbf0aa509fb2f4569437203eb53e0dc770dd73db7095ae2238323e9a10fff1520e30dfb50
7
+ data.tar.gz: f93087c069037601daa5f19c21d5794d8b176dbcc81b291b8a3f46f5d14a091bce4d75c0dd2d0e9b73cc7d0f4c5aa1568ec93ef7f33a91f2d3839010aeee60f6
data/lib/rubycritic.rb CHANGED
@@ -3,25 +3,6 @@ require "rubycritic/source_locator"
3
3
  require "rubycritic/analysers_runner"
4
4
  require "rubycritic/source_control_systems/source_control_system"
5
5
  require "rubycritic/revision_comparator"
6
- require "rubycritic/turbulence"
7
- require "rubycritic/report_generators/reporter"
8
-
9
- module Rubycritic
10
-
11
- class Rubycritic
12
- def initialize
13
- @source_control_system = SourceControlSystem.create
14
- end
15
-
16
- def critique(paths)
17
- source = SourceLocator.new(paths)
18
- smells = AnalysersRunner.new(source.paths).run
19
- if @source_control_system.has_revision?
20
- smells = RevisionComparator.new(smells, @source_control_system).smells
21
- turbulence_data = Turbulence.new(source.paths, @source_control_system).data
22
- end
23
- Reporter.new(source.pathnames, smells, turbulence_data).generate_report
24
- end
25
- end
26
-
27
- end
6
+ require "rubycritic/analysers/churn"
7
+ require "rubycritic/adapters/complexity/flog"
8
+ require "rubycritic/analysed_files_builder"
@@ -1,5 +1,5 @@
1
1
  module Rubycritic
2
- module QualityAdapter
2
+ module ComplexityAdapter
3
3
 
4
4
  class Flog
5
5
  def initialize(paths)
@@ -1,5 +1,5 @@
1
1
  require "rubycritic/analysers/flay"
2
- require "rubycritic/smell"
2
+ require "rubycritic/core/smell"
3
3
 
4
4
  module Rubycritic
5
5
  module SmellAdapter
@@ -1,5 +1,5 @@
1
1
  require "rubycritic/analysers/flog"
2
- require "rubycritic/smell"
2
+ require "rubycritic/core/smell"
3
3
 
4
4
  module Rubycritic
5
5
  module SmellAdapter
@@ -1,5 +1,5 @@
1
1
  require "rubycritic/analysers/reek"
2
- require "rubycritic/smell"
2
+ require "rubycritic/core/smell"
3
3
 
4
4
  module Rubycritic
5
5
  module SmellAdapter
@@ -0,0 +1,36 @@
1
+ require "rubycritic/core/analysed_file"
2
+
3
+ module Rubycritic
4
+
5
+ class AnalysedFilesBuilder
6
+ def initialize(pathnames, smells, churn, complexity)
7
+ @pathnames = pathnames
8
+ @smells = smells
9
+ @churn = churn
10
+ @complexity = complexity
11
+ end
12
+
13
+ def analysed_files
14
+ @pathnames.zip(@churn, @complexity).map do |file_attributes|
15
+ pathname = file_attributes[0]
16
+ AnalysedFile.new(
17
+ :smells => file_smells(pathname),
18
+ :pathname => pathname,
19
+ :churn => file_attributes[1],
20
+ :complexity => file_attributes[2]
21
+ )
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def file_smells(pathname)
28
+ file_smells = []
29
+ @smells.each do |smell|
30
+ file_smells << smell if smell.at_pathname?(pathname)
31
+ end
32
+ file_smells
33
+ end
34
+ end
35
+
36
+ end
@@ -3,6 +3,10 @@ Attribute:
3
3
  enabled: false
4
4
  IrresponsibleModule:
5
5
  enabled: false
6
+ NestedIterators:
7
+ max_allowed_nesting: 2
8
+ TooManyStatements:
9
+ enabled: false
6
10
  UncommunicativeMethodName:
7
11
  reject:
8
12
  - !ruby/regexp /^[a-z]$/
@@ -16,5 +20,5 @@ UncommunicativeVariableName:
16
20
  reject:
17
21
  - !ruby/regexp /^.$/
18
22
  - !ruby/regexp /[0-9]$/
19
- NestedIterators:
20
- max_allowed_nesting: 2
23
+ UtilityFunction:
24
+ enabled: false
@@ -14,7 +14,7 @@ module Rubycritic
14
14
  @paths = paths
15
15
  end
16
16
 
17
- def run
17
+ def smells
18
18
  aggregate_smells(smell_adapters)
19
19
  end
20
20
 
@@ -27,7 +27,7 @@ module Rubycritic
27
27
  end
28
28
 
29
29
  def aggregate_smells(smell_adapters)
30
- smell_adapters.map(&:smells).flatten.sort
30
+ smell_adapters.flat_map(&:smells).sort
31
31
  end
32
32
  end
33
33
 
@@ -1,5 +1,6 @@
1
1
  require "optparse"
2
2
  require "rubycritic"
3
+ require "rubycritic/orchestrators/main"
3
4
 
4
5
  module Rubycritic
5
6
 
@@ -23,7 +24,7 @@ module Rubycritic
23
24
  end.parse!
24
25
 
25
26
  ARGV << "." if ARGV.empty?
26
- puts "New critique at #{Rubycritic.new.critique(ARGV)}"
27
+ puts "New critique at #{Orchestrator::Main.new.critique(ARGV)}"
27
28
  exit 0
28
29
 
29
30
  end
@@ -0,0 +1,22 @@
1
+ require "virtus"
2
+
3
+ module Rubycritic
4
+
5
+ class AnalysedFile
6
+ include Virtus.model
7
+
8
+ attribute :pathname
9
+ attribute :smells
10
+ attribute :churn
11
+ attribute :complexity
12
+
13
+ def name
14
+ pathname.basename.sub_ext("").to_s
15
+ end
16
+
17
+ def has_smells?
18
+ !smells.empty?
19
+ end
20
+ end
21
+
22
+ end
File without changes
@@ -1,5 +1,5 @@
1
1
  require "virtus"
2
- require "rubycritic/location"
2
+ require "rubycritic/core/location"
3
3
 
4
4
  module Rubycritic
5
5
 
@@ -13,11 +13,11 @@ module Rubycritic
13
13
  attribute :type
14
14
  attribute :status
15
15
 
16
- def pathnames
17
- @pathnames ||= locations.map(&:pathname).uniq
16
+ def at_pathname?(other_pathname)
17
+ pathnames.any? { |pathname| pathname == other_pathname }
18
18
  end
19
19
 
20
- def located_in?(other_location)
20
+ def at_location?(other_location)
21
21
  locations.any? { |location| location == other_location }
22
22
  end
23
23
 
@@ -47,6 +47,12 @@ module Rubycritic
47
47
  def state
48
48
  [@context, @message, @score, @type]
49
49
  end
50
+
51
+ private
52
+
53
+ def pathnames
54
+ @pathnames ||= locations.map(&:pathname).uniq
55
+ end
50
56
  end
51
57
 
52
58
  end
@@ -0,0 +1,27 @@
1
+ module Rubycritic
2
+ module Orchestrator
3
+
4
+ class Base
5
+ def initialize
6
+ @source_control_system = SourceControlSystem.create
7
+ end
8
+
9
+ def critique(paths)
10
+ source = SourceLocator.new(paths)
11
+ @smells = AnalysersRunner.new(source.paths).smells
12
+ if @source_control_system.has_revision?
13
+ @smells = RevisionComparator.new(@smells, @source_control_system).smells
14
+ churn = Analyser::Churn.new(source.paths, @source_control_system).churn
15
+ end
16
+ complexity = ComplexityAdapter::Flog.new(source.paths).complexity
17
+ @analysed_files = AnalysedFilesBuilder.new(source.pathnames, @smells, churn, complexity).analysed_files
18
+ generate_report
19
+ end
20
+
21
+ def generate_report
22
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require "rubycritic/orchestrators/base"
2
+ require "rubycritic/reporters/main"
3
+
4
+ module Rubycritic
5
+ module Orchestrator
6
+
7
+ class Main < Base
8
+ def generate_report
9
+ Reporter::Main.new(@analysed_files, @smells).generate_report
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require "rubycritic/orchestrators/base"
2
+ require "rubycritic/reporters/mini"
3
+
4
+ module Rubycritic
5
+ module Orchestrator
6
+
7
+ class Mini < Base
8
+ def generate_report
9
+ Reporter::Mini.new(@analysed_files.first).generate_report
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -86,13 +86,6 @@ $("#js-chart-container").highcharts({
86
86
  }
87
87
  }
88
88
  },
89
- states: {
90
- hover: {
91
- marker: {
92
- enabled: false
93
- }
94
- }
95
- },
96
89
  tooltip: {
97
90
  headerFormat: "<b>{point.key}</b><br>",
98
91
  pointFormat: "Committed {point.x} times, with Flog score of {point.y}"
@@ -100,8 +93,8 @@ $("#js-chart-container").highcharts({
100
93
  }
101
94
  },
102
95
  series: [{
96
+ showInLegend: false,
103
97
  color: "steelblue",
104
- data: turbulence_data,
105
- showInLegend: false
98
+ data: turbulence_data
106
99
  }]
107
100
  });
@@ -0,0 +1,43 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/view_helpers"
3
+
4
+ module Rubycritic
5
+ module Generator
6
+
7
+ class Base
8
+ def self.erb_template(template_path)
9
+ ERB.new(File.read(File.join(TEMPLATES_DIR, template_path)))
10
+ end
11
+
12
+ TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
13
+ LAYOUT_TEMPLATE = erb_template(File.join("layouts", "application.html.erb"))
14
+
15
+ include ViewHelpers
16
+
17
+ def file_href
18
+ "file://#{file_pathname}"
19
+ end
20
+
21
+ def file_pathname
22
+ File.join(file_directory, file_name)
23
+ end
24
+
25
+ def file_directory
26
+ root_directory
27
+ end
28
+
29
+ def file_name
30
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
31
+ end
32
+
33
+ def render
34
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
35
+ end
36
+
37
+ def get_binding
38
+ binding
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base"
3
+ require "rubycritic/report_generators/line"
4
+
5
+ module Rubycritic
6
+ module Generator
7
+
8
+ class CodeFile < Base
9
+ LINE_NUMBER_OFFSET = 1
10
+ TEMPLATE = erb_template("code_file.html.erb")
11
+
12
+ def initialize(analysed_file)
13
+ @analysed_file = analysed_file
14
+ @pathname = @analysed_file.pathname
15
+ @smells = @analysed_file.smells
16
+ end
17
+
18
+ def file_directory
19
+ File.join(root_directory, @pathname.dirname)
20
+ end
21
+
22
+ def file_name
23
+ @pathname.basename.sub_ext(".html")
24
+ end
25
+
26
+ def render
27
+ file_code = ""
28
+ File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
29
+ location = Location.new(@pathname, line_number)
30
+ line_smells = @smells.select { |smell| smell.at_location?(location) }
31
+ file_code << Line.new(line_text, line_smells).render
32
+ end
33
+
34
+ file_body = TEMPLATE.result(get_binding { file_code })
35
+ LAYOUT_TEMPLATE.result(get_binding { file_body })
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base"
3
+
4
+ module Rubycritic
5
+ module Generator
6
+
7
+ class CodeIndex < Base
8
+ TEMPLATE = erb_template("code_index.html.erb")
9
+
10
+ def initialize(analysed_files)
11
+ @analysed_files = analysed_files
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(pathname)
24
+ File.join(root_directory, pathname.sub_ext(".html"))
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base"
3
+ require "cgi"
4
+
5
+ module Rubycritic
6
+ module Generator
7
+
8
+ class Line < Base
9
+ NORMAL_TEMPLATE = erb_template("line.html.erb")
10
+ SMELLY_TEMPLATE = erb_template("smelly_line.html.erb")
11
+
12
+ def initialize(text, smells)
13
+ @text = CGI::escapeHTML(text.chomp)
14
+ @smells = smells
15
+ @template =
16
+ if @smells.empty?
17
+ NORMAL_TEMPLATE
18
+ else
19
+ SMELLY_TEMPLATE
20
+ end
21
+ end
22
+
23
+ def render
24
+ @template.result(binding).delete("\n") + "\n"
25
+ end
26
+ end
27
+
28
+ end
29
+ end