From 6ac0fb999cc0678b2ab6fe923b7a8898c641b5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 24 May 2022 15:16:11 +0200 Subject: [PATCH 01/12] Add `gh release create` to release script --- script/release | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/release b/script/release index 2e48128..6f1b94a 100755 --- a/script/release +++ b/script/release @@ -14,3 +14,5 @@ fi git push origin HEAD "v${version}" gem push "$gem" + +gh release create "v${version}" --title "ripper-tags $version" --generate-notes From c5dc35aafe686e19a798437778429dbb6545fd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 18 May 2023 11:46:15 +0200 Subject: [PATCH 02/12] Test in Ruby 3.2 --- .github/workflows/ruby.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0e57d5a..8b4bf42 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -20,6 +20,7 @@ jobs: - "2.7" - "3.0" - "3.1" + - "3.2" steps: - uses: actions/checkout@v3 From d7938b0336aa60e62c8cc3f453c83f163f2769b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 18 May 2023 12:02:47 +0200 Subject: [PATCH 03/12] Bump rake for Ruby 3.2 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index fac412b..4cd9b50 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' gemspec -gem 'rake', '~> 10.5' +gem 'rake', '~> 12.2' gem 'test-unit', '~> 3.3.4' From df67ae4b996af45e5df06eb55835860130c7c222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 18 May 2023 12:03:31 +0200 Subject: [PATCH 04/12] Fix test for Ruby 3.2 --- test/test_data_reader.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_data_reader.rb b/test/test_data_reader.rb index 86c50b2..7fdf345 100644 --- a/test/test_data_reader.rb +++ b/test/test_data_reader.rb @@ -173,8 +173,12 @@ def test_survive_errors stderr = capture_stderr do reader.each_tag.to_a end - assert_include(stderr, "ArgumentError parsing `#{fixture('erb_template.rb')}'") - end unless RUBY_VERSION.to_f < 2.3 + if RUBY_VERSION.to_f >= 2.3 && RUBY_VERSION.to_f < 3.2 + assert_include(stderr, "ArgumentError parsing `#{fixture('erb_template.rb')}'") + else + assert_equal("", stderr) + end + end def with_tempfile file = Tempfile.new("test-ripper-tags") From 495703319f9de59bf59c545e0890c816a0986610 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 2 Feb 2018 17:46:05 +0000 Subject: [PATCH 05/12] Process inside calls to handle frozen (nested) constants --- lib/ripper-tags/parser.rb | 17 +++++++++++------ test/test_ripper_tags.rb | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index 023778d..0a211aa 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -544,12 +544,17 @@ def on_class_eval(name, body) end def on_call(*args) + process args end - alias on_aref_field on_call - alias on_field on_call - alias on_fcall on_call - alias on_args on_call - alias on_assoc on_call - alias on_! on_call + + def ignore(*args) + end + + alias on_aref_field ignore + alias on_field ignore + alias on_fcall ignore + alias on_args ignore + alias on_assoc ignore + alias on_! ignore end end diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index 5d94084..1fb546a 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -87,18 +87,26 @@ def test_nested_constant_definitions OPEN = 'open', ] + FROZEN_ARRAY = [ARRAY_ENTRY = 1].freeze + DISPLAY_MAPPING = { CANCELLED = 'cancelled' => 'Cancelled by user', STARTED = 'started' => 'Started by user', } + + FROZEN_HASH = { HASH_ENTRY = 2 => 3 }.freeze EOC assert_equal %w[ OPEN STATUSES + ARRAY_ENTRY + FROZEN_ARRAY CANCELLED STARTED DISPLAY_MAPPING + HASH_ENTRY + FROZEN_HASH ], tags.map { |t| t[:name] } tags.each do |t| From df20c1f226a272deac7f5419cec8fc5a3728d32a Mon Sep 17 00:00:00 2001 From: Yuri Smirnov Date: Sun, 26 Apr 2020 14:44:45 +0300 Subject: [PATCH 06/12] Process methods defined within ruby blocks --- lib/ripper-tags/parser.rb | 11 +++++++---- test/test_ripper_tags.rb | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index 0a211aa..48104a2 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -136,7 +136,7 @@ def on_tstring_content(str) end def on_string_add(*args) - [args[1], lineno] + [args[1], lineno] unless args[0].is_a?(Array) && args[0].include?(:string_embexpr) end def on_string_embexpr(*) @@ -291,8 +291,9 @@ def on_do_block(*args) end def on_method_add_block(method, body) - return unless method - if %w[class_eval module_eval].include?(method[2]) && body + if method.nil? + body ? body.last : nil + elsif %w[class_eval module_eval].include?(method[2]) && body [:class_eval, [ method[1].is_a?(Array) ? method[1][0] : method[1], method[3] @@ -302,6 +303,8 @@ def on_method_add_block(method, body) call = method.dup call[4] = body.last call + elsif :fcall == method[0] && body + body.last else super end @@ -544,7 +547,7 @@ def on_class_eval(name, body) end def on_call(*args) - process args + process(args) end def ignore(*args) diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index 1fb546a..3ab26de 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -823,4 +823,27 @@ class Foo assert_equal 'Foo', tags[0][:name] assert_equal 'calculate', tags[1][:name] end + + def test_method_defined_in_block + tags = extract(<<-EOC) + RSpec.describe do + def test_method; end + end + + module M + included do + def included_method; end + attr_accessor :cache + end + + %w[sub gsub].each do |m| + define_method("\#{m}!") {} + attr_reader m + end + end + EOC + + expected = ["Object#test_method", "M", "M#included_method", "M#cache", "M#cache="] + assert_equal expected, tags.map { |t| t[:full_name] } + end end From 169996f92e16fe0a68d586181bb83a77e60a3ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 18 May 2023 14:49:41 +0200 Subject: [PATCH 07/12] Reduce allocations in condition --- lib/ripper-tags/parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index 48104a2..d463bb3 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -293,7 +293,7 @@ def on_do_block(*args) def on_method_add_block(method, body) if method.nil? body ? body.last : nil - elsif %w[class_eval module_eval].include?(method[2]) && body + elsif (method[2] == "class_eval" || method[2] == "module_eval") && body [:class_eval, [ method[1].is_a?(Array) ? method[1][0] : method[1], method[3] From 22009451a4a12c7c3ed95f945c3328d9fcbb942e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 18 May 2023 15:01:13 +0200 Subject: [PATCH 08/12] ripper-tags 1.0.0 --- lib/ripper-tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ripper-tags.rb b/lib/ripper-tags.rb index 93910c1..06968d7 100644 --- a/lib/ripper-tags.rb +++ b/lib/ripper-tags.rb @@ -11,7 +11,7 @@ require 'ripper-tags/json_formatter' module RipperTags - def self.version() "0.9.1" end + def self.version() "1.0.0" end FatalError = Class.new(RuntimeError) From aac79d871f5dea0bf1852d9fe0e3d2af63211635 Mon Sep 17 00:00:00 2001 From: Drew Ulmer Date: Tue, 30 May 2023 11:40:51 -0500 Subject: [PATCH 09/12] Fix parse error for delegate statements with dynamic arguments (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mislav Marohnić --- lib/ripper-tags/parser.rb | 4 ++-- test/test_ripper_tags.rb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index d463bb3..505d355 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -316,8 +316,8 @@ def on_assoc_new(key, value) end def on_delegate(*args) - method_names = args.select { |arg| arg.first.is_a? String } - options = args.select { |arg| arg.first.is_a?(Array) && arg.first.first == :assoc }.flatten(1) + method_names = args.select { |arg| arg.is_a?(Array) && arg.first.is_a?(String) } + options = args.select { |arg| arg.is_a?(Array) && arg.first.is_a?(Array) && arg.first.first == :assoc }.flatten(1) options = Hash[options.map { |_assoc, key, val| [key[0], val[0]] if key }.compact] target = options["to:"] || options["to"] # When using hashrocket syntax there is no ':' diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index 3ab26de..a4efff7 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -578,6 +578,9 @@ def test_invalid_delegate class C delegate delegate [1, 2] + [:test].each do |m| + delegate m, :"\#{m}=", :to => :object + end end EOC assert_equal 1, tags.count From 2fcd7c981d08d9da7a49177fc9bda8dbfa9daed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 30 May 2023 18:42:58 +0200 Subject: [PATCH 10/12] ripper-tags 1.0.1 --- lib/ripper-tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ripper-tags.rb b/lib/ripper-tags.rb index 06968d7..a3242b9 100644 --- a/lib/ripper-tags.rb +++ b/lib/ripper-tags.rb @@ -11,7 +11,7 @@ require 'ripper-tags/json_formatter' module RipperTags - def self.version() "1.0.0" end + def self.version() "1.0.1" end FatalError = Class.new(RuntimeError) From f0c27ab6c560ef8c37a32948409423ee5cf5ebcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 10 Feb 2024 13:10:19 +0100 Subject: [PATCH 11/12] Fix crash in dynamic module_function within a loop --- lib/ripper-tags/parser.rb | 2 +- test/test_ripper_tags.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index 505d355..c820376 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -220,7 +220,7 @@ def on_method_add_arg(call, args) method_name = args[1][1] end - [procedure, klass, method_name, access, line] + [procedure, klass, method_name, access, line] if method_name when "scope", "named_scope" scope_name = args[1][0] [:rails_def, :scope, scope_name, line] if scope_name diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index a4efff7..55df994 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -258,6 +258,17 @@ def def() end assert_equal('method', module_tags.find{ |t| t[:name] == 'def' }[:kind]) end + def test_dynamic_module_function + tags = extract(<<-RUBY) + module Airbrussh + ANSI_CODES.each do |name, code| + module_function(name) + end + end + RUBY + assert_equal ["Airbrussh"], tags.map { |t| t.fetch(:name) } + end + def test_extract_one_line_definition_access_by_symbol %w(private public protected).each do |visibility| tags = extract(<<-EOC) From e8dcbd7f084f1d404d9aa9745f2751c5acf8634c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 13 Feb 2024 17:28:48 +0100 Subject: [PATCH 12/12] ripper-tags 1.0.2 --- lib/ripper-tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ripper-tags.rb b/lib/ripper-tags.rb index a3242b9..1112ade 100644 --- a/lib/ripper-tags.rb +++ b/lib/ripper-tags.rb @@ -11,7 +11,7 @@ require 'ripper-tags/json_formatter' module RipperTags - def self.version() "1.0.1" end + def self.version() "1.0.2" end FatalError = Class.new(RuntimeError)