rubycritic 0.0.8 → 0.0.9
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/README.md +42 -11
- data/lib/rubycritic/analysers_runner.rb +4 -2
- data/lib/rubycritic/cli.rb +5 -1
- data/lib/rubycritic/configuration.rb +17 -0
- data/lib/rubycritic/location.rb +1 -1
- data/lib/rubycritic/report_generators/base_generator.rb +2 -3
- data/lib/rubycritic/report_generators/code_index_generator.rb +0 -4
- data/lib/rubycritic/report_generators/file_generator.rb +1 -1
- data/lib/rubycritic/report_generators/reporter.rb +1 -1
- data/lib/rubycritic/report_generators/smells_index_generator.rb +0 -4
- data/lib/rubycritic/revision_comparator.rb +6 -2
- data/lib/rubycritic/smell_adapters/flog.rb +14 -4
- data/lib/rubycritic/smells_status_setter.rb +1 -1
- data/lib/rubycritic/version.rb +1 -1
- data/lib/rubycritic.rb +1 -0
- data/test/lib/rubycritic/configuration_test.rb +17 -0
- data/test/lib/rubycritic/location_test.rb +2 -2
- data/test/lib/rubycritic/metric_adapters/flog_adapter_test.rb +1 -1
- data/test/lib/rubycritic/source_locator_test.rb +1 -1
- data/test/samples/flog/smelly.rb +7 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1099d50ed1beb525a791af3127cfae40dc525d4e
|
4
|
+
data.tar.gz: 2be5a299cd4a4839ca9c096ffd613a3ae0e38647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11c74550a23f8fdcf3d7bcb579d72ab8cf584552bf8ee412bc3c41be13f565d21a5ed73159c615dfc177724c9d73a20eaa9efd6f081da363f2ab7b33f3278ec3
|
7
|
+
data.tar.gz: dcfa39fc7b30b9d2ba6a2a3d02d93eacb1f1616cfb3c78dad9f790841172d8b202d93c4c312db95798090f7a733152837d38ce95222df0545cf5fbeadc970657
|
data/README.md
CHANGED
@@ -1,33 +1,55 @@
|
|
1
|
-
|
1
|
+
RubyCritic
|
2
2
|
===========
|
3
3
|
|
4
|
-
|
4
|
+
RubyCritic is a gem that wraps around static analysis gems such as [Reek][1]
|
5
|
+
and [Flay][2] to provide a quality report of your Ruby code.
|
6
|
+
|
7
|
+
For example, given the following code:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Dirty
|
11
|
+
def awful(x, y, offset = 0, log = false)
|
12
|
+
puts @screen.title
|
13
|
+
@screen = widgets.map {|w| w.each {|key| key += 3}}
|
14
|
+
puts @screen.contents
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
It turns something like this:
|
20
|
+
|
21
|
+

|
22
|
+
|
23
|
+
Into this:
|
24
|
+
|
25
|
+

|
5
26
|
|
6
27
|
Installation
|
7
28
|
------------
|
8
29
|
|
9
|
-
|
30
|
+
RubyCritic can be installed with the following command:
|
10
31
|
|
11
|
-
```
|
12
|
-
gem
|
32
|
+
```bash
|
33
|
+
$ gem install rubycritic
|
13
34
|
```
|
14
35
|
|
15
|
-
|
36
|
+
If you'd rather install RubyCritic using Bundler, add this line to your
|
37
|
+
application's Gemfile:
|
16
38
|
|
17
|
-
```
|
18
|
-
|
39
|
+
```ruby
|
40
|
+
gem "rubycritic", :require => false
|
19
41
|
```
|
20
42
|
|
21
|
-
|
43
|
+
And then execute:
|
22
44
|
|
23
45
|
```bash
|
24
|
-
$
|
46
|
+
$ bundle
|
25
47
|
```
|
26
48
|
|
27
49
|
Usage
|
28
50
|
-----
|
29
51
|
|
30
|
-
Running `rubycritic` with no arguments will
|
52
|
+
Running `rubycritic` with no arguments will analyse all the Ruby files in the
|
31
53
|
current directory:
|
32
54
|
|
33
55
|
```bash
|
@@ -39,3 +61,12 @@ Alternatively you can pass `rubycritic` a list of files and directories to check
|
|
39
61
|
```bash
|
40
62
|
$ rubycritic app lib/foo.rb
|
41
63
|
```
|
64
|
+
|
65
|
+
For a full list of the command-line options run:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
$ rubycritic --help
|
69
|
+
```
|
70
|
+
|
71
|
+
[1]: https://github.com/troessner/reek
|
72
|
+
[2]: https://github.com/seattlerb/flay
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require "rubycritic/active_support/methods"
|
2
2
|
require "rubycritic/analysers/flay"
|
3
|
-
require "rubycritic/
|
3
|
+
require "rubycritic/analysers/flog"
|
4
4
|
require "rubycritic/analysers/reek"
|
5
|
+
require "rubycritic/smell_adapters/flay"
|
6
|
+
require "rubycritic/smell_adapters/flog"
|
5
7
|
require "rubycritic/smell_adapters/reek"
|
6
8
|
|
7
9
|
module Rubycritic
|
@@ -9,7 +11,7 @@ module Rubycritic
|
|
9
11
|
class AnalysersRunner
|
10
12
|
include ActiveSupport
|
11
13
|
|
12
|
-
ANALYSERS = ["Flay", "Reek"]
|
14
|
+
ANALYSERS = ["Flay", "Flog", "Reek"]
|
13
15
|
|
14
16
|
def initialize(paths)
|
15
17
|
@paths = paths
|
data/lib/rubycritic/cli.rb
CHANGED
@@ -6,7 +6,11 @@ module Rubycritic
|
|
6
6
|
OptionParser.new do |opts|
|
7
7
|
opts.banner = "Usage: rubycritic [options] [paths]"
|
8
8
|
|
9
|
-
opts.
|
9
|
+
opts.on("-p", "--path [PATH]", "Set path where report will be saved (tmp/rubycritic by default)") do |path|
|
10
|
+
configuration.root = path
|
11
|
+
end
|
12
|
+
|
13
|
+
opts.on_tail("-v", "--version", "Show gem's version") do
|
10
14
|
require "rubycritic/version"
|
11
15
|
puts VERSION
|
12
16
|
exit 0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rubycritic
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
class Configuration
|
7
|
+
attr_reader :root
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.root = "tmp/rubycritic"
|
11
|
+
end
|
12
|
+
|
13
|
+
def root=(path)
|
14
|
+
@root = File.expand_path(path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rubycritic/location.rb
CHANGED
@@ -4,7 +4,6 @@ require "rubycritic/report_generators/view_helpers"
|
|
4
4
|
module Rubycritic
|
5
5
|
|
6
6
|
class BaseGenerator
|
7
|
-
REPORT_DIR = File.expand_path("tmp/rubycritic", Dir.getwd)
|
8
7
|
TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
|
9
8
|
LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
|
10
9
|
|
@@ -19,7 +18,7 @@ module Rubycritic
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def file_directory
|
22
|
-
|
21
|
+
root_directory
|
23
22
|
end
|
24
23
|
|
25
24
|
def file_name
|
@@ -37,7 +36,7 @@ module Rubycritic
|
|
37
36
|
private
|
38
37
|
|
39
38
|
def root_directory
|
40
|
-
|
39
|
+
::Rubycritic.configuration.root
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -7,7 +7,7 @@ require "rubycritic/smells_status_setter"
|
|
7
7
|
module Rubycritic
|
8
8
|
|
9
9
|
class RevisionComparator
|
10
|
-
|
10
|
+
SNAPSHOTS_DIR_NAME = "snapshots"
|
11
11
|
|
12
12
|
def initialize(smells, source_control_system)
|
13
13
|
@smells_now = smells
|
@@ -36,7 +36,11 @@ module Rubycritic
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def revision_file
|
39
|
-
@revision_file ||= File.join(
|
39
|
+
@revision_file ||= File.join(
|
40
|
+
::Rubycritic.configuration.root,
|
41
|
+
SNAPSHOTS_DIR_NAME,
|
42
|
+
@source_control_system.head_reference
|
43
|
+
)
|
40
44
|
end
|
41
45
|
|
42
46
|
def paths_of_tracked_files
|
@@ -4,14 +4,18 @@ module Rubycritic
|
|
4
4
|
module SmellAdapter
|
5
5
|
|
6
6
|
class Flog
|
7
|
+
HIGH_COMPLEXITY_SCORE_THRESHOLD = 25
|
8
|
+
VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD = 60
|
9
|
+
|
7
10
|
def initialize(flog)
|
8
11
|
@flog = flog
|
9
12
|
end
|
10
13
|
|
11
14
|
def smells
|
12
15
|
smells = []
|
13
|
-
@flog.each_by_score do |class_method,
|
14
|
-
|
16
|
+
@flog.each_by_score do |class_method, original_score|
|
17
|
+
score = original_score.round
|
18
|
+
smells << create_smell(class_method, score) if score >= HIGH_COMPLEXITY_SCORE_THRESHOLD
|
15
19
|
end
|
16
20
|
smells
|
17
21
|
end
|
@@ -20,14 +24,20 @@ module Rubycritic
|
|
20
24
|
|
21
25
|
def create_smell(context, score)
|
22
26
|
location = smell_location(context)
|
23
|
-
message = "has a
|
27
|
+
message = "has a flog score of #{score}"
|
28
|
+
type =
|
29
|
+
if score >= VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD
|
30
|
+
"VeryHighComplexity"
|
31
|
+
else
|
32
|
+
"HighComplexity"
|
33
|
+
end
|
24
34
|
|
25
35
|
Smell.new(
|
26
36
|
:locations => [location],
|
27
37
|
:context => context,
|
28
38
|
:message => message,
|
29
39
|
:score => score,
|
30
|
-
:type =>
|
40
|
+
:type => type
|
31
41
|
)
|
32
42
|
end
|
33
43
|
|
data/lib/rubycritic/version.rb
CHANGED
data/lib/rubycritic.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rubycritic/configuration"
|
3
|
+
|
4
|
+
describe Rubycritic::Configuration do
|
5
|
+
describe "#root" do
|
6
|
+
it "has a default" do
|
7
|
+
Rubycritic.configuration.root.wont_be_empty
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can be configured" do
|
11
|
+
default = Rubycritic.configuration.root
|
12
|
+
Rubycritic.configuration.root = "foo"
|
13
|
+
Rubycritic.configuration.root.must_equal File.expand_path("foo")
|
14
|
+
Rubycritic.configuration.root = default
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,7 +5,7 @@ describe Rubycritic::Location do
|
|
5
5
|
describe "attribute readers" do
|
6
6
|
before do
|
7
7
|
@path = "./foo.rb"
|
8
|
-
@line = 42
|
8
|
+
@line = "42"
|
9
9
|
@location = Rubycritic::Location.new(@path, @line)
|
10
10
|
end
|
11
11
|
|
@@ -14,7 +14,7 @@ describe Rubycritic::Location do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "has a line number" do
|
17
|
-
@location.line.must_equal @line
|
17
|
+
@location.line.must_equal @line.to_i
|
18
18
|
end
|
19
19
|
|
20
20
|
it "has a file name" do
|
data/test/samples/flog/smelly.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
class AllTheMethods
|
2
2
|
def method_missing(method, *args, &block)
|
3
|
-
|
4
|
-
|
3
|
+
message = "I"
|
4
|
+
eval "message = ' did not'"
|
5
|
+
eval "message << ' exist,'"
|
6
|
+
eval "message << ' but now'"
|
7
|
+
eval "message << ' I do.'"
|
8
|
+
self.class.send(:define_method, method) { "I did not exist, but now I do." }
|
9
|
+
self.send(method)
|
5
10
|
end
|
6
11
|
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.9
|
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-05-04 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/analysers/reek.rb
|
148
148
|
- lib/rubycritic/analysers_runner.rb
|
149
149
|
- lib/rubycritic/cli.rb
|
150
|
+
- lib/rubycritic/configuration.rb
|
150
151
|
- lib/rubycritic/location.rb
|
151
152
|
- lib/rubycritic/report_generators/assets/javascripts/application.js
|
152
153
|
- lib/rubycritic/report_generators/assets/javascripts/jquery-2.1.0.js
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- lib/rubycritic/version.rb
|
181
182
|
- rubycritic.gemspec
|
182
183
|
- test/lib/rubycritic/analysers_runner_test.rb
|
184
|
+
- test/lib/rubycritic/configuration_test.rb
|
183
185
|
- test/lib/rubycritic/location_test.rb
|
184
186
|
- test/lib/rubycritic/metric_adapters/flay_adapter_test.rb
|
185
187
|
- test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
|
@@ -226,6 +228,7 @@ specification_version: 4
|
|
226
228
|
summary: Ruby code smell detector
|
227
229
|
test_files:
|
228
230
|
- test/lib/rubycritic/analysers_runner_test.rb
|
231
|
+
- test/lib/rubycritic/configuration_test.rb
|
229
232
|
- test/lib/rubycritic/location_test.rb
|
230
233
|
- test/lib/rubycritic/metric_adapters/flay_adapter_test.rb
|
231
234
|
- test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
|