rubycritic 2.6.0 → 2.7.0

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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -585
  3. data/.rubocop_todo.yml +36 -0
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +1 -1
  6. data/Rakefile +9 -9
  7. data/bin/rubycritic +2 -2
  8. data/features/command_line_interface/options.feature +1 -0
  9. data/features/step_definitions/rubycritic_steps.rb +1 -1
  10. data/features/step_definitions/sample_file_steps.rb +3 -3
  11. data/features/support/env.rb +6 -6
  12. data/lib/rubycritic.rb +1 -1
  13. data/lib/rubycritic/analysers/attributes.rb +6 -7
  14. data/lib/rubycritic/analysers/churn.rb +4 -6
  15. data/lib/rubycritic/analysers/complexity.rb +5 -7
  16. data/lib/rubycritic/analysers/helpers/ast_node.rb +4 -6
  17. data/lib/rubycritic/analysers/helpers/flay.rb +1 -3
  18. data/lib/rubycritic/analysers/helpers/flog.rb +5 -7
  19. data/lib/rubycritic/analysers/helpers/methods_counter.rb +1 -3
  20. data/lib/rubycritic/analysers/helpers/modules_locator.rb +3 -5
  21. data/lib/rubycritic/analysers/helpers/parser.rb +2 -2
  22. data/lib/rubycritic/analysers/helpers/reek.rb +1 -1
  23. data/lib/rubycritic/analysers/smells/flay.rb +14 -16
  24. data/lib/rubycritic/analysers/smells/flog.rb +15 -17
  25. data/lib/rubycritic/analysers/smells/reek.rb +11 -13
  26. data/lib/rubycritic/analysers_runner.rb +8 -10
  27. data/lib/rubycritic/browser.rb +17 -0
  28. data/lib/rubycritic/cli/application.rb +3 -3
  29. data/lib/rubycritic/cli/options.rb +29 -23
  30. data/lib/rubycritic/command_factory.rb +5 -5
  31. data/lib/rubycritic/commands/base.rb +2 -2
  32. data/lib/rubycritic/commands/ci.rb +4 -4
  33. data/lib/rubycritic/commands/default.rb +5 -5
  34. data/lib/rubycritic/commands/help.rb +1 -1
  35. data/lib/rubycritic/commands/status_reporter.rb +1 -1
  36. data/lib/rubycritic/commands/version.rb +2 -2
  37. data/lib/rubycritic/configuration.rb +4 -2
  38. data/lib/rubycritic/core/analysed_module.rb +15 -17
  39. data/lib/rubycritic/core/analysed_modules_collection.rb +3 -3
  40. data/lib/rubycritic/core/location.rb +4 -6
  41. data/lib/rubycritic/core/rating.rb +5 -7
  42. data/lib/rubycritic/core/smell.rb +11 -13
  43. data/lib/rubycritic/generators/console_report.rb +1 -1
  44. data/lib/rubycritic/generators/html/base.rb +9 -9
  45. data/lib/rubycritic/generators/html/code_file.rb +5 -7
  46. data/lib/rubycritic/generators/html/code_index.rb +3 -5
  47. data/lib/rubycritic/generators/html/line.rb +4 -6
  48. data/lib/rubycritic/generators/html/overview.rb +4 -6
  49. data/lib/rubycritic/generators/html/smells_index.rb +3 -5
  50. data/lib/rubycritic/generators/html/turbulence.rb +4 -6
  51. data/lib/rubycritic/generators/html/view_helpers.rb +4 -4
  52. data/lib/rubycritic/generators/html_report.rb +13 -9
  53. data/lib/rubycritic/generators/json/simple.rb +7 -9
  54. data/lib/rubycritic/generators/json_report.rb +1 -3
  55. data/lib/rubycritic/generators/text/list.rb +9 -9
  56. data/lib/rubycritic/reporter.rb +3 -5
  57. data/lib/rubycritic/revision_comparator.rb +6 -8
  58. data/lib/rubycritic/serializer.rb +2 -4
  59. data/lib/rubycritic/smells_status_setter.rb +2 -4
  60. data/lib/rubycritic/source_control_systems/base.rb +4 -6
  61. data/lib/rubycritic/source_control_systems/double.rb +1 -2
  62. data/lib/rubycritic/source_control_systems/git.rb +1 -3
  63. data/lib/rubycritic/source_control_systems/mercurial.rb +1 -3
  64. data/lib/rubycritic/source_locator.rb +5 -6
  65. data/lib/rubycritic/version.rb +1 -1
  66. data/rubycritic.gemspec +26 -25
  67. data/test/analysers_test_helper.rb +1 -1
  68. data/test/lib/rubycritic/analysers/churn_test.rb +9 -9
  69. data/test/lib/rubycritic/analysers/complexity_test.rb +5 -5
  70. data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +12 -12
  71. data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +25 -25
  72. data/test/lib/rubycritic/analysers/smells/flay_test.rb +12 -12
  73. data/test/lib/rubycritic/analysers/smells/flog_test.rb +7 -7
  74. data/test/lib/rubycritic/analysers/smells/reek_test.rb +8 -8
  75. data/test/lib/rubycritic/browser_test.rb +16 -0
  76. data/test/lib/rubycritic/commands/status_reporter_test.rb +31 -19
  77. data/test/lib/rubycritic/configuration_test.rb +10 -10
  78. data/test/lib/rubycritic/core/analysed_module_test.rb +37 -37
  79. data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +32 -32
  80. data/test/lib/rubycritic/core/location_test.rb +16 -16
  81. data/test/lib/rubycritic/core/smell_test.rb +31 -31
  82. data/test/lib/rubycritic/core/smells_array_test.rb +18 -18
  83. data/test/lib/rubycritic/generators/console_report_test.rb +26 -26
  84. data/test/lib/rubycritic/generators/turbulence_test.rb +8 -8
  85. data/test/lib/rubycritic/generators/view_helpers_test.rb +36 -36
  86. data/test/lib/rubycritic/smells_status_setter_test.rb +7 -7
  87. data/test/lib/rubycritic/source_control_systems/base_test.rb +7 -7
  88. data/test/lib/rubycritic/source_control_systems/double_test.rb +3 -3
  89. data/test/lib/rubycritic/source_control_systems/git_test.rb +4 -4
  90. data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +3 -3
  91. data/test/lib/rubycritic/source_locator_test.rb +30 -30
  92. data/test/lib/rubycritic/version_test.rb +4 -4
  93. data/test/test_helper.rb +4 -4
  94. metadata +30 -17
@@ -1,5 +1,5 @@
1
- require "rubycritic/source_locator"
2
- require "rubycritic/core/analysed_module"
1
+ require 'rubycritic/source_locator'
2
+ require 'rubycritic/core/analysed_module'
3
3
 
4
4
  module Rubycritic
5
5
  class AnalysedModulesCollection
@@ -17,7 +17,7 @@ module Rubycritic
17
17
 
18
18
  def initialize(paths)
19
19
  @modules = SourceLocator.new(paths).pathnames.map do |pathname|
20
- AnalysedModule.new(:pathname => pathname)
20
+ AnalysedModule.new(pathname: pathname)
21
21
  end
22
22
  end
23
23
 
@@ -1,7 +1,6 @@
1
- require "pathname"
1
+ require 'pathname'
2
2
 
3
3
  module Rubycritic
4
-
5
4
  class Location
6
5
  attr_reader :pathname, :line
7
6
 
@@ -11,7 +10,7 @@ module Rubycritic
11
10
  end
12
11
 
13
12
  def file_name
14
- @pathname.basename.sub_ext("").to_s
13
+ @pathname.basename.sub_ext('').to_s
15
14
  end
16
15
 
17
16
  def to_s
@@ -20,8 +19,8 @@ module Rubycritic
20
19
 
21
20
  def to_h
22
21
  {
23
- :path => pathname.to_s,
24
- :line => line
22
+ path: pathname.to_s,
23
+ line: line
25
24
  }
26
25
  end
27
26
 
@@ -43,5 +42,4 @@ module Rubycritic
43
42
  [@pathname, @line]
44
43
  end
45
44
  end
46
-
47
45
  end
@@ -1,12 +1,11 @@
1
1
  module Rubycritic
2
-
3
2
  class Rating
4
3
  def self.from_cost(cost)
5
- if cost <= 2 then new("A")
6
- elsif cost <= 4 then new("B")
7
- elsif cost <= 8 then new("C")
8
- elsif cost <= 16 then new("D")
9
- else new("F")
4
+ if cost <= 2 then new('A')
5
+ elsif cost <= 4 then new('B')
6
+ elsif cost <= 8 then new('C')
7
+ elsif cost <= 16 then new('D')
8
+ else new('F')
10
9
  end
11
10
  end
12
11
 
@@ -26,5 +25,4 @@ module Rubycritic
26
25
  to_h.to_json(*a)
27
26
  end
28
27
  end
29
-
30
28
  end
@@ -1,14 +1,13 @@
1
- require "virtus"
2
- require "rubycritic/core/location"
1
+ require 'virtus'
2
+ require 'rubycritic/core/location'
3
3
 
4
4
  module Rubycritic
5
-
6
5
  class Smell
7
6
  include Virtus.model
8
7
 
9
8
  attribute :context
10
9
  attribute :cost
11
- attribute :locations, Array, :default => []
10
+ attribute :locations, Array, default: []
12
11
  attribute :message
13
12
  attribute :score
14
13
  attribute :status
@@ -25,7 +24,7 @@ module Rubycritic
25
24
  def ==(other)
26
25
  state == other.state
27
26
  end
28
- alias_method :eql?, :==
27
+ alias eql? ==
29
28
 
30
29
  def to_s
31
30
  "(#{type}) #{context} #{message}"
@@ -33,13 +32,13 @@ module Rubycritic
33
32
 
34
33
  def to_h
35
34
  {
36
- :context => context,
37
- :cost => cost,
38
- :locations => locations,
39
- :message => message,
40
- :score => score,
41
- :status => status,
42
- :type => type
35
+ context: context,
36
+ cost: cost,
37
+ locations: locations,
38
+ message: message,
39
+ score: score,
40
+ status: status,
41
+ type: type
43
42
  }
44
43
  end
45
44
 
@@ -57,5 +56,4 @@ module Rubycritic
57
56
  [@context, @message, @score, @type]
58
57
  end
59
58
  end
60
-
61
59
  end
@@ -1,4 +1,4 @@
1
- require "rubycritic/generators/text/list"
1
+ require 'rubycritic/generators/text/list'
2
2
 
3
3
  module Rubycritic
4
4
  module Generator
@@ -1,18 +1,17 @@
1
- require "erb"
2
- require "pathname"
3
- require "rubycritic/generators/html/view_helpers"
1
+ require 'erb'
2
+ require 'pathname'
3
+ require 'rubycritic/generators/html/view_helpers'
4
4
 
5
5
  module Rubycritic
6
6
  module Generator
7
7
  module Html
8
-
9
8
  class Base
10
9
  def self.erb_template(template_path)
11
10
  ERB.new(File.read(File.join(TEMPLATES_DIR, template_path)))
12
11
  end
13
12
 
14
- TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
15
- LAYOUT_TEMPLATE = erb_template(File.join("layouts", "application.html.erb"))
13
+ TEMPLATES_DIR = File.expand_path('../templates', __FILE__)
14
+ LAYOUT_TEMPLATE = erb_template(File.join('layouts', 'application.html.erb'))
16
15
 
17
16
  include ViewHelpers
18
17
 
@@ -29,11 +28,13 @@ module Rubycritic
29
28
  end
30
29
 
31
30
  def file_name
32
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
31
+ fail NotImplementedError,
32
+ "The #{self.class} class must implement the #{__method__} method."
33
33
  end
34
34
 
35
35
  def render
36
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
36
+ fail NotImplementedError,
37
+ "The #{self.class} class must implement the #{__method__} method."
37
38
  end
38
39
 
39
40
  private
@@ -46,7 +47,6 @@ module Rubycritic
46
47
  binding
47
48
  end
48
49
  end
49
-
50
50
  end
51
51
  end
52
52
  end
@@ -1,13 +1,12 @@
1
- require "rubycritic/generators/html/base"
2
- require "rubycritic/generators/html/line"
1
+ require 'rubycritic/generators/html/base'
2
+ require 'rubycritic/generators/html/line'
3
3
 
4
4
  module Rubycritic
5
5
  module Generator
6
6
  module Html
7
-
8
7
  class CodeFile < Base
9
8
  LINE_NUMBER_OFFSET = 1
10
- TEMPLATE = erb_template("code_file.html.erb")
9
+ TEMPLATE = erb_template('code_file.html.erb')
11
10
 
12
11
  def initialize(analysed_module)
13
12
  @analysed_module = analysed_module
@@ -19,11 +18,11 @@ module Rubycritic
19
18
  end
20
19
 
21
20
  def file_name
22
- @pathname.basename.sub_ext(".html")
21
+ @pathname.basename.sub_ext('.html')
23
22
  end
24
23
 
25
24
  def render
26
- file_code = ""
25
+ file_code = ''
27
26
  File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
28
27
  location = Location.new(@pathname, line_number)
29
28
  line_smells = @analysed_module.smells_at_location(location)
@@ -34,7 +33,6 @@ module Rubycritic
34
33
  LAYOUT_TEMPLATE.result(get_binding { file_body })
35
34
  end
36
35
  end
37
-
38
36
  end
39
37
  end
40
38
  end
@@ -1,18 +1,17 @@
1
- require "rubycritic/generators/html/base"
1
+ require 'rubycritic/generators/html/base'
2
2
 
3
3
  module Rubycritic
4
4
  module Generator
5
5
  module Html
6
-
7
6
  class CodeIndex < Base
8
- TEMPLATE = erb_template("code_index.html.erb")
7
+ TEMPLATE = erb_template('code_index.html.erb')
9
8
 
10
9
  def initialize(analysed_modules)
11
10
  @analysed_modules = analysed_modules
12
11
  end
13
12
 
14
13
  def file_name
15
- "code_index.html"
14
+ 'code_index.html'
16
15
  end
17
16
 
18
17
  def render
@@ -20,7 +19,6 @@ module Rubycritic
20
19
  LAYOUT_TEMPLATE.result(get_binding { index_body })
21
20
  end
22
21
  end
23
-
24
22
  end
25
23
  end
26
24
  end
@@ -1,13 +1,12 @@
1
- require "cgi"
2
- require "rubycritic/generators/html/base"
1
+ require 'cgi'
2
+ require 'rubycritic/generators/html/base'
3
3
 
4
4
  module Rubycritic
5
5
  module Generator
6
6
  module Html
7
-
8
7
  class Line < Base
9
- NORMAL_TEMPLATE = erb_template("line.html.erb")
10
- SMELLY_TEMPLATE = erb_template("smelly_line.html.erb")
8
+ NORMAL_TEMPLATE = erb_template('line.html.erb')
9
+ SMELLY_TEMPLATE = erb_template('smelly_line.html.erb')
11
10
 
12
11
  attr_reader :file_directory
13
12
 
@@ -31,7 +30,6 @@ module Rubycritic
31
30
  end
32
31
  end
33
32
  end
34
-
35
33
  end
36
34
  end
37
35
  end
@@ -1,12 +1,11 @@
1
- require "rubycritic/generators/html/base"
2
- require "rubycritic/generators/html/turbulence"
1
+ require 'rubycritic/generators/html/base'
2
+ require 'rubycritic/generators/html/turbulence'
3
3
 
4
4
  module Rubycritic
5
5
  module Generator
6
6
  module Html
7
-
8
7
  class Overview < Base
9
- TEMPLATE = erb_template("overview.html.erb")
8
+ TEMPLATE = erb_template('overview.html.erb')
10
9
 
11
10
  def initialize(analysed_modules)
12
11
  @turbulence_data = Turbulence.data(analysed_modules)
@@ -15,7 +14,7 @@ module Rubycritic
15
14
  end
16
15
 
17
16
  def file_name
18
- "overview.html"
17
+ 'overview.html'
19
18
  end
20
19
 
21
20
  def render
@@ -23,7 +22,6 @@ module Rubycritic
23
22
  LAYOUT_TEMPLATE.result(get_binding { index_body })
24
23
  end
25
24
  end
26
-
27
25
  end
28
26
  end
29
27
  end
@@ -1,11 +1,10 @@
1
- require "rubycritic/generators/html/base"
1
+ require 'rubycritic/generators/html/base'
2
2
 
3
3
  module Rubycritic
4
4
  module Generator
5
5
  module Html
6
-
7
6
  class SmellsIndex < Base
8
- TEMPLATE = erb_template("smells_index.html.erb")
7
+ TEMPLATE = erb_template('smells_index.html.erb')
9
8
 
10
9
  def initialize(analysed_modules)
11
10
  @smells = analysed_modules.flat_map(&:smells).uniq
@@ -14,7 +13,7 @@ module Rubycritic
14
13
  end
15
14
 
16
15
  def file_name
17
- "smells_index.html"
16
+ 'smells_index.html'
18
17
  end
19
18
 
20
19
  def render
@@ -32,7 +31,6 @@ module Rubycritic
32
31
  names
33
32
  end
34
33
  end
35
-
36
34
  end
37
35
  end
38
36
  end
@@ -1,17 +1,15 @@
1
- require "json"
1
+ require 'json'
2
2
 
3
3
  module Rubycritic
4
-
5
4
  module Turbulence
6
5
  def self.data(analysed_modules)
7
6
  analysed_modules.map do |analysed_module|
8
7
  {
9
- :name => analysed_module.name,
10
- :x => analysed_module.churn,
11
- :y => analysed_module.complexity
8
+ name: analysed_module.name,
9
+ x: analysed_module.churn,
10
+ y: analysed_module.complexity
12
11
  }
13
12
  end.to_json
14
13
  end
15
14
  end
16
-
17
15
  end
@@ -1,5 +1,4 @@
1
1
  module Rubycritic
2
-
3
2
  module ViewHelpers
4
3
  def timeago_tag(time)
5
4
  "<time class='js-timeago' datetime='#{time}'>#{time}</time>"
@@ -32,12 +31,13 @@ module Rubycritic
32
31
  end
33
32
 
34
33
  def file_directory
35
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
34
+ fail NotImplementedError,
35
+ "The #{self.class} class must implement the #{__method__} method."
36
36
  end
37
37
 
38
38
  def root_directory
39
- raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
39
+ fail NotImplementedError,
40
+ "The #{self.class} class must implement the #{__method__} method."
40
41
  end
41
42
  end
42
-
43
43
  end
@@ -1,14 +1,14 @@
1
- require "fileutils"
2
- require "rubycritic/generators/html/overview"
3
- require "rubycritic/generators/html/smells_index"
4
- require "rubycritic/generators/html/code_index"
5
- require "rubycritic/generators/html/code_file"
1
+ require 'fileutils'
2
+ require 'rubycritic/configuration'
3
+ require 'rubycritic/generators/html/overview'
4
+ require 'rubycritic/generators/html/smells_index'
5
+ require 'rubycritic/generators/html/code_index'
6
+ require 'rubycritic/generators/html/code_file'
6
7
 
7
8
  module Rubycritic
8
9
  module Generator
9
-
10
10
  class HtmlReport
11
- ASSETS_DIR = File.expand_path("../html/assets", __FILE__)
11
+ ASSETS_DIR = File.expand_path('../html/assets', __FILE__)
12
12
 
13
13
  def initialize(analysed_modules)
14
14
  @analysed_modules = analysed_modules
@@ -18,6 +18,11 @@ module Rubycritic
18
18
  create_directories_and_files
19
19
  copy_assets_to_report_directory
20
20
  puts "New critique at #{report_location}"
21
+ browser.open unless Config.no_browser
22
+ end
23
+
24
+ def browser
25
+ @browser ||= Rubycritic::Browser.new(report_location)
21
26
  end
22
27
 
23
28
  private
@@ -25,7 +30,7 @@ module Rubycritic
25
30
  def create_directories_and_files
26
31
  Array(generators).each do |generator|
27
32
  FileUtils.mkdir_p(generator.file_directory)
28
- File.open(generator.file_pathname, "w+") do |file|
33
+ File.open(generator.file_pathname, 'w+') do |file|
29
34
  file.write(generator.render)
30
35
  end
31
36
  end
@@ -61,6 +66,5 @@ module Rubycritic
61
66
  overview_generator.file_href
62
67
  end
63
68
  end
64
-
65
69
  end
66
70
  end
@@ -1,10 +1,9 @@
1
- require "json"
2
- require "rubycritic/version"
1
+ require 'json'
2
+ require 'rubycritic/version'
3
3
 
4
4
  module Rubycritic
5
5
  module Generator
6
6
  module Json
7
-
8
7
  class Simple
9
8
  def initialize(analysed_modules)
10
9
  @analysed_modules = analysed_modules
@@ -16,17 +15,16 @@ module Rubycritic
16
15
 
17
16
  def data
18
17
  {
19
- :metadata => {
20
- :rubycritic => {
21
- :version => Rubycritic::VERSION
18
+ metadata: {
19
+ rubycritic: {
20
+ version: Rubycritic::VERSION
22
21
  }
23
22
  },
24
- :analysed_modules => @analysed_modules,
25
- :score => @analysed_modules.score
23
+ analysed_modules: @analysed_modules,
24
+ score: @analysed_modules.score
26
25
  }
27
26
  end
28
27
  end
29
-
30
28
  end
31
29
  end
32
30
  end