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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -585
- data/.rubocop_todo.yml +36 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/Rakefile +9 -9
- data/bin/rubycritic +2 -2
- data/features/command_line_interface/options.feature +1 -0
- data/features/step_definitions/rubycritic_steps.rb +1 -1
- data/features/step_definitions/sample_file_steps.rb +3 -3
- data/features/support/env.rb +6 -6
- data/lib/rubycritic.rb +1 -1
- data/lib/rubycritic/analysers/attributes.rb +6 -7
- data/lib/rubycritic/analysers/churn.rb +4 -6
- data/lib/rubycritic/analysers/complexity.rb +5 -7
- data/lib/rubycritic/analysers/helpers/ast_node.rb +4 -6
- data/lib/rubycritic/analysers/helpers/flay.rb +1 -3
- data/lib/rubycritic/analysers/helpers/flog.rb +5 -7
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +1 -3
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +3 -5
- data/lib/rubycritic/analysers/helpers/parser.rb +2 -2
- data/lib/rubycritic/analysers/helpers/reek.rb +1 -1
- data/lib/rubycritic/analysers/smells/flay.rb +14 -16
- data/lib/rubycritic/analysers/smells/flog.rb +15 -17
- data/lib/rubycritic/analysers/smells/reek.rb +11 -13
- data/lib/rubycritic/analysers_runner.rb +8 -10
- data/lib/rubycritic/browser.rb +17 -0
- data/lib/rubycritic/cli/application.rb +3 -3
- data/lib/rubycritic/cli/options.rb +29 -23
- data/lib/rubycritic/command_factory.rb +5 -5
- data/lib/rubycritic/commands/base.rb +2 -2
- data/lib/rubycritic/commands/ci.rb +4 -4
- data/lib/rubycritic/commands/default.rb +5 -5
- data/lib/rubycritic/commands/help.rb +1 -1
- data/lib/rubycritic/commands/status_reporter.rb +1 -1
- data/lib/rubycritic/commands/version.rb +2 -2
- data/lib/rubycritic/configuration.rb +4 -2
- data/lib/rubycritic/core/analysed_module.rb +15 -17
- data/lib/rubycritic/core/analysed_modules_collection.rb +3 -3
- data/lib/rubycritic/core/location.rb +4 -6
- data/lib/rubycritic/core/rating.rb +5 -7
- data/lib/rubycritic/core/smell.rb +11 -13
- data/lib/rubycritic/generators/console_report.rb +1 -1
- data/lib/rubycritic/generators/html/base.rb +9 -9
- data/lib/rubycritic/generators/html/code_file.rb +5 -7
- data/lib/rubycritic/generators/html/code_index.rb +3 -5
- data/lib/rubycritic/generators/html/line.rb +4 -6
- data/lib/rubycritic/generators/html/overview.rb +4 -6
- data/lib/rubycritic/generators/html/smells_index.rb +3 -5
- data/lib/rubycritic/generators/html/turbulence.rb +4 -6
- data/lib/rubycritic/generators/html/view_helpers.rb +4 -4
- data/lib/rubycritic/generators/html_report.rb +13 -9
- data/lib/rubycritic/generators/json/simple.rb +7 -9
- data/lib/rubycritic/generators/json_report.rb +1 -3
- data/lib/rubycritic/generators/text/list.rb +9 -9
- data/lib/rubycritic/reporter.rb +3 -5
- data/lib/rubycritic/revision_comparator.rb +6 -8
- data/lib/rubycritic/serializer.rb +2 -4
- data/lib/rubycritic/smells_status_setter.rb +2 -4
- data/lib/rubycritic/source_control_systems/base.rb +4 -6
- data/lib/rubycritic/source_control_systems/double.rb +1 -2
- data/lib/rubycritic/source_control_systems/git.rb +1 -3
- data/lib/rubycritic/source_control_systems/mercurial.rb +1 -3
- data/lib/rubycritic/source_locator.rb +5 -6
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +26 -25
- data/test/analysers_test_helper.rb +1 -1
- data/test/lib/rubycritic/analysers/churn_test.rb +9 -9
- data/test/lib/rubycritic/analysers/complexity_test.rb +5 -5
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +12 -12
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +25 -25
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +12 -12
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +7 -7
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +8 -8
- data/test/lib/rubycritic/browser_test.rb +16 -0
- data/test/lib/rubycritic/commands/status_reporter_test.rb +31 -19
- data/test/lib/rubycritic/configuration_test.rb +10 -10
- data/test/lib/rubycritic/core/analysed_module_test.rb +37 -37
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +32 -32
- data/test/lib/rubycritic/core/location_test.rb +16 -16
- data/test/lib/rubycritic/core/smell_test.rb +31 -31
- data/test/lib/rubycritic/core/smells_array_test.rb +18 -18
- data/test/lib/rubycritic/generators/console_report_test.rb +26 -26
- data/test/lib/rubycritic/generators/turbulence_test.rb +8 -8
- data/test/lib/rubycritic/generators/view_helpers_test.rb +36 -36
- data/test/lib/rubycritic/smells_status_setter_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/base_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/double_test.rb +3 -3
- data/test/lib/rubycritic/source_control_systems/git_test.rb +4 -4
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +3 -3
- data/test/lib/rubycritic/source_locator_test.rb +30 -30
- data/test/lib/rubycritic/version_test.rb +4 -4
- data/test/test_helper.rb +4 -4
- metadata +30 -17
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
-
|
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
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
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
|
-
|
61
|
+
'VeryHighComplexity'
|
63
62
|
else
|
64
|
-
|
63
|
+
'HighComplexity'
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
68
|
-
|
69
67
|
end
|
70
68
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
-
|
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
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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,4 +1,5 @@
|
|
1
|
-
require
|
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 =
|
15
|
+
opts.banner = 'Usage: rubycritic [options] [paths]'
|
15
16
|
|
16
|
-
opts.on(
|
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
|
-
|
22
|
+
'-f', '--format [FORMAT]',
|
22
23
|
[:html, :json, :console],
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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(
|
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(
|
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(
|
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(
|
44
|
+
opts.on('--suppress-ratings', 'Suppress letter ratings') do
|
44
45
|
@suppress_ratings = true
|
45
46
|
end
|
46
47
|
|
47
|
-
opts.
|
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(
|
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
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
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
|
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
|
13
|
+
require 'rubycritic/commands/version'
|
14
14
|
Command::Version
|
15
15
|
when :help
|
16
|
-
require
|
16
|
+
require 'rubycritic/commands/help'
|
17
17
|
Command::Help
|
18
18
|
when :ci
|
19
|
-
require
|
19
|
+
require 'rubycritic/commands/ci'
|
20
20
|
Command::Ci
|
21
21
|
else
|
22
|
-
require
|
22
|
+
require 'rubycritic/commands/default'
|
23
23
|
Command::Default
|
24
24
|
end
|
25
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
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
|
-
|
12
|
+
fail NotImplementedError
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
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
|
@@ -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
|
-
|
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] ||
|
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
|
2
|
-
require
|
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, :
|
10
|
+
attribute :smells, Array, default: []
|
12
11
|
attribute :churn
|
13
12
|
attribute :committed_at
|
14
13
|
attribute :complexity
|
15
|
-
attribute :duplication, Integer, :
|
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
|
-
|
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
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
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
|