rubycritic 1.0.2 → 1.1.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/CHANGELOG.md +15 -0
- data/lib/rubycritic/analysers/attributes.rb +21 -0
- data/lib/rubycritic/analysers/churn.rb +5 -5
- data/lib/rubycritic/analysers/complexity.rb +6 -6
- data/lib/rubycritic/analysers/helpers/ast_node.rb +73 -0
- data/lib/rubycritic/analysers/{adapters → helpers}/config.reek +0 -0
- data/lib/rubycritic/analysers/{adapters → helpers}/flay.rb +0 -0
- data/lib/rubycritic/analysers/{adapters → helpers}/flog.rb +0 -0
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +28 -0
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +46 -0
- data/lib/rubycritic/analysers/{adapters → helpers}/reek.rb +0 -0
- data/lib/rubycritic/analysers/smells/flay.rb +9 -9
- data/lib/rubycritic/analysers/smells/flog.rb +8 -8
- data/lib/rubycritic/analysers/smells/reek.rb +8 -8
- data/lib/rubycritic/analysers_runner.rb +6 -6
- data/lib/rubycritic/cli.rb +2 -2
- data/lib/rubycritic/core/{analysed_file.rb → analysed_module.rb} +4 -7
- data/lib/rubycritic/modules_initializer.rb +14 -0
- data/lib/rubycritic/orchestrator.rb +5 -5
- data/lib/rubycritic/report_generators/code_file.rb +4 -4
- data/lib/rubycritic/report_generators/code_index.rb +2 -2
- data/lib/rubycritic/report_generators/overview.rb +2 -2
- data/lib/rubycritic/report_generators/smells_index.rb +13 -2
- data/lib/rubycritic/report_generators/templates/code_file.html.erb +10 -10
- data/lib/rubycritic/report_generators/templates/code_index.html.erb +7 -7
- data/lib/rubycritic/report_generators/templates/smells_index.html.erb +1 -1
- data/lib/rubycritic/report_generators/turbulence.rb +5 -5
- data/lib/rubycritic/report_generators/view_helpers.rb +4 -4
- data/lib/rubycritic/reporters/main.rb +7 -8
- data/lib/rubycritic/reporters/mini.rb +3 -3
- data/lib/rubycritic/revision_comparator.rb +12 -10
- data/lib/rubycritic/source_locator.rb +1 -1
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +3 -4
- 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 +29 -0
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +53 -0
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +10 -12
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +7 -7
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +10 -10
- data/test/lib/rubycritic/core/analysed_module_test.rb +88 -0
- data/test/lib/rubycritic/report_generators/turbulence_test.rb +4 -4
- data/test/lib/rubycritic/report_generators/view_helpers_test.rb +10 -23
- data/test/lib/rubycritic/smells_status_setter_test.rb +1 -1
- data/test/lib/rubycritic/source_locator_test.rb +6 -6
- data/test/samples/{stats/empty_example.rb → empty.rb} +0 -0
- data/test/samples/{stats/example.rb → methods_count.rb} +0 -0
- data/test/samples/module_names.rb +18 -0
- data/test/samples/unparsable.rb +1 -0
- metadata +30 -23
- data/lib/rubycritic/analysers/adapters/ast_node.rb +0 -35
- data/lib/rubycritic/analysers/stats.rb +0 -34
- data/lib/rubycritic/files_initializer.rb +0 -15
- data/test/lib/rubycritic/analysers/stats_test.rb +0 -30
- data/test/lib/rubycritic/core/analysed_file_test.rb +0 -86
- data/test/samples/stats/unparsable_example.rb +0 -2
@@ -1,35 +0,0 @@
|
|
1
|
-
module Parser
|
2
|
-
module AST
|
3
|
-
|
4
|
-
class Node
|
5
|
-
def count_nodes_of_type(*types)
|
6
|
-
count = 0
|
7
|
-
recursive_children do |child|
|
8
|
-
count += 1 if types.include?(child.type)
|
9
|
-
end
|
10
|
-
count
|
11
|
-
end
|
12
|
-
|
13
|
-
def recursive_children
|
14
|
-
children.each do |child|
|
15
|
-
next unless child.is_a?(Parser::AST::Node)
|
16
|
-
yield child
|
17
|
-
child.recursive_children { |grand_child| yield grand_child }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module Rubycritic
|
26
|
-
module AST
|
27
|
-
|
28
|
-
class EmptyNode
|
29
|
-
def count_nodes_of_type(*types)
|
30
|
-
0
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "parser/current"
|
2
|
-
require "rubycritic/analysers/adapters/ast_node"
|
3
|
-
|
4
|
-
module Rubycritic
|
5
|
-
module Analyser
|
6
|
-
|
7
|
-
class Stats
|
8
|
-
def initialize(analysed_files)
|
9
|
-
@analysed_files = analysed_files
|
10
|
-
end
|
11
|
-
|
12
|
-
def run
|
13
|
-
@analysed_files.each do |analysed_file|
|
14
|
-
analysed_file.methods_count = methods_count(analysed_file.path)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def methods_count(path)
|
21
|
-
content = File.read(path)
|
22
|
-
node = parse_content(content)
|
23
|
-
node.count_nodes_of_type(:def, :defs)
|
24
|
-
end
|
25
|
-
|
26
|
-
def parse_content(content)
|
27
|
-
Parser::CurrentRuby.parse(content) || AST::EmptyNode.new
|
28
|
-
rescue Parser::SyntaxError => error
|
29
|
-
AST::EmptyNode.new
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "rubycritic/source_locator"
|
2
|
-
require "rubycritic/core/analysed_file"
|
3
|
-
|
4
|
-
module Rubycritic
|
5
|
-
|
6
|
-
module FilesInitializer
|
7
|
-
def self.init(paths)
|
8
|
-
source = SourceLocator.new(paths)
|
9
|
-
source.pathnames.map do |pathname|
|
10
|
-
AnalysedFile.new(:pathname => pathname, :smells => [], :duplication => 0)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require "analysers_test_helper"
|
2
|
-
require "rubycritic/analysers/stats"
|
3
|
-
|
4
|
-
describe Rubycritic::Analyser::Stats do
|
5
|
-
context "when a file contains Ruby code" do
|
6
|
-
it "calculates the number of methods of each file and adds it to analysed_files" do
|
7
|
-
analysed_file = AnalysedFileDouble.new(:path => "test/samples/stats/example.rb")
|
8
|
-
Rubycritic::Analyser::Stats.new([analysed_file]).run
|
9
|
-
analysed_file.methods_count.must_equal 2
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when a file is empty" do
|
14
|
-
it "calculates the number of methods as 0, adding it to analysed_files" do
|
15
|
-
analysed_file = AnalysedFileDouble.new(:path => "test/samples/stats/empty_example.rb")
|
16
|
-
Rubycritic::Analyser::Stats.new([analysed_file]).run
|
17
|
-
analysed_file.methods_count.must_equal 0
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when a file is unparsable" do
|
22
|
-
it "does not blow up" do
|
23
|
-
analysed_file = AnalysedFileDouble.new(:path => "test/samples/stats/unparsable_example.rb")
|
24
|
-
capture_output_streams do
|
25
|
-
Rubycritic::Analyser::Stats.new([analysed_file]).run
|
26
|
-
end
|
27
|
-
analysed_file.methods_count.must_equal 0
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "rubycritic/core/analysed_file"
|
3
|
-
require "rubycritic/core/smell"
|
4
|
-
|
5
|
-
describe Rubycritic::AnalysedFile do
|
6
|
-
describe "attribute readers" do
|
7
|
-
before do
|
8
|
-
@pathname = Pathname.new("foo/bar.rb")
|
9
|
-
@smells = []
|
10
|
-
@churn = 1
|
11
|
-
@complexity = 2
|
12
|
-
@analysed_file = Rubycritic::AnalysedFile.new(
|
13
|
-
:pathname => @pathname,
|
14
|
-
:smells => @smells,
|
15
|
-
:churn => @churn,
|
16
|
-
:complexity => @complexity
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "has a pathname reader" do
|
21
|
-
@analysed_file.pathname.must_equal @pathname
|
22
|
-
end
|
23
|
-
|
24
|
-
it "has a smells reader" do
|
25
|
-
@analysed_file.smells.must_equal @smells
|
26
|
-
end
|
27
|
-
|
28
|
-
it "has a churn reader" do
|
29
|
-
@analysed_file.churn.must_equal @churn
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has a complexity reader" do
|
33
|
-
@analysed_file.complexity.must_equal @complexity
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has a name reader" do
|
37
|
-
@analysed_file.name.must_equal "bar"
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has a path reader" do
|
41
|
-
@analysed_file.path.must_equal @pathname.to_s
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#cost" do
|
46
|
-
it "returns the remediation cost of fixing the analysed_file" do
|
47
|
-
smells = [SmellDouble.new(:cost => 1), SmellDouble.new(:cost => 2)]
|
48
|
-
analysed_file = Rubycritic::AnalysedFile.new(:smells => smells, :complexity => 0)
|
49
|
-
analysed_file.cost.must_equal 3
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#complexity_per_method" do
|
54
|
-
context "when the file has no methods" do
|
55
|
-
it "returns a placeholder" do
|
56
|
-
analysed_file = Rubycritic::AnalysedFile.new(:complexity => 0, :methods_count => 0)
|
57
|
-
analysed_file.complexity_per_method.must_equal "N/A"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when the file has at least one method" do
|
62
|
-
it "returns the average complexity per method" do
|
63
|
-
analysed_file = Rubycritic::AnalysedFile.new(:complexity => 10, :methods_count => 2)
|
64
|
-
analysed_file.complexity_per_method.must_equal 5
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#has_smells?" do
|
70
|
-
it "returns true if the analysed_file has at least one smell" do
|
71
|
-
analysed_file = Rubycritic::AnalysedFile.new(:smells => [SmellDouble.new])
|
72
|
-
analysed_file.has_smells?.must_equal true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#smells_at_location" do
|
77
|
-
it "returns the smells of an analysed_file at a certain location" do
|
78
|
-
location = Rubycritic::Location.new("./foo", "42")
|
79
|
-
smells = [Rubycritic::Smell.new(:locations => [location])]
|
80
|
-
analysed_file = Rubycritic::AnalysedFile.new(:smells => smells)
|
81
|
-
analysed_file.smells_at_location(location).must_equal smells
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class SmellDouble < OpenStruct; end
|