metric_fu-Saikuro 1.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ # This is a patch to RDoc so that when saikuro is installed as a
2
+ # RubyGem usage will read the proper file.
3
+
4
+ module RDoc
5
+
6
+ def RDoc.main_program_file=(file)
7
+ @@main_program_file = file
8
+ end
9
+
10
+ # Display usage
11
+ def RDoc.usage_no_exit(*args)
12
+ @@main_program_file ||= caller[-1].sub(/:\d+$/, '')
13
+ comment = File.open(@@main_program_file) do |file|
14
+ find_comment(file)
15
+ end
16
+
17
+ comment = comment.gsub(/^\s*#/, '')
18
+
19
+ markup = SM::SimpleMarkup.new
20
+ flow_convertor = SM::ToFlow.new
21
+
22
+ flow = markup.convert(comment, flow_convertor)
23
+
24
+ format = "plain"
25
+
26
+ unless args.empty?
27
+ flow = extract_sections(flow, args)
28
+ end
29
+
30
+ options = RI::Options.instance
31
+ if args = ENV["RI"]
32
+ options.parse(args.split)
33
+ end
34
+ formatter = options.formatter.new(options, "")
35
+ formatter.display_flow(flow)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Saikuro
2
+ VERSION = "1.1.1.0"
3
+ end
@@ -0,0 +1,70 @@
1
+ # These are methods to show warning and errors
2
+ # The code is nonsense it is used to make large complexity values.
3
+
4
+ class ExtraTests
5
+
6
+ # CC 8
7
+ def warn_method_cc8(a, b, c)
8
+ q, r, s = nil
9
+ if a
10
+ q = a + c
11
+ end
12
+ if b
13
+ b = r - q
14
+ end
15
+ if !c
16
+ s = r + b
17
+ end
18
+ if b > q || c
19
+ a = c + q
20
+ end
21
+ if a
22
+ c = b
23
+ end
24
+ if c
25
+ b = a
26
+ end
27
+ if s
28
+ c = s + a
29
+ end
30
+ # large token count
31
+ a + b + c + q + r + s + a + b + c + q + r + s + a + b + c + q + r + s + a + b + c + q + r + s
32
+ end
33
+
34
+ # CC 11
35
+ def error_method_cc11(a, b, c)
36
+ q, r, s = nil
37
+ if a
38
+ q = a + c
39
+ end
40
+ if b
41
+ b = r - q
42
+ end
43
+ if !c
44
+ s = r + b
45
+ end
46
+ if b > q || c
47
+ a = c + q
48
+ end
49
+ if a
50
+ c = b
51
+ end
52
+ if c
53
+ b = a
54
+ end
55
+ if s
56
+ c = s + a
57
+ end
58
+ if q
59
+ r = s + q
60
+ end
61
+ if r
62
+ s = a + r
63
+ end
64
+ a + b + c + q + r + s + a + b + c + q + r + s
65
+ rescue => err
66
+ puts err
67
+ end
68
+
69
+
70
+ end
data/tests/samples.rb ADDED
@@ -0,0 +1,315 @@
1
+
2
+
3
+ # CC : 1
4
+ def cc1
5
+ "hello"
6
+ end
7
+
8
+ class CylcoIfTestClass
9
+
10
+ # CC 2
11
+ def cc2(arg)
12
+ # Comment inside method
13
+ if arg
14
+ "True Arg"
15
+ else
16
+ "False Arg"
17
+ end
18
+ end
19
+
20
+ # CC 3
21
+ def cc3(arg1 = true, arg2 = false)
22
+ if arg1
23
+ "ARG1"
24
+ elsif arg2
25
+ "ARG2"
26
+ else
27
+ "Neither ARG1 or ARG2"
28
+ end
29
+ end
30
+
31
+ # Also CC 3
32
+ def cc3_2(arg1 = true, arg2 = false)
33
+ if arg1
34
+ if arg2
35
+ "ARG1 and ARG2"
36
+ else
37
+ "ARG1"
38
+ end
39
+ else
40
+ "No ARG1"
41
+ end
42
+ end
43
+
44
+
45
+ def cc2_2(arg)
46
+ v = "not arg"
47
+ v = "arg" if arg
48
+ v
49
+ end
50
+
51
+ def cc2_2(arg)
52
+ if arg then
53
+ "True Arg"
54
+ else
55
+ "False Arg"
56
+ end
57
+ end
58
+
59
+ def cc2_ternary(arg)
60
+ arg ? "True" : "False"
61
+ end
62
+
63
+ def cc1?(arg)
64
+ cc2?
65
+ end
66
+
67
+ end
68
+
69
+ class CycloException < StandardError; end
70
+
71
+ class CycloUnlessTestClass
72
+
73
+ def cc2(arg = true)
74
+ v = "cc2"
75
+ unless arg
76
+ arg = false
77
+ v = "unless"
78
+ end
79
+ v
80
+ end
81
+
82
+ def cc2_2(arg)
83
+ unless arg
84
+ "not arg"
85
+ else
86
+ "arg"
87
+ end
88
+ end
89
+
90
+ def cc2_3(arg)
91
+ v = "arg"
92
+ v = "trail" unless arg
93
+ v
94
+ end
95
+
96
+ end
97
+
98
+ class CycloDefTestClass
99
+
100
+ def cc3
101
+ "p1"
102
+ rescue CycloException => ce
103
+ "ce"
104
+ rescue => err
105
+ "se"
106
+ end
107
+
108
+ def cc2
109
+ p = "p1"
110
+ rescue CycloException => ce
111
+ p = "CE"
112
+ else
113
+ p = "pelse"
114
+ ensure
115
+ p + "ensured"
116
+ end
117
+
118
+ def self.classm1_cc1
119
+ "c1"
120
+ end
121
+
122
+ def CycloDefTestClass.classm2_cc1
123
+ "c2"
124
+ end
125
+
126
+ end
127
+
128
+ module CycloTestModule
129
+
130
+ def cc4_case(arg)
131
+ v = "1"
132
+ case arg
133
+ when "1"
134
+ v += "c1"
135
+ when "2"
136
+ v << "c2"
137
+ when "3", "4"
138
+ v<< "c3/4"
139
+ else
140
+ v<< "else"
141
+ end
142
+ v
143
+ end
144
+
145
+ def while1_cc2(arg)
146
+ v = "no while"
147
+ while arg
148
+ v = "while"
149
+ arg = false
150
+ end
151
+ v
152
+ end
153
+
154
+ def while2_cc2(arg)
155
+ v = "no while"
156
+ arg = false while arg
157
+ v
158
+ end
159
+
160
+ def while3_cc2(arg)
161
+ v = "no while"
162
+ begin
163
+ v = "must while"
164
+ arg = false
165
+ end while arg
166
+ end
167
+
168
+ def while4_cc3(arg)
169
+ v = "no while"
170
+ while arg do
171
+ v = "while"
172
+ arg = false
173
+ end
174
+ v
175
+ end
176
+
177
+ def for_cc2(arg)
178
+ v = 0
179
+ for x in arg
180
+ v += x
181
+ end
182
+ v
183
+ end
184
+
185
+ # The do causes an error in the current implementation.
186
+ def for2_cc2(arg)
187
+ v = 0
188
+ for x in arg do
189
+ v += x
190
+ end
191
+ v
192
+ end
193
+
194
+ # def commented_out_method
195
+ # "Should not be seen"
196
+ # end
197
+
198
+ def block_cc2(arg)
199
+ v = 0
200
+ arg.each do |i|
201
+ v += x
202
+ end
203
+ v
204
+ end
205
+
206
+ def block2_cc2(arg)
207
+ v = 0
208
+ arg.each { |i| v += x }
209
+ v
210
+ end
211
+
212
+ def hash_cc1
213
+ { :x => 1 }
214
+ end
215
+
216
+ end
217
+
218
+ # Just to make sure classes wrapped in module show.
219
+ module CycloTestModule2
220
+
221
+ class CycloUntilTestClass
222
+
223
+ def until_cc2(arg)
224
+ v = "until"
225
+ until arg
226
+ v = "no more until"
227
+ arg = true
228
+ end
229
+ v
230
+ end
231
+
232
+
233
+ def until2_cc2(arg)
234
+ v = "no until"
235
+ arg = true until arg
236
+ v
237
+ end
238
+
239
+ def until3_cc2(arg)
240
+ v = "no until"
241
+ begin
242
+ v = "must until"
243
+ arg = true
244
+ end until arg
245
+ end
246
+
247
+ def until4_cc2(arg)
248
+ v = "until"
249
+ until arg do
250
+ v = "no more until"
251
+ arg = true
252
+ end
253
+ v
254
+ end
255
+
256
+ end
257
+
258
+ end
259
+
260
+ class SyntaxTests
261
+
262
+ def here_docs_cc1
263
+ str = <<-EOF
264
+ Hello
265
+ This is a here doc
266
+ EOF
267
+ str
268
+ end
269
+
270
+ def SyntaxTests::colon_method_cc1
271
+ "cc1"
272
+ end
273
+
274
+ def symbol_test_cc1(arg)
275
+ { :s1 => 1,
276
+ :class => "should not be a class",
277
+ }
278
+ end
279
+
280
+ def hash_with_hash1(arg)
281
+ h = {
282
+ :x => {
283
+ :q => arg
284
+ }
285
+ }
286
+ end
287
+
288
+ def hash_with_block_inside1(arg)
289
+ data = {
290
+ :x => 1,
291
+ :y => arg.map do |a|
292
+ a + 2
293
+ end,
294
+ }
295
+ end
296
+
297
+ def hash_with_block_inside2(arg)
298
+ data = {
299
+ :x => 1,
300
+ :y => arg.map do |a|
301
+ {
302
+ :q => b_meth { a }
303
+ }
304
+ end,
305
+ }
306
+ end
307
+
308
+
309
+ =begin
310
+ def begin_end_comment
311
+ "Should not be shown"
312
+ end
313
+ =end
314
+
315
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metric_fu-Saikuro
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zev Blut
9
+ - David Barri
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-06-04 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: ! "When given Ruby\n source code Saikuro will generate a report listing
16
+ the cyclomatic\n complexity of each method found. In addition, Saikuro counts
17
+ the\n number of lines per method and can generate a listing of the number of\n
18
+ \ tokens on each line of code."
19
+ email:
20
+ - zb@ubit.com
21
+ - japgolly@gmail.com
22
+ executables:
23
+ - saikuro
24
+ extensions: []
25
+ extra_rdoc_files:
26
+ - README
27
+ files:
28
+ - bin/saikuro
29
+ - lib/saikuro/usage.rb
30
+ - lib/saikuro/version.rb
31
+ - lib/saikuro.rb
32
+ - README
33
+ - tests/large_example.rb
34
+ - tests/samples.rb
35
+ homepage: https://github.com/metricfu/Saikuro
36
+ licenses:
37
+ - BSD
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ segments:
49
+ - 0
50
+ hash: -4041480192229165443
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: -4041480192229165443
60
+ requirements: []
61
+ rubyforge_project: Saikuro
62
+ rubygems_version: 1.8.25
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Saikuro is a Ruby cyclomatic complexity analyzer.
66
+ test_files:
67
+ - tests/large_example.rb
68
+ - tests/samples.rb