rubycritic 0.0.12 → 0.0.13
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/lib/rubycritic.rb +3 -22
- data/lib/rubycritic/adapters/complexity/flog.rb +1 -1
- data/lib/rubycritic/adapters/smell/flay.rb +1 -1
- data/lib/rubycritic/adapters/smell/flog.rb +1 -1
- data/lib/rubycritic/adapters/smell/reek.rb +1 -1
- data/lib/rubycritic/analysed_files_builder.rb +36 -0
- data/lib/rubycritic/analysers/config.reek +6 -2
- data/lib/rubycritic/analysers_runner.rb +2 -2
- data/lib/rubycritic/cli.rb +2 -1
- data/lib/rubycritic/core/analysed_file.rb +22 -0
- data/lib/rubycritic/{location.rb → core/location.rb} +0 -0
- data/lib/rubycritic/{smell.rb → core/smell.rb} +10 -4
- data/lib/rubycritic/orchestrators/base.rb +27 -0
- data/lib/rubycritic/orchestrators/main.rb +14 -0
- data/lib/rubycritic/orchestrators/mini.rb +14 -0
- data/lib/rubycritic/report_generators/assets/javascripts/application.js +2 -9
- data/lib/rubycritic/report_generators/base.rb +43 -0
- data/lib/rubycritic/report_generators/code_file.rb +40 -0
- data/lib/rubycritic/report_generators/code_index.rb +29 -0
- data/lib/rubycritic/report_generators/line.rb +29 -0
- data/lib/rubycritic/report_generators/overview.rb +26 -0
- data/lib/rubycritic/report_generators/smells_index.rb +25 -0
- data/lib/rubycritic/report_generators/templates/{file.html.erb → code_file.html.erb} +2 -2
- data/lib/rubycritic/report_generators/templates/code_index.html.erb +3 -3
- data/lib/rubycritic/report_generators/templates/smells_index.html.erb +1 -1
- data/lib/rubycritic/report_generators/view_helpers.rb +0 -4
- data/lib/rubycritic/reporters/main.rb +55 -0
- data/lib/rubycritic/reporters/mini.rb +26 -0
- data/lib/rubycritic/revision_comparator.rb +1 -1
- data/lib/rubycritic/source_locator.rb +4 -4
- data/lib/rubycritic/turbulence.rb +8 -18
- data/lib/rubycritic/version.rb +1 -1
- data/test/lib/rubycritic/{quality_adapters → adapters/complexity}/flog_test.rb +2 -2
- data/test/lib/rubycritic/{smell_adapters → adapters/smell}/flay_test.rb +2 -2
- data/test/lib/rubycritic/{smell_adapters → adapters/smell}/flog_test.rb +0 -0
- data/test/lib/rubycritic/{smell_adapters → adapters/smell}/reek_test.rb +0 -0
- data/test/lib/rubycritic/analysed_files_builder_test.rb +36 -0
- data/test/lib/rubycritic/analysers_runner_test.rb +2 -2
- data/test/lib/rubycritic/core/analysed_file_test.rb +51 -0
- data/test/lib/rubycritic/{location_test.rb → core/location_test.rb} +1 -1
- data/test/lib/rubycritic/core/smell_test.rb +80 -0
- data/test/lib/rubycritic/{smells_array_test.rb → core/smells_array_test.rb} +1 -1
- data/test/lib/rubycritic/smells_status_setter_test.rb +1 -1
- data/test/lib/rubycritic/turbulence_test.rb +9 -18
- data/test/samples/reek/not_smelly.rb +10 -1
- metadata +36 -26
- data/lib/rubycritic/report_generators/base_generator.rb +0 -41
- data/lib/rubycritic/report_generators/code_index_generator.rb +0 -32
- data/lib/rubycritic/report_generators/file_generator.rb +0 -41
- data/lib/rubycritic/report_generators/line_generator.rb +0 -27
- data/lib/rubycritic/report_generators/overview_generator.rb +0 -24
- data/lib/rubycritic/report_generators/reporter.rb +0 -67
- data/lib/rubycritic/report_generators/smells_index_generator.rb +0 -23
- data/test/lib/rubycritic/smell_test.rb +0 -71
@@ -0,0 +1,26 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "rubycritic/report_generators/base"
|
3
|
+
require "rubycritic/turbulence"
|
4
|
+
|
5
|
+
module Rubycritic
|
6
|
+
module Generator
|
7
|
+
|
8
|
+
class Overview < Base
|
9
|
+
TEMPLATE = erb_template("overview.html.erb")
|
10
|
+
|
11
|
+
def initialize(analysed_files)
|
12
|
+
@turbulence_data = Turbulence.new(analysed_files).data
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_name
|
16
|
+
"overview.html"
|
17
|
+
end
|
18
|
+
|
19
|
+
def render
|
20
|
+
index_body = TEMPLATE.result(get_binding)
|
21
|
+
LAYOUT_TEMPLATE.result(get_binding { index_body })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "rubycritic/report_generators/base"
|
3
|
+
|
4
|
+
module Rubycritic
|
5
|
+
module Generator
|
6
|
+
|
7
|
+
class SmellsIndex < Base
|
8
|
+
TEMPLATE = erb_template("smells_index.html.erb")
|
9
|
+
|
10
|
+
def initialize(smells)
|
11
|
+
@smells = smells
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_name
|
15
|
+
"smells_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
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="file-header">
|
2
|
-
<h2 class="file-name"><%=
|
2
|
+
<h2 class="file-name"><%= @analysed_file.name %></h2>
|
3
3
|
|
4
|
-
<% if
|
4
|
+
<% if @analysed_file.has_smells? %>
|
5
5
|
<button id="js-toggle-smells" class="smells-toggle-button button">Toggle Smells</button>
|
6
6
|
<% end %>
|
7
7
|
</div>
|
@@ -6,12 +6,12 @@
|
|
6
6
|
</tr>
|
7
7
|
</thead>
|
8
8
|
<tbody>
|
9
|
-
<% @
|
9
|
+
<% @analysed_files.each do |analysed_file| %>
|
10
10
|
<tr>
|
11
11
|
<td class="first-cell">
|
12
|
-
<a href="<%= file_path(pathname) %>"><%=
|
12
|
+
<a href="<%= file_path(analysed_file.pathname) %>"><%= analysed_file.name %></a>
|
13
13
|
</td>
|
14
|
-
<td><%=
|
14
|
+
<td><%= analysed_file.smells.length %></td>
|
15
15
|
</tr>
|
16
16
|
<% end %>
|
17
17
|
</tbody>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "rubycritic/report_generators/overview"
|
2
|
+
require "rubycritic/report_generators/smells_index"
|
3
|
+
require "rubycritic/report_generators/code_index"
|
4
|
+
require "rubycritic/report_generators/code_file"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
module Rubycritic
|
8
|
+
module Reporter
|
9
|
+
|
10
|
+
class Main
|
11
|
+
ASSETS_DIR = File.expand_path("../../report_generators/assets", __FILE__)
|
12
|
+
|
13
|
+
def initialize(analysed_files, smells)
|
14
|
+
@analysed_files = analysed_files
|
15
|
+
@smells = smells
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_report
|
19
|
+
generators.each do |generator|
|
20
|
+
FileUtils.mkdir_p(generator.file_directory)
|
21
|
+
File.open(generator.file_pathname, "w+") do |file|
|
22
|
+
file.write(generator.render)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
FileUtils.cp_r(ASSETS_DIR, ::Rubycritic.configuration.root)
|
26
|
+
overview_generator.file_href
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generators
|
32
|
+
[overview_generator, code_index_generator, smells_index_generator] + file_generators
|
33
|
+
end
|
34
|
+
|
35
|
+
def overview_generator
|
36
|
+
@overview_generator ||= Generator::Overview.new(@analysed_files)
|
37
|
+
end
|
38
|
+
|
39
|
+
def code_index_generator
|
40
|
+
Generator::CodeIndex.new(@analysed_files)
|
41
|
+
end
|
42
|
+
|
43
|
+
def smells_index_generator
|
44
|
+
Generator::SmellsIndex.new(@smells)
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_generators
|
48
|
+
@analysed_files.map do |analysed_file|
|
49
|
+
Generator::CodeFile.new(analysed_file)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rubycritic/report_generators/code_file"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module Rubycritic
|
5
|
+
module Reporter
|
6
|
+
|
7
|
+
class Mini
|
8
|
+
ASSETS_DIR = File.expand_path("../../report_generators/assets", __FILE__)
|
9
|
+
|
10
|
+
def initialize(analysed_file)
|
11
|
+
@analysed_file = analysed_file
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_report
|
15
|
+
file_generator = Generator::CodeFile.new(@analysed_file)
|
16
|
+
FileUtils.mkdir_p(file_generator.file_directory)
|
17
|
+
File.open(file_generator.file_pathname, "w+") do |file|
|
18
|
+
file.write(file_generator.render)
|
19
|
+
end
|
20
|
+
FileUtils.cp_r(ASSETS_DIR, ::Rubycritic.configuration.root)
|
21
|
+
file_generator.file_href
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -10,14 +10,14 @@ module Rubycritic
|
|
10
10
|
@initial_paths = paths
|
11
11
|
end
|
12
12
|
|
13
|
-
def pathnames
|
14
|
-
@pathnames ||= expand_paths
|
15
|
-
end
|
16
|
-
|
17
13
|
def paths
|
18
14
|
@paths ||= pathnames.map(&:to_s)
|
19
15
|
end
|
20
16
|
|
17
|
+
def pathnames
|
18
|
+
@pathnames ||= expand_paths
|
19
|
+
end
|
20
|
+
|
21
21
|
private
|
22
22
|
|
23
23
|
def expand_paths
|
@@ -1,30 +1,20 @@
|
|
1
|
-
require "
|
2
|
-
require "rubycritic/adapters/complexity/flog"
|
1
|
+
require "json"
|
3
2
|
|
4
3
|
module Rubycritic
|
5
4
|
|
6
5
|
class Turbulence
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@source_control_system = source_control_system
|
6
|
+
def initialize(analysed_files)
|
7
|
+
@analysed_files = analysed_files
|
10
8
|
end
|
11
9
|
|
12
10
|
def data
|
13
|
-
@
|
11
|
+
@analysed_files.map do |analysed_file|
|
14
12
|
{
|
15
|
-
:name =>
|
16
|
-
:x =>
|
17
|
-
:y =>
|
13
|
+
:name => analysed_file.pathname,
|
14
|
+
:x => analysed_file.churn,
|
15
|
+
:y => analysed_file.complexity
|
18
16
|
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def churn
|
23
|
-
@churn ||= Analyser::Churn.new(@paths, @source_control_system).churn
|
24
|
-
end
|
25
|
-
|
26
|
-
def complexity
|
27
|
-
@complexity ||= QualityAdapter::Flog.new(@paths).complexity
|
17
|
+
end.to_json
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
data/lib/rubycritic/version.rb
CHANGED
@@ -2,10 +2,10 @@ require "test_helper"
|
|
2
2
|
require "rubycritic/analysers/flog"
|
3
3
|
require "rubycritic/adapters/complexity/flog"
|
4
4
|
|
5
|
-
describe Rubycritic::
|
5
|
+
describe Rubycritic::ComplexityAdapter::Flog do
|
6
6
|
before do
|
7
7
|
sample_paths = ["test/samples/flog/smelly.rb", "test/samples/flog/smelly2.rb"]
|
8
|
-
@adapter = Rubycritic::
|
8
|
+
@adapter = Rubycritic::ComplexityAdapter::Flog.new(sample_paths)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#complexity" do
|
@@ -13,10 +13,10 @@ describe Rubycritic::SmellAdapter::Flay do
|
|
13
13
|
|
14
14
|
it "has smells with messages" do
|
15
15
|
smell = @adapter.smells.first
|
16
|
-
smell.message.
|
16
|
+
smell.message.must_be_instance_of String
|
17
17
|
end
|
18
18
|
|
19
|
-
it "has smells with
|
19
|
+
it "has smells with scores" do
|
20
20
|
smell = @adapter.smells.first
|
21
21
|
smell.score.must_be_kind_of Numeric
|
22
22
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rubycritic/analysed_files_builder"
|
3
|
+
|
4
|
+
describe Rubycritic::AnalysedFilesBuilder do
|
5
|
+
describe "analysed_files" do
|
6
|
+
before do
|
7
|
+
@pathnames = [Pathname.new("./foo"), Pathname.new("./bar")]
|
8
|
+
@smells = [SmellDouble.new]
|
9
|
+
@churn = [1, 2]
|
10
|
+
@complexity = [3, 4]
|
11
|
+
@builder = Rubycritic::AnalysedFilesBuilder.new(@pathnames, @smells, @churn, @complexity)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an array of AnalysedFiles" do
|
15
|
+
analysed_files = @builder.analysed_files
|
16
|
+
first = analysed_files.first
|
17
|
+
last = analysed_files.last
|
18
|
+
|
19
|
+
first.pathname.must_equal Pathname.new("./foo")
|
20
|
+
first.smells.must_equal @smells
|
21
|
+
first.churn.must_equal @churn.first
|
22
|
+
first.complexity.must_equal @complexity.first
|
23
|
+
|
24
|
+
last.pathname.must_equal Pathname.new("./bar")
|
25
|
+
last.smells.must_equal @smells
|
26
|
+
last.churn.must_equal @churn.last
|
27
|
+
last.complexity.must_equal @complexity.last
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SmellDouble
|
33
|
+
def at_pathname?(other_pathname)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
@@ -2,9 +2,9 @@ require "test_helper"
|
|
2
2
|
require "rubycritic/analysers_runner"
|
3
3
|
|
4
4
|
describe Rubycritic::AnalysersRunner do
|
5
|
-
describe "#
|
5
|
+
describe "#smells" do
|
6
6
|
it "returns the smells found by various analysers" do
|
7
|
-
smells = Rubycritic::AnalysersRunner.new("test/samples/analysers_runner/empty.rb").
|
7
|
+
smells = Rubycritic::AnalysersRunner.new("test/samples/analysers_runner/empty.rb").smells
|
8
8
|
smells.must_be_instance_of Array
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rubycritic/core/analysed_file"
|
3
|
+
|
4
|
+
describe Rubycritic::AnalysedFile do
|
5
|
+
describe "attribute readers" do
|
6
|
+
before do
|
7
|
+
@pathname = Pathname.new("./foo")
|
8
|
+
@smells = []
|
9
|
+
@churn = 1
|
10
|
+
@complexity = 2
|
11
|
+
@smell = Rubycritic::AnalysedFile.new(
|
12
|
+
:pathname => @pathname,
|
13
|
+
:smells => @smells,
|
14
|
+
:churn => @churn,
|
15
|
+
:complexity => @complexity
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a pathname reader" do
|
20
|
+
@smell.pathname.must_equal @pathname
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a smells reader" do
|
24
|
+
@smell.smells.must_equal @smells
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a churn reader" do
|
28
|
+
@smell.churn.must_equal @churn
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a complexity reader" do
|
32
|
+
@smell.complexity.must_equal @complexity
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#name" do
|
37
|
+
it "returns the name of the file" do
|
38
|
+
analysed_file = Rubycritic::AnalysedFile.new(:pathname => Pathname.new("foo/bar.rb"))
|
39
|
+
analysed_file.name.must_equal "bar"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#has_smells?" do
|
44
|
+
it "returns true if the analysed_file has at least one smell" do
|
45
|
+
analysed_file = Rubycritic::AnalysedFile.new(:smells => [SmellDouble.new])
|
46
|
+
analysed_file.has_smells?.must_equal true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class SmellDouble; end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rubycritic/core/smell"
|
3
|
+
|
4
|
+
describe Rubycritic::Smell do
|
5
|
+
describe "attribute readers" do
|
6
|
+
before do
|
7
|
+
@locations = [Rubycritic::Location.new("./foo", "42")]
|
8
|
+
@context = "#bar"
|
9
|
+
@message = "This smells"
|
10
|
+
@score = 0
|
11
|
+
@type = :complexity
|
12
|
+
@smell = Rubycritic::Smell.new(
|
13
|
+
:locations => @locations,
|
14
|
+
:context => @context,
|
15
|
+
:message => @message,
|
16
|
+
:score => @score,
|
17
|
+
:type => @type
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has a context reader" do
|
22
|
+
@smell.context.must_equal @context
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a locations reader" do
|
26
|
+
@smell.locations.must_equal @locations
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a message reader" do
|
30
|
+
@smell.message.must_equal @message
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has a score reader" do
|
34
|
+
@smell.score.must_equal @score
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a type reader" do
|
38
|
+
@smell.type.must_equal @type
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#at_location?" do
|
43
|
+
it "returns true if the smell has a location that matches the location passed as argument" do
|
44
|
+
location = Rubycritic::Location.new("./foo", "42")
|
45
|
+
smell = Rubycritic::Smell.new(:locations => [location])
|
46
|
+
smell.at_location?(location).must_equal true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#at_pathname?" do
|
51
|
+
it "returns true if the smell has a pathname that matches the pathname passed as argument" do
|
52
|
+
path = "./foo"
|
53
|
+
pathname = Pathname.new(path)
|
54
|
+
location = Rubycritic::Location.new(path, "42")
|
55
|
+
smell = Rubycritic::Smell.new(:locations => [location])
|
56
|
+
smell.at_pathname?(pathname).must_equal true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#has_multiple_locations?" do
|
61
|
+
it "returns true if the smell has more than one location" do
|
62
|
+
location1 = Rubycritic::Location.new("./foo", "42")
|
63
|
+
location2 = Rubycritic::Location.new("./foo", "23")
|
64
|
+
smell = Rubycritic::Smell.new(:locations => [location1, location2])
|
65
|
+
smell.has_multiple_locations?.must_equal true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is comparable" do
|
70
|
+
attributes = {
|
71
|
+
:context => "#bar",
|
72
|
+
:message => "This smells",
|
73
|
+
:score => 0,
|
74
|
+
:type => :complexity
|
75
|
+
}
|
76
|
+
smell1 = Rubycritic::Smell.new(attributes)
|
77
|
+
smell2 = Rubycritic::Smell.new(attributes)
|
78
|
+
smell1.must_equal smell2
|
79
|
+
end
|
80
|
+
end
|