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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a1de618127c08ea218625eaf15fd6033ba99cfa
4
- data.tar.gz: 5c7835df2a2841e3312bcf4d21b4838c7f1ef85f
3
+ metadata.gz: e3de50932159be5b26bc5a2cf4afe9eeec17e8dc
4
+ data.tar.gz: c7f9620aae8d000fe5f674844158d48296c706c3
5
5
  SHA512:
6
- metadata.gz: 58f34ab665bde1c35c6ba021dd6bfcbb1ed56e644c6abd0bb4d7def02f4f571c3d58cd3e5e90b14575b815bb0552abb81cfc92d05007a3739877f3b87914ef24
7
- data.tar.gz: 7678a5279a12a6d943d22340fe1d32b26e5af95351ed6f6f315390509702cadf4f737a758b5dc01896beb2bbb460eeb7fcd3132ddc1443dc60aedbefbefe7130
6
+ metadata.gz: 28d945ef0e7036d298e1c8ff54b909c7c4c67b777e6ccfad20c548905ccb515fe849c351866b38bbba6765dfd31af610d41ae6c6cede57e469db3b54ee4f44bb
7
+ data.tar.gz: 509b8ffc4b0cdcb85cccacbbe242a5a5bc5f0e06e2975d12ac3827d9f168c0426793bcde26d4c48cf953e49ff41ba0039dce216428e8a94f009ba0e964f21522
@@ -10,16 +10,8 @@ module Rubycritic
10
10
  @line = line
11
11
  end
12
12
 
13
- def path
14
- @pathname.to_s
15
- end
16
-
17
- def file
18
- @pathname.basename.to_s
19
- end
20
-
21
13
  def to_s
22
- "#{path}:#{line}"
14
+ "#{pathname}:#{line}"
23
15
  end
24
16
 
25
17
  def ==(other)
@@ -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
  }
@@ -66,3 +66,7 @@
66
66
  .prettyprint li {
67
67
  color: #999;
68
68
  }
69
+
70
+ li.highlight {
71
+ background-color: #FFC;
72
+ }
@@ -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 file_name method.")
28
+ raise NotImplementedError.new("You must implement the render method.")
25
29
  end
26
30
 
27
- def javascript_path(file)
28
- File.join(REPORT_DIR, "assets/javascripts/#{file}.js")
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
- def index_path
36
- File.join(REPORT_DIR, "index.html")
37
- end
35
+ private
38
36
 
39
- def get_binding
40
- binding
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("").to_s
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(self.get_binding { file_code })
38
- LAYOUT_TEMPLATE.result(self.get_binding { file_body })
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(self.get_binding)
24
- LAYOUT_TEMPLATE.result(self.get_binding { index_body })
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 %>"><span class="description"><%= smell %></span></li>
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
@@ -21,6 +21,10 @@ module Rubycritic
21
21
  locations.any? { |location| location == other_location }
22
22
  end
23
23
 
24
+ def has_multiple_locations?
25
+ locations.length > 1
26
+ end
27
+
24
28
  def ==(other)
25
29
  self.class == other.class && state == other.state
26
30
  end
@@ -25,7 +25,7 @@ module Rubycritic
25
25
  end
26
26
 
27
27
  def smell_locations(file_path, file_lines)
28
- file_lines.uniq.map do |file_line|
28
+ file_lines.uniq.sort.map do |file_line|
29
29
  Location.new(file_path, file_line)
30
30
  end
31
31
  end
@@ -20,30 +20,34 @@ module Rubycritic
20
20
  end
21
21
 
22
22
  def travel_to_head
23
- if uncommited_changes?
24
- stash_successful = stash_changes
25
- end
23
+ stash_successful = stash_changes
26
24
  yield
27
25
  ensure
28
- `git stash pop` if stash_successful
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
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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 file path" do
13
- @location.path.must_equal @path
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
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-08 00:00:00.000000000 Z
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