rubycritic 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubycritic/location.rb +1 -9
- data/lib/rubycritic/report_generators/assets/javascripts/application.js +18 -0
- data/lib/rubycritic/report_generators/assets/javascripts/prettify.js +8 -1
- data/lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css +4 -0
- data/lib/rubycritic/report_generators/base_generator.rb +10 -12
- data/lib/rubycritic/report_generators/file_generator.rb +3 -3
- data/lib/rubycritic/report_generators/index_generator.rb +2 -2
- data/lib/rubycritic/report_generators/templates/smelly_line.html.erb +9 -1
- data/lib/rubycritic/report_generators/view_helpers.rb +26 -0
- data/lib/rubycritic/smell.rb +4 -0
- data/lib/rubycritic/smell_adapters/reek.rb +1 -1
- data/lib/rubycritic/source_control_systems/git.rb +12 -8
- data/lib/rubycritic/version.rb +1 -1
- data/test/lib/rubycritic/location_test.rb +2 -6
- data/test/lib/rubycritic/smell_test.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3de50932159be5b26bc5a2cf4afe9eeec17e8dc
|
4
|
+
data.tar.gz: c7f9620aae8d000fe5f674844158d48296c706c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d945ef0e7036d298e1c8ff54b909c7c4c67b777e6ccfad20c548905ccb515fe849c351866b38bbba6765dfd31af610d41ae6c6cede57e469db3b54ee4f44bb
|
7
|
+
data.tar.gz: 509b8ffc4b0cdcb85cccacbbe242a5a5bc5f0e06e2975d12ac3827d9f168c0426793bcde26d4c48cf953e49ff41ba0039dce216428e8a94f009ba0e964f21522
|
data/lib/rubycritic/location.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
prettyPrint();
|
2
2
|
|
3
|
+
highlightLineFromFragment();
|
4
|
+
|
5
|
+
function highlightLineFromFragment() {
|
6
|
+
highlightLine(window.location.hash)
|
7
|
+
}
|
8
|
+
|
9
|
+
$(".js-file-code").on("click", ".js-smell-location", highlightSmellyLine);
|
10
|
+
|
11
|
+
function highlightSmellyLine() {
|
12
|
+
var lineId = "#" + this.href.split("#")[1];
|
13
|
+
$(".js-file-code li").removeClass("highlight");
|
14
|
+
highlightLine(lineId);
|
15
|
+
}
|
16
|
+
|
17
|
+
function highlightLine(lineReference) {
|
18
|
+
$(lineReference).addClass("highlight");
|
19
|
+
}
|
20
|
+
|
3
21
|
$("#js-toggle-smells").on("click", toggleSmells);
|
4
22
|
|
5
23
|
function toggleSmells() {
|
@@ -1097,11 +1097,18 @@ var prettyPrint;
|
|
1097
1097
|
ol.className = 'linenums';
|
1098
1098
|
var offset = Math.max(0, ((opt_startLineNum - 1 /* zero index */)) | 0) || 0;
|
1099
1099
|
for (var i = 0, n = listItems.length; i < n; ++i) {
|
1100
|
-
li = listItems[i];
|
1100
|
+
var li = listItems[i];
|
1101
|
+
var j = i + offset + 1;
|
1101
1102
|
// Stick a class on the LIs so that stylesheets can
|
1102
1103
|
// color odd/even rows, or any other row pattern that
|
1103
1104
|
// is co-prime with 10.
|
1104
1105
|
li.className = 'L' + ((i + offset) % 10);
|
1106
|
+
|
1107
|
+
// Stick an ID on the LIs so that stylesheets can
|
1108
|
+
// highlight a line or set of lines
|
1109
|
+
li.id = 'L' + j;
|
1110
|
+
li.setAttribute('href', '#L' + j);
|
1111
|
+
|
1105
1112
|
if (!li.firstChild) {
|
1106
1113
|
li.appendChild(document.createTextNode('\xA0'));
|
1107
1114
|
}
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require "rubycritic/report_generators/view_helpers"
|
2
|
+
|
1
3
|
module Rubycritic
|
2
4
|
|
3
5
|
class BaseGenerator
|
4
6
|
REPORT_DIR = File.expand_path("tmp/rubycritic", Dir.getwd)
|
5
7
|
TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
|
6
8
|
|
9
|
+
include ViewHelpers
|
10
|
+
|
7
11
|
def file_href
|
8
12
|
"file://#{file_pathname}"
|
9
13
|
end
|
@@ -21,23 +25,17 @@ module Rubycritic
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def render
|
24
|
-
raise NotImplementedError.new("You must implement the render
|
28
|
+
raise NotImplementedError.new("You must implement the render method.")
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def stylesheet_path(file)
|
32
|
-
File.join(REPORT_DIR, "assets/stylesheets/#{file}.css")
|
31
|
+
def get_binding
|
32
|
+
binding
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
File.join(REPORT_DIR, "index.html")
|
37
|
-
end
|
35
|
+
private
|
38
36
|
|
39
|
-
def
|
40
|
-
|
37
|
+
def root_directory
|
38
|
+
REPORT_DIR
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
@@ -23,7 +23,7 @@ module Rubycritic
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def analysed_file_name
|
26
|
-
@pathname.basename.sub_ext("")
|
26
|
+
@pathname.basename.sub_ext("")
|
27
27
|
end
|
28
28
|
|
29
29
|
def render
|
@@ -34,8 +34,8 @@ module Rubycritic
|
|
34
34
|
file_code << LineGenerator.new(line_text, line_smells).render
|
35
35
|
end
|
36
36
|
|
37
|
-
file_body = FILE_TEMPLATE.result(
|
38
|
-
LAYOUT_TEMPLATE.result(
|
37
|
+
file_body = FILE_TEMPLATE.result(get_binding { file_code })
|
38
|
+
LAYOUT_TEMPLATE.result(get_binding { file_body })
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -20,8 +20,8 @@ module Rubycritic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def render
|
23
|
-
index_body = INDEX_TEMPLATE.result(
|
24
|
-
LAYOUT_TEMPLATE.result(
|
23
|
+
index_body = INDEX_TEMPLATE.result(get_binding)
|
24
|
+
LAYOUT_TEMPLATE.result(get_binding { index_body })
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
<ul class="nocode smells js-smells">
|
4
4
|
<% @smells.each do |smell| %>
|
5
|
-
<li class="smell <%= smell.status %>"
|
5
|
+
<li class="smell <%= smell.status %>">
|
6
|
+
<span class="description"><%= smell %>
|
7
|
+
<% if smell.has_multiple_locations? %>
|
8
|
+
<% smell.locations.each_with_index do |location, index| %>
|
9
|
+
<a href="<%= smell_location_path(location) %>" class="js-smell-location"><%= index %></a>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
12
|
+
</span>
|
13
|
+
</li>
|
6
14
|
<% end %>
|
7
15
|
</ul>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rubycritic
|
2
|
+
|
3
|
+
module ViewHelpers
|
4
|
+
def javascript_path(file)
|
5
|
+
asset_path(File.join("javascripts", "#{file}.js"))
|
6
|
+
end
|
7
|
+
|
8
|
+
def stylesheet_path(file)
|
9
|
+
asset_path(File.join("stylesheets", "#{file}.css"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def asset_path(file)
|
13
|
+
File.join(root_directory, "assets", file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def smell_location_path(location)
|
17
|
+
pathname = location.pathname
|
18
|
+
File.join(root_directory, File.dirname(pathname), "#{pathname.basename.sub_ext("")}.html#L#{location.line}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def index_path
|
22
|
+
File.join(root_directory, "index.html")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/rubycritic/smell.rb
CHANGED
@@ -20,30 +20,34 @@ module Rubycritic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def travel_to_head
|
23
|
-
|
24
|
-
stash_successful = stash_changes
|
25
|
-
end
|
23
|
+
stash_successful = stash_changes
|
26
24
|
yield
|
27
25
|
ensure
|
28
|
-
|
26
|
+
travel_to_original_state if stash_successful
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
32
30
|
|
33
|
-
def uncommited_changes?
|
34
|
-
!`git status --porcelain`.empty?
|
35
|
-
end
|
36
|
-
|
37
31
|
def stash_changes
|
32
|
+
return false if everything_commmited?
|
33
|
+
|
38
34
|
stashes_count_before = stashes_count
|
39
35
|
`git stash`
|
40
36
|
stashes_count_after = stashes_count
|
41
37
|
stashes_count_after > stashes_count_before
|
42
38
|
end
|
43
39
|
|
40
|
+
def everything_commmited?
|
41
|
+
`git status --porcelain`.empty?
|
42
|
+
end
|
43
|
+
|
44
44
|
def stashes_count
|
45
45
|
`git stash list`.split("\n").length
|
46
46
|
end
|
47
|
+
|
48
|
+
def travel_to_original_state
|
49
|
+
`git stash pop`
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
end
|
data/lib/rubycritic/version.rb
CHANGED
@@ -9,12 +9,8 @@ describe Rubycritic::Location do
|
|
9
9
|
@location = Rubycritic::Location.new(@path, @line)
|
10
10
|
end
|
11
11
|
|
12
|
-
it "has a
|
13
|
-
@location.
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has a file name" do
|
17
|
-
@location.file.must_equal "foo"
|
12
|
+
it "has a pathname" do
|
13
|
+
@location.pathname.must_equal Pathname.new(@path)
|
18
14
|
end
|
19
15
|
|
20
16
|
it "has a line number" do
|
@@ -48,6 +48,15 @@ describe Rubycritic::Smell do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe "#has_multiple_locations?" do
|
52
|
+
it "returns true if the smell has more than one location" do
|
53
|
+
location1 = Rubycritic::Location.new("./foo", "42")
|
54
|
+
location2 = Rubycritic::Location.new("./foo", "23")
|
55
|
+
smell = Rubycritic::Smell.new(:locations => [location1, location2])
|
56
|
+
smell.has_multiple_locations?.must_equal true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
51
60
|
it "is comparable" do
|
52
61
|
attributes = {
|
53
62
|
:context => "#bar",
|
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.5
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/rubycritic/report_generators/templates/layouts/application.html.erb
|
148
148
|
- lib/rubycritic/report_generators/templates/line.html.erb
|
149
149
|
- lib/rubycritic/report_generators/templates/smelly_line.html.erb
|
150
|
+
- lib/rubycritic/report_generators/view_helpers.rb
|
150
151
|
- lib/rubycritic/revision_comparator.rb
|
151
152
|
- lib/rubycritic/smell.rb
|
152
153
|
- lib/rubycritic/smell_adapters/flog.rb
|