ruby-watchr 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,9 +3,9 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in watchr.gemspec
4
4
  gemspec
5
5
 
6
- gem "reek", :git => 'git@github.com:petrjanda/reek.git', :branch => :rubinius_support
7
- gem 'flog'
8
- gem 'ruby_parser', '2.0'
6
+ gem 'reek', '1.2.12'
7
+ gem 'flog', '2.5.3'
8
+ gem 'flay', '1.4.3'
9
9
 
10
10
  gem 'rspec'
11
11
  gem 'shoulda-matchers'
data/Gemfile.lock CHANGED
@@ -1,14 +1,3 @@
1
- GIT
2
- remote: git@github.com:petrjanda/reek.git
3
- revision: a52c448ea2d88ec931c3402f540d33a42ec92abe
4
- branch: rubinius_support
5
- specs:
6
- reek (1.2.12)
7
- ripper_ruby_parser (~> 0.0.7)
8
- ruby2ruby (~> 1.2.5)
9
- ruby_parser (~> 2.0)
10
- sexp_processor (~> 3.0)
11
-
12
1
  PATH
13
2
  remote: .
14
3
  specs:
@@ -16,16 +5,11 @@ PATH
16
5
  flay
17
6
  flog
18
7
  reek
8
+ ruby2ruby
19
9
 
20
10
  GEM
21
11
  remote: http://rubygems.org/
22
12
  specs:
23
- ParseTree (3.0.9)
24
- RubyInline (~> 3.9.0)
25
- sexp_processor (~> 3.2.0)
26
- RubyInline (3.9.0)
27
- ZenTest (~> 4.3)
28
- ZenTest (4.8.2)
29
13
  activesupport (3.2.9)
30
14
  i18n (~> 0.6)
31
15
  multi_json (~> 1.0)
@@ -41,6 +25,11 @@ GEM
41
25
  mocha (0.13.0)
42
26
  metaclass (~> 0.0.1)
43
27
  multi_json (1.3.7)
28
+ reek (1.2.12)
29
+ ripper_ruby_parser (~> 0.0.7)
30
+ ruby2ruby (~> 1.2.5)
31
+ ruby_parser (~> 2.0)
32
+ sexp_processor (~> 3.0)
44
33
  ripper_ruby_parser (0.0.8)
45
34
  sexp_processor (~> 3.0)
46
35
  rspec (2.12.0)
@@ -54,9 +43,8 @@ GEM
54
43
  ruby2ruby (1.2.5)
55
44
  ruby_parser (~> 2.0)
56
45
  sexp_processor (~> 3.0)
57
- ruby_parser (2.0.0)
58
- ParseTree
59
- sexp_processor (>= 3.0.0)
46
+ ruby_parser (2.3.1)
47
+ sexp_processor (~> 3.0)
60
48
  sexp_processor (3.2.0)
61
49
  shoulda-matchers (1.4.1)
62
50
  activesupport (>= 3.0.0)
@@ -65,10 +53,10 @@ PLATFORMS
65
53
  ruby
66
54
 
67
55
  DEPENDENCIES
68
- flog
56
+ flay (= 1.4.3)
57
+ flog (= 2.5.3)
69
58
  mocha
70
- reek!
59
+ reek (= 1.2.12)
71
60
  rspec
72
61
  ruby-watchr!
73
- ruby_parser (= 2.0)
74
62
  shoulda-matchers
@@ -64,7 +64,7 @@ module Watchr
64
64
  end
65
65
 
66
66
  def is_complex_by_level?(score, type, level)
67
- score >= Flog.const_get("#{level.to_s.upcase}_#{type.to_s.upcase}_THRESHOLD")
67
+ score >= Flog.const_get("#{level.upcase}_#{type.upcase}_THRESHOLD")
68
68
  end
69
69
  end
70
70
  end
@@ -38,6 +38,14 @@ module Watchr
38
38
  smells.any?
39
39
  end
40
40
 
41
+ def loc
42
+ stats_report.loc
43
+ end
44
+
45
+ def code_loc
46
+ stats_report.code_loc
47
+ end
48
+
41
49
  #
42
50
  # Store the flay report, which was evaluated on global basis
43
51
  # to check for duplications across multiple files.
@@ -56,5 +64,11 @@ module Watchr
56
64
  def add_smell(smell)
57
65
  @smells.add(smell)
58
66
  end
67
+
68
+ private
69
+
70
+ def stats_report
71
+ @stats ||= Stats::Report.new(path)
72
+ end
59
73
  end
60
74
  end
@@ -5,9 +5,12 @@ module Watchr
5
5
  diff = Diff.new(same, nodes, bonus, mass)
6
6
 
7
7
  nodes.each do |x|
8
- diff.add_location(Location.new(x.file, x.line - 1))
8
+ diff.add_location(Location.new(x.file, x.line))
9
9
  end
10
10
 
11
+ #r2r = Ruby2Ruby.new
12
+ #diff.code = n_way_diff(*nodes.map { |s| r2r.process(s.deep_clone) })
13
+
11
14
  diff
12
15
  end
13
16
  end
@@ -0,0 +1,48 @@
1
+ module Watchr
2
+ module Stats
3
+ class Report
4
+ attr_reader :loc, :code_loc
5
+
6
+ def initialize(file_name)
7
+ @file_name = file_name
8
+
9
+ @loc = 0
10
+ @code_loc = 0
11
+ @inside_comment = false
12
+
13
+ calculate
14
+ end
15
+
16
+ private
17
+
18
+ def calculate
19
+ File.open(@file_name) do |file|
20
+ while line = file.gets
21
+ calculate_line(line)
22
+ end
23
+ end
24
+ end
25
+
26
+ def calculate_line(line)
27
+ @loc += 1
28
+
29
+ comment_end if inside_comment? && line =~ /^=end/
30
+ comment_start if line =~ /^=begin/
31
+
32
+ @code_loc += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
33
+ end
34
+
35
+ def inside_comment?
36
+ @inside_comment
37
+ end
38
+
39
+ def comment_start
40
+ @inside_comment = true
41
+ end
42
+
43
+ def comment_end
44
+ @inside_comment = false
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Watchr
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -10,6 +10,9 @@ module Baz
10
10
  end
11
11
  end
12
12
 
13
+ #
14
+ # Bar
15
+ #
13
16
  def self.bar
14
17
  if true == false
15
18
  return false
@@ -60,7 +60,7 @@ describe Watchr::Analysers::Flog do
60
60
  Watchr::SmellBuilder.expects(:new).with(
61
61
  :complex_method,
62
62
  complex_method.name,
63
- "complexity = #{complex_method.total_score}"
63
+ "complexity = #{complex_method.total_score}",
64
64
  ).returns(builder)
65
65
 
66
66
  analyse.expects(:add_smell).returns(smell)
@@ -84,7 +84,7 @@ describe Watchr::Analysers::Flog do
84
84
  Watchr::SmellBuilder.expects(:new).with(
85
85
  :very_complex_object,
86
86
  clazz.name,
87
- "complexity = #{clazz.total_score}"
87
+ "complexity = #{clazz.total_score}",
88
88
  ).returns(builder)
89
89
 
90
90
  analyse.expects(:add_smell).returns(smell)
@@ -32,4 +32,52 @@ describe Watchr::FileAnalyse do
32
32
  it { should be_true }
33
33
  end
34
34
  end
35
+
36
+ describe '#loc' do
37
+ let(:stats_report) do
38
+ stub('stats_report', :loc => 10)
39
+ end
40
+
41
+ subject { file_analyse.loc }
42
+
43
+ before do
44
+ Watchr::Stats::Report.expects(:new).with(path).returns(stats_report)
45
+ end
46
+
47
+ it 'should return loc from stats report' do
48
+ should == stats_report.loc
49
+ end
50
+
51
+ it 'should cache report' do
52
+ file_analyse.loc
53
+
54
+ Watchr::Stats::Report.expects(:new).never
55
+
56
+ file_analyse.loc
57
+ end
58
+ end
59
+
60
+ describe '#code_loc' do
61
+ let(:stats_report) do
62
+ stub('stats_report', :loc => 10, :code_loc => 20)
63
+ end
64
+
65
+ subject { file_analyse.code_loc }
66
+
67
+ before do
68
+ Watchr::Stats::Report.expects(:new).with(path).returns(stats_report)
69
+ end
70
+
71
+ it 'should return code_loc from stats report' do
72
+ should == stats_report.code_loc
73
+ end
74
+
75
+ it 'should cache report' do
76
+ file_analyse.loc.should == 10
77
+
78
+ Watchr::Stats::Report.expects(:new).never
79
+
80
+ file_analyse.code_loc.should == 20
81
+ end
82
+ end
35
83
  end
@@ -59,7 +59,7 @@ describe Watchr::FlogMetric::Report do
59
59
  subject { flog_report.classes.first.methods.first.location }
60
60
 
61
61
  its(:file) { should == 'spec/fixtures/class.rb' }
62
- its(:line) { should == 13 }
62
+ its(:line) { should == 16 }
63
63
  end
64
64
 
65
65
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'watchr/metrics/stats/report'
3
+
4
+ describe Watchr::Stats::Report do
5
+ let(:stats) do
6
+ Watchr::Stats::Report.new(
7
+ 'spec/fixtures/class.rb'
8
+ )
9
+ end
10
+
11
+ describe '#loc' do
12
+ subject { stats.loc }
13
+
14
+ it { should == 24 }
15
+ end
16
+
17
+ describe '#code_loc' do
18
+ subject { stats.code_loc }
19
+
20
+ it { should == 19 }
21
+ end
22
+ end
data/watchr.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency 'flog'
25
25
  s.add_dependency 'flay'
26
26
  s.add_dependency 'reek'
27
+ s.add_dependency 'ruby2ruby'
27
28
  end
metadata CHANGED
@@ -1,74 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-watchr
3
- version: !ruby/object:Gem::Version
4
- hash: 596984887313028563
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Petr Janda
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-11-17 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: flog
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 2002549777813010636
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: flay
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: flay
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 2002549777813010636
43
- segments:
44
- - 0
45
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
49
47
  name: reek
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
50
55
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby2ruby
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 2002549777813010636
57
- segments:
58
- - 0
59
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
60
70
  type: :runtime
61
- version_requirements: *id003
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: Utility to gather summary of code smells according to multiple analysers.
63
- email:
79
+ email:
64
80
  - petrjanda@me.com
65
81
  executables: []
66
-
67
82
  extensions: []
68
-
69
83
  extra_rdoc_files: []
70
-
71
- files:
84
+ files:
72
85
  - .gitignore
73
86
  - .rspec
74
87
  - .rvmrc
@@ -89,6 +102,7 @@ files:
89
102
  - lib/watchr/metrics/flog/method.rb
90
103
  - lib/watchr/metrics/flog/report.rb
91
104
  - lib/watchr/metrics/reek/report.rb
105
+ - lib/watchr/metrics/stats/report.rb
92
106
  - lib/watchr/paths.rb
93
107
  - lib/watchr/smell.rb
94
108
  - lib/watchr/smell_builder.rb
@@ -105,45 +119,37 @@ files:
105
119
  - spec/watchr/location_spec.rb
106
120
  - spec/watchr/metrics/flay/report_spec.rb
107
121
  - spec/watchr/metrics/flog/flog_report_spec.rb
122
+ - spec/watchr/metrics/stats/stats_spec.rb
108
123
  - spec/watchr/paths_spec.rb
109
124
  - spec/watchr/smell_builder_spec.rb
110
125
  - spec/watchr/smell_spec.rb
111
126
  - spec/watchr/smells_collector_spec.rb
112
127
  - watchr.gemspec
113
- homepage: ""
128
+ homepage: ''
114
129
  licenses: []
115
-
116
130
  post_install_message:
117
131
  rdoc_options: []
118
-
119
- require_paths:
132
+ require_paths:
120
133
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
122
135
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 2002549777813010636
127
- segments:
128
- - 0
129
- version: "0"
130
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
141
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 2002549777813010636
136
- segments:
137
- - 0
138
- version: "0"
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
139
146
  requirements: []
140
-
141
147
  rubyforge_project: watchr
142
148
  rubygems_version: 1.8.24
143
149
  signing_key:
144
150
  specification_version: 3
145
151
  summary: Ruby static code analysis
146
- test_files:
152
+ test_files:
147
153
  - spec/fixtures/class.rb
148
154
  - spec/fixtures/module.rb
149
155
  - spec/spec_helper.rb
@@ -154,6 +160,7 @@ test_files:
154
160
  - spec/watchr/location_spec.rb
155
161
  - spec/watchr/metrics/flay/report_spec.rb
156
162
  - spec/watchr/metrics/flog/flog_report_spec.rb
163
+ - spec/watchr/metrics/stats/stats_spec.rb
157
164
  - spec/watchr/paths_spec.rb
158
165
  - spec/watchr/smell_builder_spec.rb
159
166
  - spec/watchr/smell_spec.rb