rubycritic 0.0.3 → 0.0.4
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/report_generators/assets/javascripts/application.js +7 -0
- data/lib/rubycritic/report_generators/assets/javascripts/jquery-2.1.0.js +9111 -0
- data/lib/rubycritic/report_generators/assets/javascripts/prettify.js +1655 -0
- data/lib/rubycritic/report_generators/assets/stylesheets/application.css +19 -5
- data/lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css +68 -0
- data/lib/rubycritic/report_generators/base_generator.rb +6 -2
- data/lib/rubycritic/report_generators/file_generator.rb +2 -2
- data/lib/rubycritic/report_generators/line_generator.rb +1 -3
- data/lib/rubycritic/report_generators/templates/file.html.erb +3 -1
- data/lib/rubycritic/report_generators/templates/layouts/application.html.erb +5 -2
- data/lib/rubycritic/report_generators/templates/line.html.erb +1 -1
- data/lib/rubycritic/report_generators/templates/smelly_line.html.erb +7 -1
- data/lib/rubycritic/smell_adapters/flog.rb +1 -1
- data/lib/rubycritic/source_control_systems/git.rb +17 -6
- data/lib/rubycritic/source_control_systems/source_control_system.rb +4 -4
- data/lib/rubycritic/source_locator.rb +10 -4
- data/lib/rubycritic/version.rb +1 -1
- data/lib/rubycritic.rb +2 -2
- data/rubycritic.gemspec +1 -1
- data/test/lib/rubycritic/source_locator_test.rb +8 -4
- metadata +7 -3
@@ -1,12 +1,26 @@
|
|
1
|
-
.
|
2
|
-
|
3
|
-
|
1
|
+
.smells {
|
2
|
+
margin: 2px 0 22px 0;
|
3
|
+
padding-left: 0;
|
4
|
+
border: 1px solid #000;
|
5
|
+
background-color: #DDD;
|
6
|
+
white-space: normal;
|
7
|
+
list-style-type: disc;
|
4
8
|
}
|
5
9
|
|
6
10
|
.smell {
|
7
|
-
|
11
|
+
margin: 5px 5px 5px 30px;
|
12
|
+
font-size: 24px;
|
13
|
+
}
|
14
|
+
|
15
|
+
.smell.new {
|
16
|
+
color: #F00;
|
8
17
|
}
|
9
18
|
|
10
19
|
.smell.old {
|
11
|
-
|
20
|
+
color: #FA0;
|
21
|
+
}
|
22
|
+
|
23
|
+
.smell .description {
|
24
|
+
color: #000;
|
25
|
+
font-size: initial;
|
12
26
|
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/* Pretty printing styles. Used with prettify.js. */
|
2
|
+
|
3
|
+
/* SPAN elements with the classes below are added by prettyprint. */
|
4
|
+
.pln { /* plain text */
|
5
|
+
color: #000;
|
6
|
+
}
|
7
|
+
|
8
|
+
.str { /* string content */
|
9
|
+
color: #690;
|
10
|
+
}
|
11
|
+
|
12
|
+
.kwd { /* a keyword */
|
13
|
+
color: #07a;
|
14
|
+
}
|
15
|
+
|
16
|
+
.com { /* a comment */
|
17
|
+
color: #800;
|
18
|
+
}
|
19
|
+
|
20
|
+
.typ { /* a type name */
|
21
|
+
color: #905;
|
22
|
+
}
|
23
|
+
|
24
|
+
.lit { /* a literal value */
|
25
|
+
color: #a67f59;
|
26
|
+
}
|
27
|
+
|
28
|
+
.pun, .opn, .clo { /* punctuation, lisp open bracket, lisp close bracket */
|
29
|
+
color: #660;
|
30
|
+
}
|
31
|
+
|
32
|
+
.tag { /* a markup tag name */
|
33
|
+
color: #008;
|
34
|
+
}
|
35
|
+
|
36
|
+
.atn { /* a markup attribute name */
|
37
|
+
color: #606;
|
38
|
+
}
|
39
|
+
|
40
|
+
.atv { /* a markup attribute value */
|
41
|
+
color: #080;
|
42
|
+
}
|
43
|
+
|
44
|
+
.dec, .var { /* a declaration; a variable name */
|
45
|
+
color: #a67f59;
|
46
|
+
}
|
47
|
+
|
48
|
+
.fun { /* a function name */
|
49
|
+
color: red;
|
50
|
+
}
|
51
|
+
|
52
|
+
/* Put a border around prettyprinted code snippets. */
|
53
|
+
.prettyprint {
|
54
|
+
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
55
|
+
white-space: pre-wrap;
|
56
|
+
}
|
57
|
+
|
58
|
+
/* Specify class=linenums on a pre to get line numbering */
|
59
|
+
.prettyprint ol.linenums {
|
60
|
+
margin-top: 0;
|
61
|
+
margin-bottom: 0;
|
62
|
+
background-color: #EEEBE9;
|
63
|
+
padding-left: 66px;
|
64
|
+
}
|
65
|
+
|
66
|
+
.prettyprint li {
|
67
|
+
color: #999;
|
68
|
+
}
|
@@ -24,8 +24,12 @@ module Rubycritic
|
|
24
24
|
raise NotImplementedError.new("You must implement the render file_name method.")
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
File.join(REPORT_DIR, "assets/
|
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")
|
29
33
|
end
|
30
34
|
|
31
35
|
def index_path
|
@@ -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("").to_s
|
27
27
|
end
|
28
28
|
|
29
29
|
def render
|
@@ -31,7 +31,7 @@ module Rubycritic
|
|
31
31
|
File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
|
32
32
|
location = Location.new(@pathname, line_number)
|
33
33
|
line_smells = @smells.select { |smell| smell.located_in?(location) }
|
34
|
-
file_code << LineGenerator.new(line_text,
|
34
|
+
file_code << LineGenerator.new(line_text, line_smells).render
|
35
35
|
end
|
36
36
|
|
37
37
|
file_body = FILE_TEMPLATE.result(self.get_binding { file_code })
|
@@ -5,13 +5,11 @@ require "cgi"
|
|
5
5
|
module Rubycritic
|
6
6
|
|
7
7
|
class LineGenerator < BaseGenerator
|
8
|
-
LINE_NUMBER_PADDING = 3
|
9
8
|
NORMAL_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "line.html.erb")))
|
10
9
|
SMELLY_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "smelly_line.html.erb")))
|
11
10
|
|
12
|
-
def initialize(text,
|
11
|
+
def initialize(text, smells)
|
13
12
|
@text = CGI::escapeHTML(text.chomp)
|
14
|
-
@number = number.to_s.rjust(LINE_NUMBER_PADDING)
|
15
13
|
@smells = smells
|
16
14
|
@template =
|
17
15
|
if @smells.empty?
|
@@ -4,13 +4,16 @@
|
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
6
|
<title>RubyCritic</title>
|
7
|
-
<link href="<%= stylesheet_path %>" media="screen, projection, print" rel="stylesheet" type="text/css">
|
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">
|
8
9
|
<meta name="description" content="">
|
9
10
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
10
11
|
</head>
|
11
12
|
<body>
|
12
13
|
<h1><a href="<%= index_path %>">RubyCritic</a></h1>
|
13
|
-
|
14
14
|
<%= yield %>
|
15
|
+
<script src="<%= javascript_path(:'jquery-2.1.0') %>"></script>
|
16
|
+
<script src="<%= javascript_path(:prettify) %>"></script>
|
17
|
+
<script src="<%= javascript_path(:application) %>"></script>
|
15
18
|
</body>
|
16
19
|
</html>
|
@@ -1 +1 @@
|
|
1
|
-
<%= @
|
1
|
+
<%= @text %>
|
@@ -1 +1,7 @@
|
|
1
|
-
|
1
|
+
<%= @text %>
|
2
|
+
|
3
|
+
<ul class="nocode smells js-smells">
|
4
|
+
<% @smells.each do |smell| %>
|
5
|
+
<li class="smell <%= smell.status %>"><span class="description"><%= smell %></span></li>
|
6
|
+
<% end %>
|
7
|
+
</ul>
|
@@ -15,17 +15,17 @@ module Rubycritic
|
|
15
15
|
head_reference && $?.success?
|
16
16
|
end
|
17
17
|
|
18
|
+
def head_reference
|
19
|
+
`git rev-parse --verify HEAD`.chomp
|
20
|
+
end
|
21
|
+
|
18
22
|
def travel_to_head
|
19
23
|
if uncommited_changes?
|
20
|
-
|
24
|
+
stash_successful = stash_changes
|
21
25
|
end
|
22
26
|
yield
|
23
27
|
ensure
|
24
|
-
`git stash pop` if
|
25
|
-
end
|
26
|
-
|
27
|
-
def head_reference
|
28
|
-
`git rev-parse --verify HEAD`.chomp
|
28
|
+
`git stash pop` if stash_successful
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -33,6 +33,17 @@ module Rubycritic
|
|
33
33
|
def uncommited_changes?
|
34
34
|
!`git status --porcelain`.empty?
|
35
35
|
end
|
36
|
+
|
37
|
+
def stash_changes
|
38
|
+
stashes_count_before = stashes_count
|
39
|
+
`git stash`
|
40
|
+
stashes_count_after = stashes_count
|
41
|
+
stashes_count_after > stashes_count_before
|
42
|
+
end
|
43
|
+
|
44
|
+
def stashes_count
|
45
|
+
`git stash list`.split("\n").length
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
38
49
|
end
|
@@ -28,13 +28,13 @@ module Rubycritic
|
|
28
28
|
raise NotImplementedError.new("You must implement the has_revision? method.")
|
29
29
|
end
|
30
30
|
|
31
|
-
def travel_to_head
|
32
|
-
raise NotImplementedError.new("You must implement the travel_to_head method.")
|
33
|
-
end
|
34
|
-
|
35
31
|
def head_reference
|
36
32
|
raise NotImplementedError.new("You must implement the head_reference method.")
|
37
33
|
end
|
34
|
+
|
35
|
+
def travel_to_head
|
36
|
+
raise NotImplementedError.new("You must implement the travel_to_head method.")
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module Rubycritic
|
2
4
|
|
3
5
|
class SourceLocator
|
4
6
|
RUBY_EXTENSION = ".rb"
|
5
7
|
RUBY_FILES = File.join("**", "*#{RUBY_EXTENSION}")
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
+
def initialize(paths)
|
10
|
+
@user_paths = paths
|
9
11
|
end
|
10
12
|
|
11
13
|
def pathnames
|
@@ -19,14 +21,18 @@ module Rubycritic
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def expand_paths
|
22
|
-
@
|
24
|
+
@user_paths.map do |path|
|
23
25
|
if File.directory?(path)
|
24
|
-
Pathname.glob(
|
26
|
+
Pathname.glob(files_contained_in(path))
|
25
27
|
elsif File.exists?(path) && File.extname(path) == RUBY_EXTENSION
|
26
28
|
Pathname.new(path)
|
27
29
|
end
|
28
30
|
end.flatten.compact.sort
|
29
31
|
end
|
32
|
+
|
33
|
+
def files_contained_in(path)
|
34
|
+
(path == ".") ? RUBY_FILES : File.join(path, RUBY_FILES)
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
end
|
data/lib/rubycritic/version.rb
CHANGED
data/lib/rubycritic.rb
CHANGED
@@ -12,8 +12,8 @@ module Rubycritic
|
|
12
12
|
@source_control_system = SourceControlSystem.create
|
13
13
|
end
|
14
14
|
|
15
|
-
def critique(
|
16
|
-
source = SourceLocator.new(
|
15
|
+
def critique(paths)
|
16
|
+
source = SourceLocator.new(paths)
|
17
17
|
if @source_control_system.has_revision?
|
18
18
|
smelly_pathnames = RevisionComparator.new(source.paths, @source_control_system).compare
|
19
19
|
else
|
data/rubycritic.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
Ruby Critic is a tool that detects and reports smells in Ruby classes, modules and methods.
|
13
13
|
EOF
|
14
14
|
spec.summary = "Ruby code smell detector"
|
15
|
-
spec.homepage = "https://github.com/
|
15
|
+
spec.homepage = "https://github.com/whitesmith/rubycritic"
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split("\n")
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/source_locator"
|
3
|
-
require "pathname"
|
4
3
|
|
5
4
|
describe Rubycritic::SourceLocator do
|
6
5
|
before do
|
@@ -14,7 +13,7 @@ describe Rubycritic::SourceLocator do
|
|
14
13
|
Rubycritic::SourceLocator.new(paths).paths.must_equal paths
|
15
14
|
end
|
16
15
|
|
17
|
-
it "finds multiple paths" do
|
16
|
+
it "finds files through multiple paths" do
|
18
17
|
paths = ["dir1/file1.rb", "file0.rb"]
|
19
18
|
Rubycritic::SourceLocator.new(paths).paths.must_equal paths
|
20
19
|
end
|
@@ -24,12 +23,17 @@ describe Rubycritic::SourceLocator do
|
|
24
23
|
Rubycritic::SourceLocator.new(["."]).paths.must_equal paths
|
25
24
|
end
|
26
25
|
|
27
|
-
it "
|
26
|
+
it "finds all the files inside a given directory" do
|
27
|
+
paths = ["dir1/file1.rb"]
|
28
|
+
Rubycritic::SourceLocator.new(["dir1"]).paths.must_equal paths
|
29
|
+
end
|
30
|
+
|
31
|
+
it "ignores paths to non-existent files" do
|
28
32
|
paths = ["non_existent_dir1/non_existent_file1.rb", "non_existent_file0.rb"]
|
29
33
|
Rubycritic::SourceLocator.new(paths).paths.must_equal []
|
30
34
|
end
|
31
35
|
|
32
|
-
it "ignores
|
36
|
+
it "ignores paths to files that do not match the Ruby extension" do
|
33
37
|
paths = ["file_with_no_extension", "file_with_different_extension.py"]
|
34
38
|
Rubycritic::SourceLocator.new(paths).paths.must_equal []
|
35
39
|
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.4
|
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-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -132,7 +132,11 @@ files:
|
|
132
132
|
- lib/rubycritic/analysers_runner.rb
|
133
133
|
- lib/rubycritic/cli.rb
|
134
134
|
- lib/rubycritic/location.rb
|
135
|
+
- lib/rubycritic/report_generators/assets/javascripts/application.js
|
136
|
+
- lib/rubycritic/report_generators/assets/javascripts/jquery-2.1.0.js
|
137
|
+
- lib/rubycritic/report_generators/assets/javascripts/prettify.js
|
135
138
|
- lib/rubycritic/report_generators/assets/stylesheets/application.css
|
139
|
+
- lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css
|
136
140
|
- lib/rubycritic/report_generators/base_generator.rb
|
137
141
|
- lib/rubycritic/report_generators/file_generator.rb
|
138
142
|
- lib/rubycritic/report_generators/index_generator.rb
|
@@ -173,7 +177,7 @@ files:
|
|
173
177
|
- test/samples/reek/not_smelly.rb
|
174
178
|
- test/samples/reek/smelly.rb
|
175
179
|
- test/test_helper.rb
|
176
|
-
homepage: https://github.com/
|
180
|
+
homepage: https://github.com/whitesmith/rubycritic
|
177
181
|
licenses:
|
178
182
|
- MIT
|
179
183
|
metadata: {}
|