flog 4.6.6 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +19 -0
- data/Rakefile +3 -1
- data/lib/flog.rb +13 -12
- data/lib/flog_cli.rb +11 -4
- data/lib/flog_task.rb +4 -0
- data/test/test_flog.rb +35 -20
- data/test/test_flog_cli.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +13 -13
- metadata.gz.sig +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad09cd2ae98738c0d08e2e366636604774c3ae81a38c15e1feec23220b392243
|
4
|
+
data.tar.gz: b5e85e4f01c0d0297a3c929c93bab48bf393d813a048e34a6808353c1f56cfaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51a2c880e819dc4e31e62a94b990176f2d83fb755b78c5e0c84dcefa95ee1a87b5f4a2e610ad5af2e0e9986921c01b5e528f0e452c788e3c940c579e1b6a0273
|
7
|
+
data.tar.gz: b01ab52f28fcf8ee2c57927586abfc8e7c36bbb982e1e4c0ab2a8a8c1c367c00a48b0bd81c1f1ba96425c39f57bca5923e8a5a0d365af2453fec8cc93e24f8bf
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
=== 4.8.0 / 2023-09-28
|
2
|
+
|
3
|
+
* 2 minor enhancements:
|
4
|
+
|
5
|
+
* Added ability to pass down option overrides through Flog.run.
|
6
|
+
* Removed ancient File.binread alias.
|
7
|
+
|
8
|
+
* 1 bug fix:
|
9
|
+
|
10
|
+
* Added missing rdoc.
|
11
|
+
|
12
|
+
=== 4.7.0 / 2023-07-18
|
13
|
+
|
14
|
+
* 3 minor enhancements:
|
15
|
+
|
16
|
+
* Extend flog to process complex numbers. (petergoldstein)
|
17
|
+
* Only penalize magic numbers if they're not assigned to a const (excludes 0/-1).
|
18
|
+
* Renamed :lit_fixnum to :magic_number.
|
19
|
+
|
1
20
|
=== 4.6.6 / 2022-07-03
|
2
21
|
|
3
22
|
* 1 minor enhancement:
|
data/Rakefile
CHANGED
@@ -40,17 +40,19 @@ task :debug do
|
|
40
40
|
file = ENV["F"]
|
41
41
|
ruby = ENV["R"]
|
42
42
|
details = ENV["D"]
|
43
|
+
continue = ENV["C"]
|
43
44
|
|
44
45
|
flog = FlogCLI.new :parser => RubyParser
|
45
46
|
|
46
47
|
flog.option[:details] = true if details
|
48
|
+
flog.option[:continue] = true if continue
|
47
49
|
|
48
50
|
if file then
|
49
51
|
if File.directory? file then # quick hack to get directory scanning going
|
50
52
|
argv = [file]
|
51
53
|
argv.unshift "-v" if ENV["V"]
|
52
54
|
|
53
|
-
FlogCLI.run argv
|
55
|
+
FlogCLI.run argv, flog.option
|
54
56
|
exit 0
|
55
57
|
end
|
56
58
|
flog.flog file
|
data/lib/flog.rb
CHANGED
@@ -2,16 +2,17 @@ require "sexp_processor"
|
|
2
2
|
require "ruby_parser"
|
3
3
|
require "timeout"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
##
|
6
|
+
# Flog is a SexpProcessor that calculates a ABC (assignments,
|
7
|
+
# branches, conditionals) complexity metric with some ruby-aware
|
8
|
+
# enhancements and a compounding penalty for increasing depth.
|
9
|
+
#
|
10
|
+
# In essence, this calculates the most tortured code. The higher the
|
11
|
+
# score, the more pain the code is in and the harder it is to
|
12
|
+
# thoroughly test.
|
12
13
|
|
13
14
|
class Flog < MethodBasedSexpProcessor
|
14
|
-
VERSION = "4.
|
15
|
+
VERSION = "4.8.0" # :nodoc:
|
15
16
|
|
16
17
|
##
|
17
18
|
# Cut off point where the report should stop unless --all given.
|
@@ -40,7 +41,7 @@ class Flog < MethodBasedSexpProcessor
|
|
40
41
|
:block_pass => 1,
|
41
42
|
:block_call => 1,
|
42
43
|
:branch => 1,
|
43
|
-
:
|
44
|
+
:magic_number => 0.25,
|
44
45
|
:sclass => 5,
|
45
46
|
:super => 1,
|
46
47
|
:to_proc_icky! => 10,
|
@@ -508,9 +509,9 @@ class Flog < MethodBasedSexpProcessor
|
|
508
509
|
when 0, -1 then
|
509
510
|
# ignore those because they're used as array indicies instead of
|
510
511
|
# first/last
|
511
|
-
when Integer, Rational then
|
512
|
-
add_to_score :
|
513
|
-
when
|
512
|
+
when Integer, Float, Rational, Complex then
|
513
|
+
add_to_score :magic_number unless context[1] == :cdecl
|
514
|
+
when Symbol, Regexp, Range then
|
514
515
|
# do nothing
|
515
516
|
else
|
516
517
|
raise "Unhandled lit: #{value.inspect}:#{value.class}"
|
data/lib/flog_cli.rb
CHANGED
@@ -5,6 +5,10 @@ require "forwardable"
|
|
5
5
|
require "path_expander"
|
6
6
|
require "flog"
|
7
7
|
|
8
|
+
##
|
9
|
+
# This is the CLI interface for Flog, responsible for processing
|
10
|
+
# options, finding files, loading plugins, and reporting results.
|
11
|
+
|
8
12
|
class FlogCLI
|
9
13
|
extend Forwardable
|
10
14
|
|
@@ -13,13 +17,16 @@ class FlogCLI
|
|
13
17
|
def_delegators :@flog, :threshold, :total_score, :no_method, :calculate_total_scores
|
14
18
|
def_delegators :@flog, :max_method
|
15
19
|
|
16
|
-
|
20
|
+
##
|
21
|
+
# This kicks off the whole thing.
|
22
|
+
|
23
|
+
def self.run args = ARGV, extra = {}
|
17
24
|
load_plugins
|
18
25
|
|
19
26
|
expander = PathExpander.new args, "**/*.{rb,rake}"
|
20
27
|
files = expander.process
|
21
28
|
|
22
|
-
options = parse_options args
|
29
|
+
options = parse_options args, extra
|
23
30
|
|
24
31
|
abort "no files or stdin (-) to process, aborting." if
|
25
32
|
files.empty? and args.empty?
|
@@ -66,12 +73,12 @@ class FlogCLI
|
|
66
73
|
##
|
67
74
|
# Parse options in +args+ (defaults to ARGV).
|
68
75
|
|
69
|
-
def self.parse_options args = ARGV
|
76
|
+
def self.parse_options args = ARGV, extra_options = {}
|
70
77
|
option = {
|
71
78
|
:quiet => false,
|
72
79
|
:continue => false,
|
73
80
|
:parser => RubyParser,
|
74
|
-
}
|
81
|
+
}.merge extra_options
|
75
82
|
|
76
83
|
OptionParser.new do |opts|
|
77
84
|
opts.separator "Standard options:"
|
data/lib/flog_task.rb
CHANGED
data/test/test_flog.rb
CHANGED
@@ -44,7 +44,7 @@ class TestFlog < FlogTest
|
|
44
44
|
def test_flog
|
45
45
|
setup_flog
|
46
46
|
|
47
|
-
exp = { "main#none" => { :+ => 1.0, :
|
47
|
+
exp = { "main#none" => { :+ => 1.0, :magic_number => 0.6 } }
|
48
48
|
assert_equal exp, @flog.calls
|
49
49
|
|
50
50
|
assert_in_epsilon 1.6, @flog.total_score unless @flog.option[:methods]
|
@@ -58,7 +58,7 @@ class TestFlog < FlogTest
|
|
58
58
|
@flog.flog_ruby ruby, file
|
59
59
|
@flog.calculate_total_scores
|
60
60
|
|
61
|
-
exp = { "main#none" => { :+ => 1.0, :
|
61
|
+
exp = { "main#none" => { :+ => 1.0, :magic_number => 0.6 } }
|
62
62
|
assert_equal exp, @flog.calls
|
63
63
|
|
64
64
|
assert_in_epsilon 1.6, @flog.total_score unless @flog.option[:methods]
|
@@ -173,7 +173,7 @@ class TestFlog < FlogTest
|
|
173
173
|
s(:iter, s(:call, nil, :lambda), nil, s(:lit, 1)))
|
174
174
|
|
175
175
|
assert_process(sexp, 12.316,
|
176
|
-
:
|
176
|
+
:magic_number => 0.275,
|
177
177
|
:block_pass => 1.0,
|
178
178
|
:lambda => 1.0,
|
179
179
|
:block_call => 1.0,
|
@@ -187,7 +187,7 @@ class TestFlog < FlogTest
|
|
187
187
|
s(:iter, s(:call, nil, :lambda), nil, s(:lit, 1))))
|
188
188
|
|
189
189
|
assert_process(sexp, 17.333,
|
190
|
-
:
|
190
|
+
:magic_number => 0.275,
|
191
191
|
:block_pass => 1.0,
|
192
192
|
:lambda => 1.0,
|
193
193
|
:assignment => 1.0,
|
@@ -250,7 +250,7 @@ class TestFlog < FlogTest
|
|
250
250
|
s(:colon2, s(:const, :X), :Y), nil,
|
251
251
|
s(:scope, s(:lit, 42)))
|
252
252
|
|
253
|
-
assert_process sexp, 0.25, :
|
253
|
+
assert_process sexp, 0.25, :magic_number => 0.25
|
254
254
|
end
|
255
255
|
|
256
256
|
# TODO:
|
@@ -275,7 +275,7 @@ class TestFlog < FlogTest
|
|
275
275
|
s(:block,
|
276
276
|
s(:lit, 42))))
|
277
277
|
|
278
|
-
assert_process sexp, 0.275, :
|
278
|
+
assert_process sexp, 0.275, :magic_number => 0.275
|
279
279
|
end
|
280
280
|
|
281
281
|
def test_process_defn_in_self
|
@@ -288,7 +288,7 @@ class TestFlog < FlogTest
|
|
288
288
|
@flog.process sexp
|
289
289
|
@flog.calculate_total_scores
|
290
290
|
|
291
|
-
exp = {'main::x' => {:
|
291
|
+
exp = {'main::x' => {:magic_number => 0.375}, 'main#none' => {:sclass => 5.0}}
|
292
292
|
assert_equal exp, @flog.calls
|
293
293
|
|
294
294
|
assert_in_delta 5.375, @flog.total_score
|
@@ -305,7 +305,7 @@ class TestFlog < FlogTest
|
|
305
305
|
@flog.process sexp
|
306
306
|
@flog.calculate_total_scores
|
307
307
|
|
308
|
-
exp = {'main::x' => {:
|
308
|
+
exp = {'main::x' => {:magic_number => 0.375}, 'main#none' => {:sclass => 12.5}}
|
309
309
|
assert_equal exp, @flog.calls
|
310
310
|
|
311
311
|
assert_in_delta 12.875, @flog.total_score
|
@@ -320,7 +320,7 @@ class TestFlog < FlogTest
|
|
320
320
|
s(:block,
|
321
321
|
s(:lit, 42))))
|
322
322
|
|
323
|
-
assert_process sexp, 0.275, :
|
323
|
+
assert_process sexp, 0.275, :magic_number => 0.275
|
324
324
|
end
|
325
325
|
|
326
326
|
# FIX: huh? over-refactored?
|
@@ -386,7 +386,7 @@ class TestFlog < FlogTest
|
|
386
386
|
|
387
387
|
@klass, @meth = "task", "#woot"
|
388
388
|
|
389
|
-
assert_process sexp, 2.3, :something => 1.0, :task => 1.0, :
|
389
|
+
assert_process sexp, 2.3, :something => 1.0, :task => 1.0, :magic_number => 0.3
|
390
390
|
end
|
391
391
|
|
392
392
|
def test_process_iter_dsl_hash_when_hash_empty
|
@@ -423,7 +423,7 @@ class TestFlog < FlogTest
|
|
423
423
|
hash = {
|
424
424
|
"namespace(blah)::task#woot" => {
|
425
425
|
:something => 1.0,
|
426
|
-
:
|
426
|
+
:magic_number => 0.3,
|
427
427
|
:task => 1.0,
|
428
428
|
},
|
429
429
|
"namespace#blah" => {
|
@@ -446,14 +446,29 @@ class TestFlog < FlogTest
|
|
446
446
|
|
447
447
|
def test_process_lit_int
|
448
448
|
sexp = s(:lit, 42)
|
449
|
-
assert_process sexp, 0.25, :
|
449
|
+
assert_process sexp, 0.25, :magic_number => 0.25
|
450
|
+
end
|
451
|
+
|
452
|
+
def test_process_lit_int__const
|
453
|
+
sexp = s(:cdecl, :X, s(:lit, 42))
|
454
|
+
assert_process sexp, 0.0
|
450
455
|
end
|
451
456
|
|
452
457
|
def test_process_lit_float # and other lits
|
453
|
-
sexp = s(:lit, 3.1415)
|
458
|
+
sexp = s(:lit, 3.1415)
|
459
|
+
assert_process sexp, 0.25, :magic_number => 0.25
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_process_lit_float__const
|
463
|
+
sexp = s(:cdecl, :X, s(:lit, 3.1415))
|
454
464
|
assert_process sexp, 0.0
|
455
465
|
end
|
456
466
|
|
467
|
+
def test_process_lit_complex
|
468
|
+
sexp = s(:lit, (0+1i))
|
469
|
+
assert_process sexp, 0.25
|
470
|
+
end
|
471
|
+
|
457
472
|
def test_process_lit_bad
|
458
473
|
assert_raises RuntimeError do
|
459
474
|
@flog.process s(:lit, Object.new)
|
@@ -475,12 +490,12 @@ class TestFlog < FlogTest
|
|
475
490
|
s(:colon2, s(:const, :X), :Y),
|
476
491
|
s(:scope, s(:lit, 42)))
|
477
492
|
|
478
|
-
assert_process sexp, 0.25, :
|
493
|
+
assert_process sexp, 0.25, :magic_number => 0.25
|
479
494
|
end
|
480
495
|
|
481
496
|
def test_process_sclass
|
482
497
|
sexp = s(:sclass, s(:self), s(:scope, s(:lit, 42)))
|
483
|
-
assert_process sexp, 5.375, :sclass => 5.0, :
|
498
|
+
assert_process sexp, 5.375, :sclass => 5.0, :magic_number => 0.375
|
484
499
|
end
|
485
500
|
|
486
501
|
def test_process_super
|
@@ -488,7 +503,7 @@ class TestFlog < FlogTest
|
|
488
503
|
assert_process sexp, 1.0, :super => 1.0
|
489
504
|
|
490
505
|
sexp = s(:super, s(:lit, 42))
|
491
|
-
assert_process sexp, 1.25, :super => 1.0, :
|
506
|
+
assert_process sexp, 1.25, :super => 1.0, :magic_number => 0.25
|
492
507
|
end
|
493
508
|
|
494
509
|
def test_process_while
|
@@ -505,10 +520,10 @@ class TestFlog < FlogTest
|
|
505
520
|
assert_process sexp, 1.00, :yield => 1.0
|
506
521
|
|
507
522
|
sexp = s(:yield, s(:lit, 4))
|
508
|
-
assert_process sexp, 1.25, :yield => 1.0, :
|
523
|
+
assert_process sexp, 1.25, :yield => 1.0, :magic_number => 0.25
|
509
524
|
|
510
525
|
sexp = s(:yield, s(:lit, 42), s(:lit, 24))
|
511
|
-
assert_process sexp, 1.50, :yield => 1.0, :
|
526
|
+
assert_process sexp, 1.50, :yield => 1.0, :magic_number => 0.50
|
512
527
|
end
|
513
528
|
|
514
529
|
def test_score_method
|
@@ -617,7 +632,7 @@ class TestFlog < FlogTest
|
|
617
632
|
@flog.calculate_total_scores
|
618
633
|
@flog.calculate
|
619
634
|
|
620
|
-
assert_equal({ 'User#blah' => 'user.rb:3-
|
635
|
+
assert_equal({ 'User#blah' => 'user.rb:3-5' }, @flog.method_locations)
|
621
636
|
assert_equal({ "User#blah" => 2.2 }, @flog.totals)
|
622
637
|
assert_in_epsilon(2.2, @flog.total_score)
|
623
638
|
assert_in_epsilon(1.0, @flog.multiplier)
|
@@ -639,7 +654,7 @@ class TestFlog < FlogTest
|
|
639
654
|
@flog.calculate_total_scores
|
640
655
|
@flog.calculate
|
641
656
|
|
642
|
-
assert_equal({ 'Coder#happy?' => 'coder.rb:3-
|
657
|
+
assert_equal({ 'Coder#happy?' => 'coder.rb:3-5' }, @flog.method_locations)
|
643
658
|
assert_equal({ "Coder#happy?" => 1.0 }, @flog.totals)
|
644
659
|
assert_in_epsilon(1.0, @flog.total_score)
|
645
660
|
assert_in_epsilon(1.0, @flog.multiplier)
|
data/test/test_flog_cli.rb
CHANGED
@@ -135,7 +135,7 @@ class TestFlogCLI < FlogTest
|
|
135
135
|
|
136
136
|
expected = "\n 1.6: main#none
|
137
137
|
1.0: +
|
138
|
-
0.6:
|
138
|
+
0.6: magic_number
|
139
139
|
|
140
140
|
"
|
141
141
|
|
@@ -165,7 +165,7 @@ class TestFlogCLI < FlogTest
|
|
165
165
|
|
166
166
|
@flog.flog "-"
|
167
167
|
|
168
|
-
exp = { "main#none" => { :+ => 1.0, :
|
168
|
+
exp = { "main#none" => { :+ => 1.0, :magic_number => 0.6 } }
|
169
169
|
assert_equal exp, @flog.calls
|
170
170
|
|
171
171
|
@flog.option[:all] = true
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDPjCCAiagAwIBAgIBBzANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
|
14
14
|
ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJem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: 2023-09-28 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: sexp_processor
|
@@ -119,14 +119,14 @@ dependencies:
|
|
119
119
|
requirements:
|
120
120
|
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
122
|
+
version: '4.0'
|
123
123
|
type: :development
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
129
|
+
version: '4.0'
|
130
130
|
description: |-
|
131
131
|
Flog reports the most tortured code in an easy to read pain
|
132
132
|
report. The higher the score, the more pain the code is in.
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
178
|
+
rubygems_version: 3.4.10
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: Flog reports the most tortured code in an easy to read pain report
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
�
|
1
|
+
&&���I[� ���W��nCf<�������Lf(�/J���ЮY���uI��S�ީI�V�Һ����RJ?�
|
2
|
+
"�l)�,*IS8�`J��+Ҙ���r�Q�O�Fh`
|
3
|
+
�0�r��:�a7����1��A�w���`?�P��T��}��h�D*�NU� Iu�f*ק@e)s�04
|