rubycritic 0.0.7 → 0.0.8
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 +4 -5
- data/lib/rubycritic/location.rb +4 -0
- data/lib/rubycritic/report_generators/assets/stylesheets/application.css +100 -1
- data/lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css +1 -4
- data/lib/rubycritic/report_generators/base_generator.rb +5 -3
- data/lib/rubycritic/report_generators/{index_generator.rb → code_index_generator.rb} +4 -5
- data/lib/rubycritic/report_generators/file_generator.rb +6 -3
- data/lib/rubycritic/report_generators/reporter.rb +23 -7
- data/lib/rubycritic/report_generators/smells_index_generator.rb +27 -0
- data/lib/rubycritic/report_generators/templates/{index.html.erb → code_index.html.erb} +1 -1
- data/lib/rubycritic/report_generators/templates/file.html.erb +7 -1
- data/lib/rubycritic/report_generators/templates/layouts/application.html.erb +21 -16
- data/lib/rubycritic/report_generators/templates/smells_index.html.erb +20 -0
- data/lib/rubycritic/report_generators/view_helpers.rb +11 -2
- data/lib/rubycritic/revision_comparator.rb +12 -20
- data/lib/rubycritic/smells_aggregator.rb +0 -16
- data/lib/rubycritic/{smelly_pathnames_serializer.rb → smells_serializer.rb} +3 -5
- data/lib/rubycritic/smells_status_setter.rb +9 -12
- data/lib/rubycritic/source_control_systems/source_control_system.rb +7 -3
- data/lib/rubycritic/version.rb +1 -1
- data/test/lib/rubycritic/location_test.rb +5 -1
- data/test/lib/rubycritic/smells_aggregator_test.rb +8 -23
- data/test/lib/rubycritic/smells_status_setter_test.rb +4 -4
- data/test/lib/rubycritic/source_control_systems/source_control_system_test.rb +2 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf087d756a9bf0d14b016b82d75b675870614854
|
4
|
+
data.tar.gz: 5c17c62548734bd39a5ca405f764473b96cdd24e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0cfeef76646512463c61140b93959f5de1bc6654bc505005f74f5d560c1e5518d5cda6af6cfbcc18b81285c594aad88ae15fce0cd9ef1c143d56ee49300dc81
|
7
|
+
data.tar.gz: 957ce873afee75b3c4ae67b43d4fd2402bdc3317f7c78f0f2d36d93a0e252eb3d47101a48b83b398df38e887169f1aeafc151231217d2dd580f14316bc6527f9
|
data/lib/rubycritic.rb
CHANGED
@@ -14,13 +14,12 @@ module Rubycritic
|
|
14
14
|
|
15
15
|
def critique(paths)
|
16
16
|
source = SourceLocator.new(paths)
|
17
|
+
smell_adapters = AnalysersRunner.new(source.paths).run
|
18
|
+
smells = SmellsAggregator.new(smell_adapters).smells
|
17
19
|
if @source_control_system.has_revision?
|
18
|
-
|
19
|
-
else
|
20
|
-
smell_adapters = AnalysersRunner.new(source.paths).run
|
21
|
-
smelly_pathnames = SmellsAggregator.new(smell_adapters).smelly_pathnames
|
20
|
+
smells = RevisionComparator.new(smells, @source_control_system).smells
|
22
21
|
end
|
23
|
-
Reporter.new(source.pathnames,
|
22
|
+
Reporter.new(source.pathnames, smells).generate_report
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
data/lib/rubycritic/location.rb
CHANGED
@@ -1,8 +1,107 @@
|
|
1
|
+
.group:after {
|
2
|
+
content: '';
|
3
|
+
display: table;
|
4
|
+
clear: both;
|
5
|
+
}
|
6
|
+
|
7
|
+
html {
|
8
|
+
overflow-y: scroll;
|
9
|
+
}
|
10
|
+
|
11
|
+
.project-header {
|
12
|
+
padding: 20px 0 20px 60px;
|
13
|
+
}
|
14
|
+
|
15
|
+
.logo {
|
16
|
+
float: left;
|
17
|
+
margin: 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
.logo-link {
|
21
|
+
color: black;
|
22
|
+
text-decoration: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
.project-nav {
|
26
|
+
float: left;
|
27
|
+
margin-left: 100px;
|
28
|
+
line-height: 2.5em;
|
29
|
+
}
|
30
|
+
|
31
|
+
.project-nav-item {
|
32
|
+
color: black;
|
33
|
+
margin-right: 40px;
|
34
|
+
text-decoration: none;
|
35
|
+
}
|
36
|
+
|
37
|
+
.code-table,
|
38
|
+
.smells-table {
|
39
|
+
width: 100%;
|
40
|
+
border-collapse: collapse;
|
41
|
+
}
|
42
|
+
|
43
|
+
.code-table th,
|
44
|
+
.smells-table th {
|
45
|
+
text-align: left;
|
46
|
+
padding-bottom: 8px;
|
47
|
+
border-bottom: 1px solid silver;
|
48
|
+
font-size: 1.55em;
|
49
|
+
font-weight: normal;
|
50
|
+
}
|
51
|
+
|
52
|
+
.code-table td,
|
53
|
+
.smells-table td {
|
54
|
+
padding-top: 12px;
|
55
|
+
padding-bottom: 12px;
|
56
|
+
}
|
57
|
+
|
58
|
+
.code-table tr td:first-child,
|
59
|
+
.code-table tr th:first-child,
|
60
|
+
.smells-table tr td:first-child,
|
61
|
+
.smells-table tr th:first-child {
|
62
|
+
padding-left: 60px;
|
63
|
+
}
|
64
|
+
|
65
|
+
.button {
|
66
|
+
margin: 0;
|
67
|
+
padding: 0.5em 1em;
|
68
|
+
border: 1px solid black;
|
69
|
+
font-size: 0.9em;
|
70
|
+
border-radius: 0.2em;
|
71
|
+
cursor: pointer;
|
72
|
+
transition-property: background-color;
|
73
|
+
-webkit-transition-duration: 0.5s;
|
74
|
+
transition-duration: 0.5s;
|
75
|
+
}
|
76
|
+
|
77
|
+
.file-header {
|
78
|
+
position: relative;
|
79
|
+
padding: 0 0 10px 60px;
|
80
|
+
border-bottom: 1px solid silver;
|
81
|
+
}
|
82
|
+
|
83
|
+
.file-name {
|
84
|
+
margin: 0;
|
85
|
+
font-weight: normal;
|
86
|
+
}
|
87
|
+
|
88
|
+
.smells-toggle-button {
|
89
|
+
position: absolute;
|
90
|
+
right: 64px;
|
91
|
+
top: 22px;
|
92
|
+
border-color: silver;
|
93
|
+
background-color: #EEEBE9;
|
94
|
+
}
|
95
|
+
|
96
|
+
.smells-toggle-button:hover {
|
97
|
+
background-color: #D1CFCD;
|
98
|
+
}
|
99
|
+
|
1
100
|
.smells {
|
2
101
|
margin: 2px 0 22px 0;
|
3
102
|
padding-left: 0;
|
4
103
|
border: 1px solid #000;
|
5
|
-
background-color: #
|
104
|
+
background-color: #EEEBE9;
|
6
105
|
white-space: normal;
|
7
106
|
list-style-type: disc;
|
8
107
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "erb"
|
1
2
|
require "rubycritic/report_generators/view_helpers"
|
2
3
|
|
3
4
|
module Rubycritic
|
@@ -5,6 +6,7 @@ module Rubycritic
|
|
5
6
|
class BaseGenerator
|
6
7
|
REPORT_DIR = File.expand_path("tmp/rubycritic", Dir.getwd)
|
7
8
|
TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
|
9
|
+
LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
|
8
10
|
|
9
11
|
include ViewHelpers
|
10
12
|
|
@@ -17,15 +19,15 @@ module Rubycritic
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def file_directory
|
20
|
-
raise NotImplementedError.new("
|
22
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
21
23
|
end
|
22
24
|
|
23
25
|
def file_name
|
24
|
-
raise NotImplementedError.new("
|
26
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
25
27
|
end
|
26
28
|
|
27
29
|
def render
|
28
|
-
raise NotImplementedError.new("
|
30
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
29
31
|
end
|
30
32
|
|
31
33
|
def get_binding
|
@@ -3,9 +3,8 @@ require "rubycritic/report_generators/base_generator"
|
|
3
3
|
|
4
4
|
module Rubycritic
|
5
5
|
|
6
|
-
class
|
7
|
-
|
8
|
-
LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
|
6
|
+
class CodeIndexGenerator < BaseGenerator
|
7
|
+
TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "code_index.html.erb")))
|
9
8
|
|
10
9
|
def initialize(file_generators)
|
11
10
|
@file_generators = file_generators.sort { |a, b| a.analysed_file_name <=> b.analysed_file_name }
|
@@ -16,11 +15,11 @@ module Rubycritic
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def file_name
|
19
|
-
"
|
18
|
+
"code_index.html"
|
20
19
|
end
|
21
20
|
|
22
21
|
def render
|
23
|
-
index_body =
|
22
|
+
index_body = TEMPLATE.result(get_binding)
|
24
23
|
LAYOUT_TEMPLATE.result(get_binding { index_body })
|
25
24
|
end
|
26
25
|
end
|
@@ -6,8 +6,7 @@ module Rubycritic
|
|
6
6
|
|
7
7
|
class FileGenerator < BaseGenerator
|
8
8
|
LINE_NUMBER_OFFSET = 1
|
9
|
-
|
10
|
-
LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
|
9
|
+
TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "file.html.erb")))
|
11
10
|
|
12
11
|
def initialize(pathname, smells)
|
13
12
|
@pathname = pathname
|
@@ -34,9 +33,13 @@ module Rubycritic
|
|
34
33
|
file_code << LineGenerator.new(line_text, line_smells).render
|
35
34
|
end
|
36
35
|
|
37
|
-
file_body =
|
36
|
+
file_body = TEMPLATE.result(get_binding { file_code })
|
38
37
|
LAYOUT_TEMPLATE.result(get_binding { file_body })
|
39
38
|
end
|
39
|
+
|
40
|
+
def file_has_smells?
|
41
|
+
!@smells.empty?
|
42
|
+
end
|
40
43
|
end
|
41
44
|
|
42
45
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rubycritic/report_generators/base_generator"
|
2
2
|
require "rubycritic/report_generators/file_generator"
|
3
|
-
require "rubycritic/report_generators/
|
3
|
+
require "rubycritic/report_generators/code_index_generator"
|
4
|
+
require "rubycritic/report_generators/smells_index_generator"
|
4
5
|
require "fileutils"
|
5
6
|
|
6
7
|
module Rubycritic
|
@@ -8,9 +9,10 @@ module Rubycritic
|
|
8
9
|
class Reporter
|
9
10
|
ASSETS_DIR = File.expand_path("../assets", __FILE__)
|
10
11
|
|
11
|
-
def initialize(source_pathnames,
|
12
|
+
def initialize(source_pathnames, smells)
|
12
13
|
@source_pathnames = source_pathnames
|
13
|
-
@
|
14
|
+
@smells = smells
|
15
|
+
@smelly_pathnames = pathnames_to_files_with_smells
|
14
16
|
end
|
15
17
|
|
16
18
|
def generate_report
|
@@ -21,17 +23,21 @@ module Rubycritic
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
FileUtils.cp_r(ASSETS_DIR, BaseGenerator::REPORT_DIR)
|
24
|
-
|
26
|
+
code_index_generator.file_href
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
31
|
def generators
|
30
|
-
|
32
|
+
[code_index_generator, smells_index_generator] + file_generators
|
31
33
|
end
|
32
34
|
|
33
|
-
def
|
34
|
-
@
|
35
|
+
def code_index_generator
|
36
|
+
@code_index_generator ||= CodeIndexGenerator.new(file_generators)
|
37
|
+
end
|
38
|
+
|
39
|
+
def smells_index_generator
|
40
|
+
@smells_index_generator ||= SmellsIndexGenerator.new(@smells)
|
35
41
|
end
|
36
42
|
|
37
43
|
def file_generators
|
@@ -40,6 +46,16 @@ module Rubycritic
|
|
40
46
|
FileGenerator.new(file_pathname, file_smells)
|
41
47
|
end
|
42
48
|
end
|
49
|
+
|
50
|
+
def pathnames_to_files_with_smells
|
51
|
+
pathnames = Hash.new { |hash, key| hash[key] = [] }
|
52
|
+
@smells.each do |smell|
|
53
|
+
smell.pathnames.each do |path|
|
54
|
+
pathnames[path] << smell
|
55
|
+
end
|
56
|
+
end
|
57
|
+
pathnames
|
58
|
+
end
|
43
59
|
end
|
44
60
|
|
45
61
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "rubycritic/report_generators/base_generator"
|
3
|
+
|
4
|
+
module Rubycritic
|
5
|
+
|
6
|
+
class SmellsIndexGenerator < BaseGenerator
|
7
|
+
TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "smells_index.html.erb")))
|
8
|
+
|
9
|
+
def initialize(smells)
|
10
|
+
@smells = smells.sort { |a, b| a.type <=> b.type }
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_directory
|
14
|
+
REPORT_DIR
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_name
|
18
|
+
"smells_index.html"
|
19
|
+
end
|
20
|
+
|
21
|
+
def render
|
22
|
+
index_body = TEMPLATE.result(get_binding)
|
23
|
+
LAYOUT_TEMPLATE.result(get_binding { index_body })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -1,3 +1,9 @@
|
|
1
|
-
<
|
1
|
+
<div class="file-header">
|
2
|
+
<h2 class="file-name"><%= analysed_file_name %></h2>
|
3
|
+
|
4
|
+
<% if file_has_smells? %>
|
5
|
+
<button id="js-toggle-smells" class="smells-toggle-button button">Toggle Smells</button>
|
6
|
+
<% end %>
|
7
|
+
</div>
|
2
8
|
|
3
9
|
<code class="prettyprint linenums lang-ruby file-code js-file-code"><%= yield %></code>
|
@@ -1,19 +1,24 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<
|
13
|
-
|
14
|
-
|
15
|
-
<
|
16
|
-
<
|
17
|
-
|
18
|
-
</
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
|
+
<title>Ruby Critic</title>
|
7
|
+
<link href="<%= stylesheet_path(:application) %>" media="screen, projection, print" rel="stylesheet" type="text/css">
|
8
|
+
<link href="<%= stylesheet_path(:'prettify.custom_theme') %>" media="screen, projection, print" rel="stylesheet" type="text/css">
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<header class="project-header group">
|
13
|
+
<h1 class="logo"><a href="<%= code_index_path %>" class="logo-link">Ruby Critic</a></h1>
|
14
|
+
<nav class="project-nav">
|
15
|
+
<a href="<%= code_index_path %>" class="project-nav-item">Code</a>
|
16
|
+
<a href="<%= smells_index_path %>" class="project-nav-item">Smells</a>
|
17
|
+
</nav>
|
18
|
+
</header>
|
19
|
+
<%= yield %>
|
20
|
+
<script src="<%= javascript_path(:'jquery-2.1.0') %>"></script>
|
21
|
+
<script src="<%= javascript_path(:prettify) %>"></script>
|
22
|
+
<script src="<%= javascript_path(:application) %>"></script>
|
23
|
+
</body>
|
19
24
|
</html>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<table class="smells-table">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>Smell</th>
|
5
|
+
<th>Locations</th>
|
6
|
+
</tr>
|
7
|
+
</thead>
|
8
|
+
<tbody>
|
9
|
+
<% @smells.each do |smell| %>
|
10
|
+
<tr>
|
11
|
+
<td><%= smell.type %></td>
|
12
|
+
<td>
|
13
|
+
<% smell.locations.each do |location| %>
|
14
|
+
<a href="<%= smell_location_path(location) %>"><%= location.file_name %></a>
|
15
|
+
<% end %>
|
16
|
+
</td>
|
17
|
+
</tr>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
@@ -18,8 +18,17 @@ module Rubycritic
|
|
18
18
|
File.join(root_directory, "#{pathname.sub_ext('.html')}#L#{location.line}")
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
File.join(root_directory, "
|
21
|
+
def code_index_path
|
22
|
+
File.join(root_directory, "code_index.html")
|
23
|
+
end
|
24
|
+
|
25
|
+
def smells_index_path
|
26
|
+
File.join(root_directory, "smells_index.html")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Includers must override
|
30
|
+
def root_directory
|
31
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "rubycritic/
|
1
|
+
require "rubycritic/smells_serializer"
|
2
2
|
require "rubycritic/source_locator"
|
3
3
|
require "rubycritic/analysers_runner"
|
4
4
|
require "rubycritic/smells_aggregator"
|
@@ -9,40 +9,32 @@ module Rubycritic
|
|
9
9
|
class RevisionComparator
|
10
10
|
SNAPSHOTS_DIR = File.expand_path("tmp/rubycritic/snapshots", Dir.getwd)
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@
|
12
|
+
def initialize(smells, source_control_system)
|
13
|
+
@smells_now = smells
|
14
14
|
@source_control_system = source_control_system
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
SmellsStatusSetter.new(
|
17
|
+
def smells
|
18
|
+
SmellsStatusSetter.new(smells_before, @smells_now).smells
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def
|
24
|
-
serializer =
|
23
|
+
def smells_before
|
24
|
+
serializer = SmellsSerializer.new(revision_file)
|
25
25
|
if File.file?(revision_file)
|
26
26
|
serializer.load
|
27
27
|
else
|
28
|
-
|
28
|
+
smells = nil
|
29
29
|
@source_control_system.travel_to_head do
|
30
|
-
|
30
|
+
smell_adapters = AnalysersRunner.new(paths_of_tracked_files).run
|
31
|
+
smells = SmellsAggregator.new(smell_adapters).smells
|
31
32
|
end
|
32
|
-
serializer.dump(
|
33
|
-
|
33
|
+
serializer.dump(smells)
|
34
|
+
smells
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def smelly_pathnames_now
|
38
|
-
smelly_pathnames(@paths)
|
39
|
-
end
|
40
|
-
|
41
|
-
def smelly_pathnames(paths)
|
42
|
-
smell_adapters = AnalysersRunner.new(paths).run
|
43
|
-
SmellsAggregator.new(smell_adapters).smelly_pathnames
|
44
|
-
end
|
45
|
-
|
46
38
|
def revision_file
|
47
39
|
@revision_file ||= File.join(SNAPSHOTS_DIR, @source_control_system.head_reference)
|
48
40
|
end
|
@@ -8,22 +8,6 @@ module Rubycritic
|
|
8
8
|
def smells
|
9
9
|
@smells ||= @smell_adapters.map(&:smells).flatten.sort
|
10
10
|
end
|
11
|
-
|
12
|
-
def smelly_pathnames
|
13
|
-
@smelly_pathnames ||= pathnames_to_files_with_smells
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def pathnames_to_files_with_smells
|
19
|
-
pathnames = Hash.new { |hash, key| hash[key] = [] }
|
20
|
-
smells.each do |smell|
|
21
|
-
smell.pathnames.each do |path|
|
22
|
-
pathnames[path] << smell
|
23
|
-
end
|
24
|
-
end
|
25
|
-
pathnames
|
26
|
-
end
|
27
11
|
end
|
28
12
|
|
29
13
|
end
|
@@ -2,7 +2,7 @@ require "fileutils"
|
|
2
2
|
|
3
3
|
module Rubycritic
|
4
4
|
|
5
|
-
class
|
5
|
+
class SmellsSerializer
|
6
6
|
def initialize(file_name)
|
7
7
|
@file_name = file_name
|
8
8
|
end
|
@@ -11,12 +11,10 @@ module Rubycritic
|
|
11
11
|
Marshal.load(File.binread(@file_name))
|
12
12
|
end
|
13
13
|
|
14
|
-
def dump(
|
14
|
+
def dump(smells)
|
15
15
|
create_file_directory
|
16
|
-
# HACK It's not possible to Marshal procs or lambdas.
|
17
|
-
smelly_pathnames.default = []
|
18
16
|
File.open(@file_name, "w+") do |file|
|
19
|
-
Marshal.dump(
|
17
|
+
Marshal.dump(smells, file)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -1,20 +1,17 @@
|
|
1
1
|
module Rubycritic
|
2
2
|
|
3
3
|
class SmellsStatusSetter
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@
|
4
|
+
def initialize(smells_before, smells_now)
|
5
|
+
@smells_before = smells_before || []
|
6
|
+
@smells_now = smells_now
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
set_status(new_smells, :new)
|
16
|
-
end
|
17
|
-
@smelly_pathnames_now
|
9
|
+
def smells
|
10
|
+
old_smells = @smells_now & @smells_before
|
11
|
+
set_status(old_smells, :old)
|
12
|
+
new_smells = @smells_now - @smells_before
|
13
|
+
set_status(new_smells, :new)
|
14
|
+
@smells_now
|
18
15
|
end
|
19
16
|
|
20
17
|
private
|
@@ -24,16 +24,20 @@ module Rubycritic
|
|
24
24
|
systems.join(", ")
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.supported?
|
28
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
29
|
+
end
|
30
|
+
|
27
31
|
def has_revision?
|
28
|
-
raise NotImplementedError.new("
|
32
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
29
33
|
end
|
30
34
|
|
31
35
|
def head_reference
|
32
|
-
raise NotImplementedError.new("
|
36
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
33
37
|
end
|
34
38
|
|
35
39
|
def travel_to_head
|
36
|
-
raise NotImplementedError.new("
|
40
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
data/lib/rubycritic/version.rb
CHANGED
@@ -4,7 +4,7 @@ require "rubycritic/location"
|
|
4
4
|
describe Rubycritic::Location do
|
5
5
|
describe "attribute readers" do
|
6
6
|
before do
|
7
|
-
@path = "./foo"
|
7
|
+
@path = "./foo.rb"
|
8
8
|
@line = 42
|
9
9
|
@location = Rubycritic::Location.new(@path, @line)
|
10
10
|
end
|
@@ -16,6 +16,10 @@ describe Rubycritic::Location do
|
|
16
16
|
it "has a line number" do
|
17
17
|
@location.line.must_equal @line
|
18
18
|
end
|
19
|
+
|
20
|
+
it "has a file name" do
|
21
|
+
@location.file_name.must_equal "foo"
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
it "is comparable" do
|
@@ -4,43 +4,28 @@ require "rubycritic/smells_aggregator"
|
|
4
4
|
describe Rubycritic::SmellsAggregator do
|
5
5
|
context "when analysing smelly files" do
|
6
6
|
before do
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@smell2 = Rubycritic::Smell.new(:locations => [@location2, @location3])
|
12
|
-
@smell_adapters = [stub(:smells => [@smell1]), stub(:smells => [@smell2])]
|
7
|
+
smell1 = Rubycritic::Smell.new
|
8
|
+
smell2 = Rubycritic::Smell.new
|
9
|
+
@smells = [smell2, smell1]
|
10
|
+
@smell_adapters = [stub(:smells => [smell1]), stub(:smells => [smell2])]
|
13
11
|
end
|
14
12
|
|
15
13
|
describe "#smells" do
|
16
14
|
it "returns the smells found in those files" do
|
17
|
-
smells
|
18
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal smells
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#smelly_pathnames" do
|
23
|
-
it "returns the files where smells were found" do
|
24
|
-
smelly_pathnames = {@location1.pathname => [@smell1], @location2.pathname => [@smell2]}
|
25
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smelly_pathnames.must_equal smelly_pathnames
|
15
|
+
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal @smells
|
26
16
|
end
|
27
17
|
end
|
28
18
|
end
|
29
19
|
|
30
20
|
context "when analysing files with no smells" do
|
31
21
|
before do
|
32
|
-
@
|
22
|
+
@smells = []
|
23
|
+
@smell_adapters = [stub(:smells => @smells)]
|
33
24
|
end
|
34
25
|
|
35
26
|
describe "#smells" do
|
36
27
|
it "returns an empty array" do
|
37
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#smelly_pathnames" do
|
42
|
-
it "returns an empty hash" do
|
43
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smelly_pathnames.must_equal({})
|
28
|
+
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal @smells
|
44
29
|
end
|
45
30
|
end
|
46
31
|
end
|
@@ -3,19 +3,19 @@ require "rubycritic/smell"
|
|
3
3
|
require "rubycritic/smells_status_setter"
|
4
4
|
|
5
5
|
describe Rubycritic::SmellsStatusSetter do
|
6
|
-
describe "#
|
6
|
+
describe "#smells" do
|
7
7
|
before do
|
8
8
|
@smell = Rubycritic::Smell.new(:context => "#bar")
|
9
|
-
@
|
9
|
+
@smells = [@smell]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "marks old smells" do
|
13
|
-
Rubycritic::SmellsStatusSetter.new(@
|
13
|
+
Rubycritic::SmellsStatusSetter.new(@smells, @smells).smells
|
14
14
|
@smell.status.must_equal :old
|
15
15
|
end
|
16
16
|
|
17
17
|
it "marks new smells" do
|
18
|
-
Rubycritic::SmellsStatusSetter.new(
|
18
|
+
Rubycritic::SmellsStatusSetter.new([], @smells).smells
|
19
19
|
@smell.status.must_equal :new
|
20
20
|
end
|
21
21
|
end
|
@@ -19,7 +19,8 @@ describe Rubycritic::SourceControlSystem do
|
|
19
19
|
|
20
20
|
describe "when no source control system is found" do
|
21
21
|
it "raises an error" do
|
22
|
-
proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
|
22
|
+
error = proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
|
23
|
+
error.message.must_match "Rubycritic requires a Git repository."
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycritic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Simoes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -154,14 +154,16 @@ files:
|
|
154
154
|
- lib/rubycritic/report_generators/assets/stylesheets/application.css
|
155
155
|
- lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css
|
156
156
|
- lib/rubycritic/report_generators/base_generator.rb
|
157
|
+
- lib/rubycritic/report_generators/code_index_generator.rb
|
157
158
|
- lib/rubycritic/report_generators/file_generator.rb
|
158
|
-
- lib/rubycritic/report_generators/index_generator.rb
|
159
159
|
- lib/rubycritic/report_generators/line_generator.rb
|
160
160
|
- lib/rubycritic/report_generators/reporter.rb
|
161
|
+
- lib/rubycritic/report_generators/smells_index_generator.rb
|
162
|
+
- lib/rubycritic/report_generators/templates/code_index.html.erb
|
161
163
|
- lib/rubycritic/report_generators/templates/file.html.erb
|
162
|
-
- lib/rubycritic/report_generators/templates/index.html.erb
|
163
164
|
- lib/rubycritic/report_generators/templates/layouts/application.html.erb
|
164
165
|
- lib/rubycritic/report_generators/templates/line.html.erb
|
166
|
+
- lib/rubycritic/report_generators/templates/smells_index.html.erb
|
165
167
|
- lib/rubycritic/report_generators/templates/smelly_line.html.erb
|
166
168
|
- lib/rubycritic/report_generators/view_helpers.rb
|
167
169
|
- lib/rubycritic/revision_comparator.rb
|
@@ -170,8 +172,8 @@ files:
|
|
170
172
|
- lib/rubycritic/smell_adapters/flog.rb
|
171
173
|
- lib/rubycritic/smell_adapters/reek.rb
|
172
174
|
- lib/rubycritic/smells_aggregator.rb
|
175
|
+
- lib/rubycritic/smells_serializer.rb
|
173
176
|
- lib/rubycritic/smells_status_setter.rb
|
174
|
-
- lib/rubycritic/smelly_pathnames_serializer.rb
|
175
177
|
- lib/rubycritic/source_control_systems/git.rb
|
176
178
|
- lib/rubycritic/source_control_systems/source_control_system.rb
|
177
179
|
- lib/rubycritic/source_locator.rb
|