flog 4.7.0 → 4.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bde1a28d5e030ce021a8f20e9d7e877714e2c91e030b7560c3da7337a8a1e916
4
- data.tar.gz: 6b4dffe1d2a47f688deb1665a0a31a4c9ef5b901add108aac37489c97cb8f7ee
3
+ metadata.gz: 9047c8b22acece9cd9e5c1dbb2e44d486fd903c40bd80967d1e4c257fa8669a9
4
+ data.tar.gz: 69a903441dcc41ab504399e173f8d231a242869ffbc5b6aebfa74e758822c4af
5
5
  SHA512:
6
- metadata.gz: 56c6a3005252c00d8d61257f35f6eb9bf3d07b232acb316ebf5807dee9144c6bc76f24478ba64a000885677e1ba04d3d0af5ad8677934f90a5f8a965a2227f87
7
- data.tar.gz: 876c48e4a05cf087fb924f5c10977870facdec0f07c3cabd09eccee03360fca82d19a3b5a708e2a9bd51cd57f109d525b29cc50d22399fac17df3062b0d3c272
6
+ metadata.gz: 88c867edf9e72b5b1f392697f3de483dfd18234a620028eeb6a60527b5dbdc21e994afb103870fa2d79fd4d88a91301a35fc37c0d095b330d1469be72595b879
7
+ data.tar.gz: f57466932cb71074ae085276bb9dbc9f47e684f4da599ce52a33d2a94198d2e9d86b22a41094bf2f65f6a8afa3a3c4be369ded47f970bcaad21fe82d9e334dbd
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,50 @@
1
+ === 4.9.4 / 2026-01-06
2
+
3
+ * 2 bug fixes:
4
+
5
+ * Namespace NotRubyParser to avoid problems with bundler's horrid eager loading. (nateberkopec)
6
+ * Patch prism to recognize `it` as a local. (faisal)
7
+
8
+ === 4.9.3 / 2026-01-05
9
+
10
+ * 1 bug fix:
11
+
12
+ * Fixed bug caused by last release duplicating (frozen) options hash. (nateberkopec)
13
+
14
+ === 4.9.2 / 2026-01-04
15
+
16
+ * 2 bug fixes:
17
+
18
+ * Duplicate passed in options in case frozen.
19
+ * Oops! Fixed --legacy option definition.
20
+
21
+ === 4.9.1 / 2025-12-20
22
+
23
+ * 4 bug fixes:
24
+
25
+ * Bumped dependency to prism to get some upstreamed fixes.
26
+ * Dropped ruby_parser dependency (now considered soft dep for --legacy flag).
27
+ * Minor cleanup of some of the upstreamed fixes.
28
+ * Re-add ruby_parser dependency until I can get a patch into prism to loosen it up.
29
+
30
+ === 4.9.0 / 2025-12-11
31
+
32
+ * 2 minor enhancements:
33
+
34
+ * Bumped path_expander to 2.0.0.
35
+ * Switched to prism for ruby parsing. Use --legacy for RubyParser.
36
+
37
+ === 4.8.0 / 2023-09-28
38
+
39
+ * 2 minor enhancements:
40
+
41
+ * Added ability to pass down option overrides through Flog.run.
42
+ * Removed ancient File.binread alias.
43
+
44
+ * 1 bug fix:
45
+
46
+ * Added missing rdoc.
47
+
1
48
  === 4.7.0 / 2023-07-18
2
49
 
3
50
  * 3 minor enhancements:
data/Rakefile CHANGED
@@ -3,9 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
- Hoe.add_include_dirs("../../ruby_parser/dev/lib",
7
- "../../RubyInline/dev/lib",
8
- "../../sexp_processor/dev/lib",
6
+ Hoe.add_include_dirs("../../sexp_processor/dev/lib",
9
7
  "../../ZenTest/dev/lib",
10
8
  "../../path_expander/dev/lib",
11
9
  "lib")
@@ -24,10 +22,8 @@ Hoe.spec 'flog' do
24
22
  license "MIT"
25
23
 
26
24
  dependency "sexp_processor", "~> 4.8"
27
- dependency "ruby_parser", ["~> 3.1", "> 3.1.0"]
28
- dependency "path_expander", "~> 1.0"
29
-
30
- dependency "minitest", "~> 5.0", :dev
25
+ dependency "prism", "~> 1.7"
26
+ dependency "path_expander", "~> 2.0"
31
27
  end
32
28
 
33
29
  task :debug do
@@ -40,17 +36,19 @@ task :debug do
40
36
  file = ENV["F"]
41
37
  ruby = ENV["R"]
42
38
  details = ENV["D"]
39
+ continue = ENV["C"]
43
40
 
44
- flog = FlogCLI.new :parser => RubyParser
41
+ flog = FlogCLI.new
45
42
 
46
43
  flog.option[:details] = true if details
44
+ flog.option[:continue] = true if continue
47
45
 
48
46
  if file then
49
47
  if File.directory? file then # quick hack to get directory scanning going
50
48
  argv = [file]
51
49
  argv.unshift "-v" if ENV["V"]
52
50
 
53
- FlogCLI.run argv
51
+ FlogCLI.run argv, flog.option
54
52
  exit 0
55
53
  end
56
54
  flog.flog file
data/bin/flog CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env -S ruby -w
2
2
 
3
- require "flog_cli"
3
+ require_relative "../lib/flog_cli"
4
4
 
5
5
  FlogCLI.run
6
6
 
data/lib/flog.rb CHANGED
@@ -1,25 +1,37 @@
1
1
  require "sexp_processor"
2
- require "ruby_parser"
2
+ require "prism"
3
+ require "prism/translation/ruby_parser"
3
4
  require "timeout"
5
+ require "racc" # for Racc::ParseError
4
6
 
5
- class File
6
- RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19 # :nodoc:
7
-
8
- class << self
9
- alias :binread :read unless RUBY19
7
+ class Prism::Translation::RubyParser
8
+ module TweakIt
9
+ def visit_it_local_variable_read_node(node) # TODO: upstream
10
+ s(node, :lvar, :it)
11
+ end
10
12
  end
13
+ Compiler.prepend TweakIt
11
14
  end
12
15
 
16
+ ##
17
+ # Flog is a SexpProcessor that calculates a ABC (assignments,
18
+ # branches, conditionals) complexity metric with some ruby-aware
19
+ # enhancements and a compounding penalty for increasing depth.
20
+ #
21
+ # In essence, this calculates the most tortured code. The higher the
22
+ # score, the more pain the code is in and the harder it is to
23
+ # thoroughly test.
24
+
13
25
  class Flog < MethodBasedSexpProcessor
14
- VERSION = "4.7.0" # :nodoc:
26
+ VERSION = "4.9.4" # :nodoc:
27
+
28
+ NotRubyParser = Class.new Prism::Translation::RubyParser # compatibility layer :nodoc:
15
29
 
16
30
  ##
17
31
  # Cut off point where the report should stop unless --all given.
18
32
 
19
33
  DEFAULT_THRESHOLD = 0.60
20
34
 
21
- THRESHOLD = DEFAULT_THRESHOLD # :nodoc:
22
-
23
35
  ##
24
36
  # The scoring system hash. Maps node type to score.
25
37
 
@@ -208,7 +220,7 @@ class Flog < MethodBasedSexpProcessor
208
220
  # methods. Does not handle timeouts or syntax errors. See #flog_ruby.
209
221
 
210
222
  def flog_ruby! ruby, file="-", timeout = 10
211
- @parser = (option[:parser] || RubyParser).new
223
+ @parser = option[:parser].new
212
224
 
213
225
  warn "** flogging #{file}" if option[:verbose]
214
226
 
@@ -225,10 +237,11 @@ class Flog < MethodBasedSexpProcessor
225
237
 
226
238
  def initialize option = {}
227
239
  super()
228
- @option = option
240
+ @option = option = option.dup
229
241
  @mass = {}
230
242
  @parser = nil
231
243
  @threshold = option[:threshold] || DEFAULT_THRESHOLD
244
+ option[:parser] ||= NotRubyParser
232
245
  self.auto_shift_type = true
233
246
  self.reset
234
247
  end
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
- def self.run args = ARGV
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
- files = expander.process
27
+ files = expander.process.to_a
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
- :parser => RubyParser,
74
- }
80
+ :parser => nil,
81
+ }.merge extra_options
75
82
 
76
83
  OptionParser.new do |opts|
77
84
  opts.separator "Standard options:"
@@ -123,6 +130,11 @@ class FlogCLI
123
130
  option[:score] = true
124
131
  end
125
132
 
133
+ opts.on "--legacy", "Use RubyParser for parsing." do
134
+ require "ruby_parser"
135
+ option[:parser] = RubyParser
136
+ end
137
+
126
138
  opts.on("-tN", "--threshold=N", Integer, "Set the report cutoff threshold (def: 60%).") do |n|
127
139
  option[:threshold] = n / 100.0
128
140
  end
data/lib/flog_task.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'rake/tasklib'
2
2
 
3
+ ##
4
+ # A rake front-end for flog, allowing task creation with options for
5
+ # verbosity, reporting, and a failure threshold.
6
+
3
7
  class FlogTask < Rake::TaskLib
4
8
  ##
5
9
  # The name of the task. Defaults to :flog
data/test/test_flog.rb CHANGED
@@ -19,7 +19,7 @@ end
19
19
 
20
20
  class TestFlog < FlogTest
21
21
  def setup
22
- @flog = Flog.new :parser => RubyParser
22
+ @flog = Flog.new
23
23
  end
24
24
 
25
25
  def test_add_to_score
@@ -344,6 +344,17 @@ class TestFlog < FlogTest
344
344
  assert_process sexp, 2.326, :loop => 1.0, :branch => 1.1, :block_call => 1
345
345
  end
346
346
 
347
+ def test_process_iter__it
348
+ ruby = "blah { puts it }"
349
+ sexp = s(:iter,
350
+ s(:call, nil, :blah), 0,
351
+ s(:call, nil, :puts, s(:lvar, :it)))
352
+
353
+ assert_parse sexp, ruby
354
+
355
+ assert_process sexp, 2.326, blah: 1, block_call: 1, puts: 1.1
356
+ end
357
+
347
358
  def test_process_iter_dsl
348
359
  # task :blah do
349
360
  # something
@@ -465,7 +476,7 @@ class TestFlog < FlogTest
465
476
  end
466
477
 
467
478
  def test_process_lit_complex
468
- sexp = s(:lit, (0+1i))
479
+ sexp = eval 's(:lit, 0+1i)' # stupid emacs is borking on the complex
469
480
  assert_process sexp, 0.25
470
481
  end
471
482
 
@@ -571,6 +582,10 @@ class TestFlog < FlogTest
571
582
  end
572
583
  end
573
584
 
585
+ def assert_parse sexp, ruby
586
+ assert_equal sexp, Flog::NotRubyParser.new.process(ruby)
587
+ end
588
+
574
589
  def assert_process sexp, score = -1, hash = {}
575
590
  setup
576
591
  @flog.process sexp
@@ -697,3 +712,15 @@ class TestFlog < FlogTest
697
712
  @flog.add_to_score "blah", 42
698
713
  end
699
714
  end
715
+
716
+ class TestFlogDefaultOptions < Minitest::Test
717
+ def test_flog_with_default_options
718
+ # Regression test for issue #84
719
+ # Flog should work with default options (no explicit parser)
720
+ flog = Flog.new
721
+ flog.flog_ruby "2 + 3", "test.rb"
722
+ flog.calculate_total_scores
723
+
724
+ assert_in_epsilon 1.6, flog.total_score
725
+ end
726
+ end
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class TestFlogCLI < FlogTest
11
11
  def setup
12
- @flog = FlogCLI.new :parser => RubyParser
12
+ @flog = FlogCLI.new
13
13
  end
14
14
 
15
15
  def test_cls_parse_options
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
12
11
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBBzANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
12
+ MIIDPjCCAiagAwIBAgIBCjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
13
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQY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kE7e2BKmgQE42vSOZMce0kCEAPbx0
26
+ rQtqonfWTHQ8UbQ7GqCL3gDQ0QDD2B+HUlb4uaCZ2icxqa/eOtxMvHC2tj+h0xKY
27
+ xL84ipM5kr0bHGf9/MRZJWcw51urueNycBXu1Xh+pEN8qBmYsFRR4SIODLClybAO
28
+ 6cbm2PyPQgKNiqE4H+IQrDVHd9bJs1XgLElk3qoaJBWXc/5fy0J1imYb25UqmiHG
29
+ snGe1hrppvBRdcyEzvhfIPjI
31
30
  -----END CERTIFICATE-----
32
- date: 2023-07-18 00:00:00.000000000 Z
31
+ date: 1980-01-02 00:00:00.000000000 Z
33
32
  dependencies:
34
33
  - !ruby/object:Gem::Dependency
35
34
  name: sexp_processor
@@ -46,87 +45,67 @@ dependencies:
46
45
  - !ruby/object:Gem::Version
47
46
  version: '4.8'
48
47
  - !ruby/object:Gem::Dependency
49
- name: ruby_parser
48
+ name: prism
50
49
  requirement: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '3.1'
55
- - - ">"
56
- - !ruby/object:Gem::Version
57
- version: 3.1.0
53
+ version: '1.7'
58
54
  type: :runtime
59
55
  prerelease: false
60
56
  version_requirements: !ruby/object:Gem::Requirement
61
57
  requirements:
62
58
  - - "~>"
63
59
  - !ruby/object:Gem::Version
64
- version: '3.1'
65
- - - ">"
66
- - !ruby/object:Gem::Version
67
- version: 3.1.0
60
+ version: '1.7'
68
61
  - !ruby/object:Gem::Dependency
69
62
  name: path_expander
70
63
  requirement: !ruby/object:Gem::Requirement
71
64
  requirements:
72
65
  - - "~>"
73
66
  - !ruby/object:Gem::Version
74
- version: '1.0'
67
+ version: '2.0'
75
68
  type: :runtime
76
69
  prerelease: false
77
70
  version_requirements: !ruby/object:Gem::Requirement
78
71
  requirements:
79
72
  - - "~>"
80
73
  - !ruby/object:Gem::Version
81
- version: '1.0'
82
- - !ruby/object:Gem::Dependency
83
- name: minitest
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '5.0'
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '5.0'
74
+ version: '2.0'
96
75
  - !ruby/object:Gem::Dependency
97
76
  name: rdoc
98
77
  requirement: !ruby/object:Gem::Requirement
99
78
  requirements:
100
79
  - - ">="
101
80
  - !ruby/object:Gem::Version
102
- version: '4.0'
81
+ version: '6.0'
103
82
  - - "<"
104
83
  - !ruby/object:Gem::Version
105
- version: '7'
84
+ version: '8'
106
85
  type: :development
107
86
  prerelease: false
108
87
  version_requirements: !ruby/object:Gem::Requirement
109
88
  requirements:
110
89
  - - ">="
111
90
  - !ruby/object:Gem::Version
112
- version: '4.0'
91
+ version: '6.0'
113
92
  - - "<"
114
93
  - !ruby/object:Gem::Version
115
- version: '7'
94
+ version: '8'
116
95
  - !ruby/object:Gem::Dependency
117
96
  name: hoe
118
97
  requirement: !ruby/object:Gem::Requirement
119
98
  requirements:
120
99
  - - "~>"
121
100
  - !ruby/object:Gem::Version
122
- version: '4.0'
101
+ version: '4.5'
123
102
  type: :development
124
103
  prerelease: false
125
104
  version_requirements: !ruby/object:Gem::Requirement
126
105
  requirements:
127
106
  - - "~>"
128
107
  - !ruby/object:Gem::Version
129
- version: '4.0'
108
+ version: '4.5'
130
109
  description: |-
131
110
  Flog reports the most tortured code in an easy to read pain
132
111
  report. The higher the score, the more pain the code is in.
@@ -158,7 +137,6 @@ licenses:
158
137
  metadata:
159
138
  homepage_uri: http://ruby.sadi.st/
160
139
  source_code_uri: https://github.com/seattlerb/flog
161
- post_install_message:
162
140
  rdoc_options:
163
141
  - "--main"
164
142
  - README.rdoc
@@ -175,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
153
  - !ruby/object:Gem::Version
176
154
  version: '0'
177
155
  requirements: []
178
- rubygems_version: 3.4.10
179
- signing_key:
156
+ rubygems_version: 3.7.2
180
157
  specification_version: 4
181
158
  summary: Flog reports the most tortured code in an easy to read pain report
182
159
  test_files: []
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- a���M�˒zlme��h��ᱣ�{(8C���m��lJ%(ߞ%��J�#�دW({u`B��ĩ�o7�<qNr��D���"�q
1
+ o�Z��q��˧T4}P�E#?hO������r�v��eZ�Ԡ�lÛ�BwK4���G-�~���6`�ӥ4���EB� H:,,�u�Ac���x��M�A���Ǜ�j����v�� �� �k��2y<V,��$C0��-둴��s��#��;7�*���n4RX��y;�����jGq�>L��z�}��|FG��r��l-���VH?9��;YQi��#,�}��0qPpyR��Fv3R ��18o ���h0T'