flay 2.13.3 → 2.14.0

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: f398ea8e7f796a1871faedb32dbee7d7377d30abcc91edd075f2015a6be95c74
4
- data.tar.gz: cdb49c908285be2c5c40118a33e7d0227e4a32a4b31736b374aaf31a43e58ac6
3
+ metadata.gz: 5c7f7b9d1cb38c582802edc030bce9090a4f6c5d407ff6f5bead6fda67acdeda
4
+ data.tar.gz: 3ea1d180981dbdada766c51a9073485f85bcf7847fa43328d32fe1d0fd9b52a5
5
5
  SHA512:
6
- metadata.gz: 9c7f5b54202e563702d21ee8006d24124dd7810bb3518ae307a1eba17966a042864af2c0b772df9deab11517a8a6268159e5503d6fe70845722ef3544b7b84a9
7
- data.tar.gz: 301d1e56ecfd1c12e8d41e826e56c44899598712aec55daac4ba55f74df547e5421250c3ea8dace955edaeacacd0a513c4a3e888f83aa47fddcfe340fb49c9b2
6
+ metadata.gz: 1057f752d2e665129fb259dee3dfc15c151b62fc928f77c1ab417e728a674dc47c6d90bf47ef63dfc7b9c0162d7f1d41ed43c5b30b63d631ded4f457ec9adf1f
7
+ data.tar.gz: 8d31dd5ae191f6055c36c6c77adeae47bd0309ab71ff3521469a22e4c7ff7cfbae829fcee8b4811dcad5f7d2f901a3a36b5ba1b63425f1cd63b029c69bbc6edd
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ === 2.14.0 / 2025-12-11
2
+
3
+ * 2 minor enhancements:
4
+
5
+ * Bumped path_expander to 2.0.0.
6
+ * Switched to prism for ruby parsing. Use --legacy for RubyParser.
7
+
1
8
  === 2.13.3 / 2024-05-21
2
9
 
3
10
  * 2 bug fixes:
data/Rakefile CHANGED
@@ -20,9 +20,9 @@ Hoe.spec "flay" do
20
20
  license "MIT"
21
21
 
22
22
  dependency "sexp_processor", "~> 4.0"
23
- dependency "ruby_parser", "~> 3.0"
23
+ dependency "prism", "~> 1.5"
24
24
  dependency "erubi", "~> 1.10"
25
- dependency "path_expander", "~> 1.0"
25
+ dependency "path_expander", "~> 2.0"
26
26
 
27
27
  dependency "minitest", "~> 5.8.0", :dev
28
28
  dependency "ruby2ruby", "~> 2.2.0", :dev
data/lib/flay.rb CHANGED
@@ -2,13 +2,63 @@
2
2
 
3
3
  require "optparse"
4
4
  require "sexp_processor"
5
- require "ruby_parser"
6
5
  require "path_expander"
7
6
  require "timeout"
8
7
  require "zlib"
9
8
 
9
+ require "prism"
10
+ require "prism/translation/ruby_parser"
11
+
12
+ unless Prism::Translation::RubyParser.method_defined? :process then
13
+ module PrismCompilerMonkeyPatches
14
+ def attach_comments sexp, node
15
+ return unless node.comments
16
+ return if node.comments.empty?
17
+
18
+ extra = node.location.start_line - node.comments.last.location.start_line
19
+ comments = node.comments.map(&:slice)
20
+ comments.concat [nil] * extra
21
+ sexp.comments = comments.join "\n"
22
+ end
23
+
24
+ def visit_class_node(node) = super.tap { |sexp| attach_comments sexp, node }
25
+ def visit_def_node(node) = super.tap { |sexp| attach_comments sexp, node }
26
+ def visit_module_node(node) = super.tap { |sexp| attach_comments sexp, node }
27
+ end
28
+
29
+ module PrismRPMonkeyPatches
30
+ def process ruby, file="(string)", timeout=nil
31
+ Timeout.timeout timeout do
32
+ parse ruby, file
33
+ end
34
+ end
35
+
36
+ def translate(result, filepath)
37
+ result.attach_comments!
38
+ super
39
+ end
40
+ end
41
+
42
+ module Prism
43
+ module Translation
44
+ class RubyParser
45
+ prepend PrismRPMonkeyPatches
46
+
47
+ class Compiler
48
+ prepend PrismCompilerMonkeyPatches
49
+ end
50
+ end
51
+ end
52
+ end
53
+ else
54
+ warn "Tell zenspider to remove prism monkeypatches: #{caller.first}"
55
+ end
56
+
57
+ class NotRubyParser < Prism::Translation::RubyParser # compatibility layer
58
+ end
59
+
10
60
  class Flay
11
- VERSION = "2.13.3" # :nodoc:
61
+ VERSION = "2.14.0" # :nodoc:
12
62
 
13
63
  class Item < Struct.new(:structural_hash, :name, :bonus, :mass, :locations)
14
64
  alias identical? bonus
@@ -45,6 +95,7 @@ class Flay
45
95
  :fuzzy => false,
46
96
  :only => nil,
47
97
  :filters => [],
98
+ :parser => NotRubyParser,
48
99
  }
49
100
  end
50
101
 
@@ -106,6 +157,11 @@ class Flay
106
157
  options[:timeout] = t.to_i
107
158
  end
108
159
 
160
+ opts.on("-t", "--legacy", "Use RubyParser to parse.") do
161
+ require "ruby_parser"
162
+ options[:parser] = RubyParser
163
+ end
164
+
109
165
  extensions = ["rb"] + Flay.load_plugins
110
166
 
111
167
  opts.separator ""
@@ -266,7 +322,8 @@ class Flay
266
322
 
267
323
  def process_rb file
268
324
  begin
269
- RubyParser.new.process(File.binread(file), file, option[:timeout])
325
+ parser = option[:parser].new
326
+ parser.process(File.binread(file), file, option[:timeout])
270
327
  rescue Timeout::Error
271
328
  warn "TIMEOUT parsing #{file}. Skipping."
272
329
  end
@@ -445,7 +502,7 @@ class Flay
445
502
  end
446
503
 
447
504
  def collapse_and_label ary # :nodoc:
448
- ary[0].zip(*ary[1..-1]).map { |lines|
505
+ ary.first.zip(*ary.drop(1)).map { |lines|
449
506
  if lines.uniq.size == 1 then
450
507
  " #{lines.first}"
451
508
  else
data/lib/flay_erb.rb CHANGED
@@ -13,7 +13,8 @@ class Flay
13
13
  ruby = Erubi.new(erb).src
14
14
 
15
15
  begin
16
- RubyParser.new.process(ruby, file)
16
+ parser = option[:parser].new
17
+ parser.process(ruby, file, option[:timeout])
17
18
  rescue => e
18
19
  warn ruby if option[:verbose]
19
20
  raise e
data/test/test_flay.rb CHANGED
@@ -8,7 +8,6 @@ $: << "../../sexp_processor/dev/lib"
8
8
 
9
9
  class TestSexp < Minitest::Test
10
10
  OPTS = Flay.parse_options %w[--mass=1 -v]
11
- DEF_OPTS = {:diff=>false, :mass=>16, :summary=>false, :verbose=>false, :number=>true, :timeout=>10, :liberal=>false, :fuzzy=>false, :only=>nil}
12
11
 
13
12
  def setup
14
13
  # a(1) { |c| d }
@@ -65,7 +64,7 @@ class TestSexp < Minitest::Test
65
64
  assert_equal expected, x.sort.uniq
66
65
  end
67
66
 
68
- DOG_AND_CAT = RubyParser.new.process <<-RUBY
67
+ DOG_AND_CAT = NotRubyParser.new.process <<~RUBY
69
68
  ##
70
69
  # I am a dog.
71
70
 
@@ -88,7 +87,7 @@ class TestSexp < Minitest::Test
88
87
  end
89
88
  RUBY
90
89
 
91
- ROUND = RubyParser.new.process <<-RUBY
90
+ ROUND = NotRubyParser.new.process <<~RUBY
92
91
  def x(n)
93
92
  if n % 2 == 0
94
93
  return n
@@ -106,7 +105,7 @@ class TestSexp < Minitest::Test
106
105
  flay.process_sexp s(:outer,contained)
107
106
  2.times { flay.process_sexp s(:outer,container) }
108
107
 
109
- exp = eval <<-EOM # just to prevent emacs from reindenting it
108
+ exp = eval <<~EOM # just to prevent emacs from reindenting it
110
109
  [
111
110
  [ s(:a, s(:b, s(:c)), s(:d, s(:e))),
112
111
  s(:a, s(:b, s(:c)), s(:d, s(:e))),
@@ -142,7 +141,7 @@ class TestSexp < Minitest::Test
142
141
  flay.process_sexp s(:outer,contained)
143
142
  2.times { flay.process_sexp s(:outer,container) }
144
143
 
145
- exp = eval <<-EOM # just to prevent emacs from reindenting it
144
+ exp = eval <<~EOM # just to prevent emacs from reindenting it
146
145
  [
147
146
  [ s(:a, s(:b, s(:c)), s(:d, s(:e))),
148
147
  s(:a, s(:b, s(:c)), s(:d, s(:e))),
@@ -218,7 +217,7 @@ class TestSexp < Minitest::Test
218
217
  flay.report
219
218
  end
220
219
 
221
- exp = <<-END.gsub(/\d+/, "N").gsub(/^ {6}/, "")
220
+ exp = <<~END
222
221
  Total score (lower is better) = 16
223
222
 
224
223
  1) Similar code found in :class (mass = 16)
@@ -227,7 +226,7 @@ class TestSexp < Minitest::Test
227
226
  END
228
227
 
229
228
  assert_equal "", err
230
- assert_equal exp, out.gsub(/\d+/, "N")
229
+ assert_equal exp.gsub(/\d+/, "N"), out.gsub(/\d+/, "N")
231
230
  end
232
231
 
233
232
  def test_report_io
@@ -238,7 +237,7 @@ class TestSexp < Minitest::Test
238
237
  flay.analyze
239
238
  flay.report out
240
239
 
241
- exp = <<-END.gsub(/\d+/, "N").gsub(/^ {6}/, "")
240
+ exp = <<~END
242
241
  Total score (lower is better) = 16
243
242
 
244
243
  1) Similar code found in :class (mass = 16)
@@ -246,7 +245,7 @@ class TestSexp < Minitest::Test
246
245
  (string):6
247
246
  END
248
247
 
249
- assert_equal exp, out.string.gsub(/\d+/, "N")
248
+ assert_equal exp.gsub(/\d+/, "N"), out.string.gsub(/\d+/, "N")
250
249
  end
251
250
 
252
251
  def test_report_diff
@@ -259,7 +258,7 @@ class TestSexp < Minitest::Test
259
258
  flay.report
260
259
  end
261
260
 
262
- exp = <<-END.gsub(/\d+/, "N").gsub(/^ {6}/, "")
261
+ exp = <<~END.gsub(/_NL_/, "")
263
262
  Total score (lower is better) = 16
264
263
 
265
264
  1) Similar code found in :class (mass = 16)
@@ -272,7 +271,7 @@ class TestSexp < Minitest::Test
272
271
  B: # am
273
272
  B: # a
274
273
  B: # cat.
275
-
274
+ _NL_
276
275
  A: class Dog
277
276
  B: class Cat
278
277
  A: def x
@@ -283,7 +282,7 @@ class TestSexp < Minitest::Test
283
282
  END
284
283
 
285
284
  assert_equal "", err
286
- assert_equal exp, out.gsub(/\d+/, "N").gsub(/^ {3}$/, "")
285
+ assert_equal exp.gsub(/\d+/, "N"), out.gsub(/\d+/, "N")
287
286
  end
288
287
 
289
288
  def test_report_diff_plugin_converter
@@ -301,7 +300,7 @@ class TestSexp < Minitest::Test
301
300
 
302
301
  Flay.send(:remove_method, :sexp_to_)
303
302
 
304
- exp = <<-END.gsub(/\d+/, "N").gsub(/^ {6}/, "")
303
+ exp = <<~END
305
304
  Total score (lower is better) = 16
306
305
 
307
306
  1) Similar code found in :class (mass = 16)
@@ -313,7 +312,7 @@ class TestSexp < Minitest::Test
313
312
  END
314
313
 
315
314
  assert_equal "", err
316
- assert_equal exp, out.gsub(/\d+/, "N").gsub(/^ {3}$/, "")
315
+ assert_equal exp.gsub(/\d+/, "N"), out.gsub(/\d+/, "N")
317
316
  end
318
317
 
319
318
  def test_n_way_diff
@@ -322,7 +321,7 @@ class TestSexp < Minitest::Test
322
321
 
323
322
  flay = Flay.new
324
323
 
325
- exp = <<-EOM.gsub(/\d+/, "N").gsub(/^ {6}/, "").chomp
324
+ exp = <<~EOM.chomp
326
325
  ##
327
326
  A: # I am a dog.
328
327
  B: # I
@@ -349,7 +348,7 @@ class TestSexp < Minitest::Test
349
348
 
350
349
  flay = Flay.new
351
350
 
352
- exp = <<-EOM.gsub(/\d+/, "N").gsub(/^ {6}/, "").chomp
351
+ exp = <<~EOM.gsub(/\d+/, "N").chomp
353
352
  A: class Dog
354
353
  B: class Cat
355
354
  A: def x
@@ -359,7 +358,7 @@ class TestSexp < Minitest::Test
359
358
  end
360
359
  EOM
361
360
 
362
- assert_equal exp, flay.n_way_diff(*dog_and_cat).gsub(/^ {3}$/, "")
361
+ assert_equal exp, flay.n_way_diff(*dog_and_cat)
363
362
  end
364
363
 
365
364
  def test_split_and_group
@@ -393,10 +392,12 @@ class TestSexp < Minitest::Test
393
392
  def test_collapse_and_label
394
393
  flay = Flay.new
395
394
 
396
- a = %w(a b c).map { |s| s.group = "A"; s }
397
- b = %w(d b f).map { |s| s.group = "B"; s }
395
+ a = %w(a b c).map(&:dup).map { |s| s.group = "A"; s }
396
+ b = %w(d b f).map(&:dup).map { |s| s.group = "B"; s }
398
397
 
399
- exp = [["A: a", "B: d"], " b", ["A: c", "B: f"]]
398
+ exp = [["A: a", "B: d"],
399
+ " b",
400
+ ["A: c", "B: f"]]
400
401
 
401
402
  assert_equal exp, flay.collapse_and_label([a, b])
402
403
  end
@@ -404,8 +405,8 @@ class TestSexp < Minitest::Test
404
405
  def test_collapse_and_label_same
405
406
  flay = Flay.new
406
407
 
407
- a = %w(a b c).map { |s| s.group = "A"; s }
408
- b = %w(a b c).map { |s| s.group = "B"; s }
408
+ a = %w(a b c).map(&:dup).map { |s| s.group = "A"; s }
409
+ b = %w(a b c).map(&:dup).map { |s| s.group = "B"; s }
409
410
 
410
411
  exp = [" a", " b", " c"]
411
412
 
@@ -416,9 +417,9 @@ class TestSexp < Minitest::Test
416
417
  dog_and_cat = ["##\n# I am a dog.\n\ndef x\n return \"Hello\"\nend",
417
418
  "##\n# I\n#\n# am\n# a\n# cat.\n\ndef y\n return \"Hello\"\nend"]
418
419
 
419
- flay = Flay.new DEF_OPTS
420
+ flay = Flay.new Flay.default_options
420
421
 
421
- exp = <<-EOM.gsub(/\d+/, "N").gsub(/^ {6}/, "").chomp
422
+ exp = <<~EOM.gsub(/\d+/, "N").gsub(/_NL_/, "").chomp
422
423
  ##
423
424
  A: # I am a dog.
424
425
  B: # I
@@ -426,14 +427,14 @@ class TestSexp < Minitest::Test
426
427
  B: # am
427
428
  B: # a
428
429
  B: # cat.
429
-
430
+ _NL_
430
431
  A: def x
431
432
  B: def y
432
433
  return \"Hello\"
433
434
  end
434
435
  EOM
435
436
 
436
- assert_equal exp, flay.n_way_diff(*dog_and_cat).gsub(/^ {3}$/, "")
437
+ assert_equal exp, flay.n_way_diff(*dog_and_cat)
437
438
  end
438
439
 
439
440
  attr_accessor :flay
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.3
4
+ version: 2.14.0
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
- MIIDPjCCAiagAwIBAgIBCDANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
12
+ MIIDPjCCAiagAwIBAgIBCTANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
13
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTI0MDEwMjIxMjEyM1oXDTI1MDEwMTIxMjEyM1owRTETMBEGA1UE
14
+ GRYDY29tMB4XDTI1MDEwNjIzMjcwMVoXDTI2MDEwNjIzMjcwMVowRTETMBEGA1UE
16
15
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
16
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
17
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +21,14 @@ cert_chain:
22
21
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
22
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
23
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
- AQCygvpmncmkiSs9r/Kceo4bBPDszhTv6iBi4LwMReqnFrpNLMOWJw7xi8x+3eL2
26
- XS09ZPNOt2zm70KmFouBMgOysnDY4k2dE8uF6B8JbZOO8QfalW+CoNBliefOTcn2
27
- bg5IOP7UoGM5lC174/cbDJrJnRG9bzig5FAP0mvsgA8zgTRXQzIUAZEo92D5K7p4
28
- B4/O998ho6BSOgYBI9Yk1ttdCtti6Y+8N9+fZESsjtWMykA+WXWeGUScHqiU+gH8
29
- S7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW
30
- deKfBjgVAq7EYHu1AczzlUly
24
+ AQAC0WQJcPOWPFwkojhzweilRVjTJ19UiLhiBTw3C1wJO3LVdBkWDmnnhAmKuX4D
25
+ r7vjQvESlABGIPdutI1Yl7mrHQzTkfLfXvNN6MT0nLChPyIYauT6SZZxubwJrUfA
26
+ 7R0c2CJTIboZ0XaGpLsXqHEF1c29H7TV1QvVuqKAN2mCjh4N82QVn+ZKtys28AwT
27
+ 6GfQX2fqLoi4KSc7xIzHKaNzqxeOICmJofk9w5VZ2rRN6yes8jvFYwz9HR41wdj8
28
+ bwfinv7Yp5fA6AysuZLhCykyfDuZVRrUp0Vb68YCKsLjJly/Theak+euNTxvHsB+
29
+ al9oSgPPHICMEX65qvLywitx
31
30
  -----END CERTIFICATE-----
32
- date: 2024-05-22 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,19 +45,19 @@ dependencies:
46
45
  - !ruby/object:Gem::Version
47
46
  version: '4.0'
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.0'
53
+ version: '1.5'
55
54
  type: :runtime
56
55
  prerelease: false
57
56
  version_requirements: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '3.0'
60
+ version: '1.5'
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: erubi
64
63
  requirement: !ruby/object:Gem::Requirement
@@ -79,14 +78,14 @@ dependencies:
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '1.0'
81
+ version: '2.0'
83
82
  type: :runtime
84
83
  prerelease: false
85
84
  version_requirements: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '1.0'
88
+ version: '2.0'
90
89
  - !ruby/object:Gem::Dependency
91
90
  name: minitest
92
91
  requirement: !ruby/object:Gem::Requirement
@@ -141,14 +140,14 @@ dependencies:
141
140
  requirements:
142
141
  - - "~>"
143
142
  - !ruby/object:Gem::Version
144
- version: '4.2'
143
+ version: '4.3'
145
144
  type: :development
146
145
  prerelease: false
147
146
  version_requirements: !ruby/object:Gem::Requirement
148
147
  requirements:
149
148
  - - "~>"
150
149
  - !ruby/object:Gem::Version
151
- version: '4.2'
150
+ version: '4.3'
152
151
  description: |-
153
152
  Flay analyzes code for structural similarities. Differences in literal
154
153
  values, variable, class, method names, whitespace, programming style,
@@ -179,7 +178,6 @@ licenses:
179
178
  metadata:
180
179
  homepage_uri: http://ruby.sadi.st/
181
180
  source_code_uri: https://github.com/seattlerb/flay
182
- post_install_message:
183
181
  rdoc_options:
184
182
  - "--main"
185
183
  - README.rdoc
@@ -196,8 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
194
  - !ruby/object:Gem::Version
197
195
  version: '0'
198
196
  requirements: []
199
- rubygems_version: 3.5.3
200
- signing_key:
197
+ rubygems_version: 3.7.2
201
198
  specification_version: 4
202
199
  summary: Flay analyzes code for structural similarities
203
200
  test_files: []
metadata.gz.sig CHANGED
Binary file