rubycritic 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,10 +1,9 @@
1
- require "rubycritic/analysers/helpers/flog"
2
- require "rubycritic/core/smell"
3
- require "rubycritic/colorize"
1
+ require 'rubycritic/analysers/helpers/flog'
2
+ require 'rubycritic/core/smell'
3
+ require 'rubycritic/colorize'
4
4
 
5
5
  module Rubycritic
6
6
  module Analyser
7
-
8
7
  class FlogSmells
9
8
  include Colorize
10
9
  HIGH_COMPLEXITY_SCORE_THRESHOLD = 25
@@ -18,13 +17,13 @@ module Rubycritic
18
17
  def run
19
18
  @analysed_modules.each do |analysed_module|
20
19
  add_smells_to(analysed_module)
21
- print green "."
20
+ print green '.'
22
21
  end
23
- puts ""
22
+ puts ''
24
23
  end
25
24
 
26
25
  def to_s
27
- "flog smells"
26
+ 'flog smells'
28
27
  end
29
28
 
30
29
  private
@@ -42,29 +41,28 @@ module Rubycritic
42
41
 
43
42
  def create_smell(context, score)
44
43
  Smell.new(
45
- :locations => smell_locations(context),
46
- :context => context,
47
- :message => "has a flog score of #{score}",
48
- :score => score,
49
- :type => type(score),
50
- :cost => 0
44
+ locations: smell_locations(context),
45
+ context: context,
46
+ message: "has a flog score of #{score}",
47
+ score: score,
48
+ type: type(score),
49
+ cost: 0
51
50
  )
52
51
  end
53
52
 
54
53
  def smell_locations(context)
55
54
  line = @flog.method_locations[context]
56
- file_path, file_line = line.split(":")
55
+ file_path, file_line = line.split(':')
57
56
  [Location.new(file_path, file_line)]
58
57
  end
59
58
 
60
59
  def type(score)
61
60
  if score >= VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD
62
- "VeryHighComplexity"
61
+ 'VeryHighComplexity'
63
62
  else
64
- "HighComplexity"
63
+ 'HighComplexity'
65
64
  end
66
65
  end
67
66
  end
68
-
69
67
  end
70
68
  end
@@ -1,10 +1,9 @@
1
- require "rubycritic/analysers/helpers/reek"
2
- require "rubycritic/core/smell"
3
- require "rubycritic/colorize"
1
+ require 'rubycritic/analysers/helpers/reek'
2
+ require 'rubycritic/core/smell'
3
+ require 'rubycritic/colorize'
4
4
 
5
5
  module Rubycritic
6
6
  module Analyser
7
-
8
7
  class ReekSmells
9
8
  include Colorize
10
9
  def initialize(analysed_modules)
@@ -14,13 +13,13 @@ module Rubycritic
14
13
  def run
15
14
  @analysed_modules.each do |analysed_module|
16
15
  add_smells_to(analysed_module)
17
- print green "."
16
+ print green '.'
18
17
  end
19
- puts ""
18
+ puts ''
20
19
  end
21
20
 
22
21
  def to_s
23
- "reek smells"
22
+ 'reek smells'
24
23
  end
25
24
 
26
25
  private
@@ -33,11 +32,11 @@ module Rubycritic
33
32
 
34
33
  def create_smell(smell)
35
34
  Smell.new(
36
- :locations => smell_locations(smell.source, smell.lines),
37
- :context => smell.context,
38
- :message => smell.message,
39
- :type => smell.smell_type,
40
- :cost => 0
35
+ locations: smell_locations(smell.source, smell.lines),
36
+ context: smell.context,
37
+ message: smell.message,
38
+ type: smell.smell_type,
39
+ cost: 0
41
40
  )
42
41
  end
43
42
 
@@ -47,6 +46,5 @@ module Rubycritic
47
46
  end.sort
48
47
  end
49
48
  end
50
-
51
49
  end
52
50
  end
@@ -1,13 +1,12 @@
1
- require "rubycritic/core/analysed_modules_collection"
2
- require "rubycritic/analysers/smells/flay"
3
- require "rubycritic/analysers/smells/flog"
4
- require "rubycritic/analysers/smells/reek"
5
- require "rubycritic/analysers/complexity"
6
- require "rubycritic/analysers/churn"
7
- require "rubycritic/analysers/attributes"
1
+ require 'rubycritic/core/analysed_modules_collection'
2
+ require 'rubycritic/analysers/smells/flay'
3
+ require 'rubycritic/analysers/smells/flog'
4
+ require 'rubycritic/analysers/smells/reek'
5
+ require 'rubycritic/analysers/complexity'
6
+ require 'rubycritic/analysers/churn'
7
+ require 'rubycritic/analysers/attributes'
8
8
 
9
9
  module Rubycritic
10
-
11
10
  class AnalysersRunner
12
11
  ANALYSERS = [
13
12
  Analyser::FlaySmells,
@@ -16,7 +15,7 @@ module Rubycritic
16
15
  Analyser::Complexity,
17
16
  Analyser::Attributes,
18
17
  Analyser::Churn
19
- ]
18
+ ].freeze
20
19
 
21
20
  def initialize(paths)
22
21
  @paths = paths
@@ -35,5 +34,4 @@ module Rubycritic
35
34
  @analysed_modules ||= AnalysedModulesCollection.new(@paths)
36
35
  end
37
36
  end
38
-
39
37
  end
@@ -0,0 +1,17 @@
1
+ require 'launchy'
2
+
3
+ module Rubycritic
4
+ class Browser
5
+ attr_reader :report_path
6
+
7
+ def initialize(report_path)
8
+ @report_path = report_path
9
+ end
10
+
11
+ def open
12
+ Launchy.open(report_path) do |exception|
13
+ puts "Attempted to open #{report_path} and failed because #{exception}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,6 @@
1
- require "rubycritic"
2
- require "rubycritic/cli/options"
3
- require "rubycritic/command_factory"
1
+ require 'rubycritic'
2
+ require 'rubycritic/cli/options'
3
+ require 'rubycritic/command_factory'
4
4
 
5
5
  module Rubycritic
6
6
  module Cli
@@ -1,4 +1,5 @@
1
- require "optparse"
1
+ require 'optparse'
2
+ require 'rubycritic/browser'
2
3
 
3
4
  module Rubycritic
4
5
  module Cli
@@ -11,44 +12,48 @@ module Rubycritic
11
12
  # rubocop:disable Metrics/MethodLength
12
13
  def parse
13
14
  @parser.new do |opts|
14
- opts.banner = "Usage: rubycritic [options] [paths]"
15
+ opts.banner = 'Usage: rubycritic [options] [paths]'
15
16
 
16
- opts.on("-p", "--path [PATH]", "Set path where report will be saved (tmp/rubycritic by default)") do |path|
17
+ opts.on('-p', '--path [PATH]', 'Set path where report will be saved (tmp/rubycritic by default)') do |path|
17
18
  @root = path
18
19
  end
19
20
 
20
21
  opts.on(
21
- "-f", "--format [FORMAT]",
22
+ '-f', '--format [FORMAT]',
22
23
  [:html, :json, :console],
23
- "Report smells in the given format:",
24
- " html (default)",
25
- " json",
26
- " console"
24
+ 'Report smells in the given format:',
25
+ ' html (default)',
26
+ ' json',
27
+ ' console'
27
28
  ) do |format|
28
29
  @format = format
29
30
  end
30
31
 
31
- opts.on("-s", "--minimum-score [MIN_SCORE]", "Set a minimum score") do |min_score|
32
+ opts.on('-s', '--minimum-score [MIN_SCORE]', 'Set a minimum score') do |min_score|
32
33
  @minimum_score = Integer(min_score)
33
34
  end
34
35
 
35
- opts.on("-m", "--mode-ci", "Use CI mode (faster, but only analyses last commit)") do
36
+ opts.on('-m', '--mode-ci', 'Use CI mode (faster, but only analyses last commit)') do
36
37
  @mode = :ci
37
38
  end
38
39
 
39
- opts.on("--deduplicate-symlinks", "De-duplicate symlinks based on their final target") do
40
+ opts.on('--deduplicate-symlinks', 'De-duplicate symlinks based on their final target') do
40
41
  @deduplicate_symlinks = true
41
42
  end
42
43
 
43
- opts.on("--suppress-ratings", "Suppress letter ratings") do
44
+ opts.on('--suppress-ratings', 'Suppress letter ratings') do
44
45
  @suppress_ratings = true
45
46
  end
46
47
 
47
- opts.on_tail("-v", "--version", "Show gem's version") do
48
+ opts.on('--no-browser', 'Do not open html report with browser') do
49
+ @no_browser = true
50
+ end
51
+
52
+ opts.on_tail('-v', '--version', "Show gem's version") do
48
53
  @mode = :version
49
54
  end
50
55
 
51
- opts.on_tail("-h", "--help", "Show this message") do
56
+ opts.on_tail('-h', '--help', 'Show this message') do
52
57
  @mode = :help
53
58
  end
54
59
  end.parse!(@argv)
@@ -57,14 +62,15 @@ module Rubycritic
57
62
 
58
63
  def to_h
59
64
  {
60
- :mode => @mode,
61
- :root => @root,
62
- :format => @format,
63
- :deduplicate_symlinks => @deduplicate_symlinks,
64
- :paths => paths,
65
- :suppress_ratings => @suppress_ratings,
66
- :help_text => @parser.help,
67
- :minimum_score => @minimum_score || 0
65
+ mode: @mode,
66
+ root: @root,
67
+ format: @format,
68
+ deduplicate_symlinks: @deduplicate_symlinks,
69
+ paths: paths,
70
+ suppress_ratings: @suppress_ratings,
71
+ help_text: @parser.help,
72
+ minimum_score: @minimum_score || 0,
73
+ no_browser: @no_browser
68
74
  }
69
75
  end
70
76
 
@@ -72,7 +78,7 @@ module Rubycritic
72
78
 
73
79
  def paths
74
80
  if @argv.empty?
75
- ["."]
81
+ ['.']
76
82
  else
77
83
  @argv
78
84
  end
@@ -1,4 +1,4 @@
1
- require "rubycritic/configuration"
1
+ require 'rubycritic/configuration'
2
2
 
3
3
  module Rubycritic
4
4
  class CommandFactory
@@ -10,16 +10,16 @@ module Rubycritic
10
10
  def self.command_class(mode)
11
11
  case mode
12
12
  when :version
13
- require "rubycritic/commands/version"
13
+ require 'rubycritic/commands/version'
14
14
  Command::Version
15
15
  when :help
16
- require "rubycritic/commands/help"
16
+ require 'rubycritic/commands/help'
17
17
  Command::Help
18
18
  when :ci
19
- require "rubycritic/commands/ci"
19
+ require 'rubycritic/commands/ci'
20
20
  Command::Ci
21
21
  else
22
- require "rubycritic/commands/default"
22
+ require 'rubycritic/commands/default'
23
23
  Command::Default
24
24
  end
25
25
  end
@@ -1,4 +1,4 @@
1
- require "rubycritic/commands/status_reporter"
1
+ require 'rubycritic/commands/status_reporter'
2
2
 
3
3
  module Rubycritic
4
4
  module Command
@@ -9,7 +9,7 @@ module Rubycritic
9
9
  end
10
10
 
11
11
  def execute
12
- raise NotImplementedError
12
+ fail NotImplementedError
13
13
  end
14
14
  end
15
15
  end
@@ -1,7 +1,7 @@
1
- require "rubycritic/source_control_systems/base"
2
- require "rubycritic/analysers_runner"
3
- require "rubycritic/reporter"
4
- require "rubycritic/commands/default"
1
+ require 'rubycritic/source_control_systems/base'
2
+ require 'rubycritic/analysers_runner'
3
+ require 'rubycritic/reporter'
4
+ require 'rubycritic/commands/default'
5
5
 
6
6
  module Rubycritic
7
7
  module Command
@@ -1,8 +1,8 @@
1
- require "rubycritic/source_control_systems/base"
2
- require "rubycritic/analysers_runner"
3
- require "rubycritic/revision_comparator"
4
- require "rubycritic/reporter"
5
- require "rubycritic/commands/base"
1
+ require 'rubycritic/source_control_systems/base'
2
+ require 'rubycritic/analysers_runner'
3
+ require 'rubycritic/revision_comparator'
4
+ require 'rubycritic/reporter'
5
+ require 'rubycritic/commands/base'
6
6
 
7
7
  module Rubycritic
8
8
  module Command
@@ -1,4 +1,4 @@
1
- require "rubycritic/commands/base"
1
+ require 'rubycritic/commands/base'
2
2
 
3
3
  module Rubycritic
4
4
  module Command
@@ -11,7 +11,7 @@ module Rubycritic
11
11
  end
12
12
 
13
13
  def score=(score)
14
- @score = score
14
+ @score = score.round(2)
15
15
  update_status
16
16
  end
17
17
 
@@ -1,5 +1,5 @@
1
- require "rubycritic/version"
2
- require "rubycritic/commands/base"
1
+ require 'rubycritic/version'
2
+ require 'rubycritic/commands/base'
3
3
 
4
4
  module Rubycritic
5
5
  module Command
@@ -2,14 +2,16 @@ module Rubycritic
2
2
  class Configuration
3
3
  attr_reader :root
4
4
  attr_accessor :source_control_system, :mode, :format, :deduplicate_symlinks,
5
- :suppress_ratings
5
+ :suppress_ratings, :open_with, :no_browser
6
6
 
7
7
  def set(options)
8
8
  self.mode = options[:mode] || :default
9
- self.root = options[:root] || "tmp/rubycritic"
9
+ self.root = options[:root] || 'tmp/rubycritic'
10
10
  self.format = options[:format] || :html
11
11
  self.deduplicate_symlinks = options[:deduplicate_symlinks] || false
12
12
  self.suppress_ratings = options[:suppress_ratings] || false
13
+ self.open_with = options[:open_with]
14
+ self.no_browser = options[:no_browser]
13
15
  end
14
16
 
15
17
  def root=(path)
@@ -1,18 +1,17 @@
1
- require "virtus"
2
- require "rubycritic/core/rating"
1
+ require 'virtus'
2
+ require 'rubycritic/core/rating'
3
3
 
4
4
  module Rubycritic
5
-
6
5
  class AnalysedModule
7
6
  include Virtus.model
8
7
 
9
8
  attribute :name
10
9
  attribute :pathname
11
- attribute :smells, Array, :default => []
10
+ attribute :smells, Array, default: []
12
11
  attribute :churn
13
12
  attribute :committed_at
14
13
  attribute :complexity
15
- attribute :duplication, Integer, :default => 0
14
+ attribute :duplication, Integer, default: 0
16
15
  attribute :methods_count
17
16
 
18
17
  def path
@@ -29,7 +28,7 @@ module Rubycritic
29
28
 
30
29
  def complexity_per_method
31
30
  if methods_count == 0
32
- "N/A"
31
+ 'N/A'
33
32
  else
34
33
  complexity.fdiv(methods_count).round(1)
35
34
  end
@@ -49,16 +48,16 @@ module Rubycritic
49
48
 
50
49
  def to_h
51
50
  {
52
- :name => name,
53
- :path => path,
54
- :smells => smells,
55
- :churn => churn,
56
- :committed_at => committed_at,
57
- :complexity => complexity,
58
- :duplication => duplication,
59
- :methods_count => methods_count,
60
- :cost => cost,
61
- :rating => rating
51
+ name: name,
52
+ path: path,
53
+ smells: smells,
54
+ churn: churn,
55
+ committed_at: committed_at,
56
+ complexity: complexity,
57
+ duplication: duplication,
58
+ methods_count: methods_count,
59
+ cost: cost,
60
+ rating: rating
62
61
  }
63
62
  end
64
63
 
@@ -66,5 +65,4 @@ module Rubycritic
66
65
  to_h.to_json(*a)
67
66
  end
68
67
  end
69
-
70
68
  end