Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

* Silence parser warning and patch version mismatch for Ruby 3.4.x > 3.4.0 [#612](https://github.com/glebm/i18n-tasks/issues/612)
* Append JSON instructions to OpenAI system prompt to be able to use response_format json_object [#615](https://github.com/glebm/i18n-tasks/pull/615)
* Set `log_errors: true` on OpenAI::Client options in order to display HTTP client errors. [#614](https://github.com/glebm/i18n-tasks/pull/614)
* Uses AST-parser for all ERB-files, not just `.html.erb`
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/tasks/scanners/local_ruby_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'parser/current'
require 'i18n/tasks/scanners/ruby_parser_factory'

module I18n::Tasks::Scanners
class LocalRubyParser
Expand All @@ -9,7 +9,7 @@ class LocalRubyParser
BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/.freeze

def initialize(ignore_blocks: false)
@parser = ::Parser::CurrentRuby.new
@parser = RubyParserFactory.create_parser
@ignore_blocks = ignore_blocks
end

Expand Down
6 changes: 3 additions & 3 deletions lib/i18n/tasks/scanners/ruby_ast_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require 'i18n/tasks/scanners/file_scanner'
require 'i18n/tasks/scanners/relative_keys'
require 'i18n/tasks/scanners/ruby_ast_call_finder'
require 'i18n/tasks/scanners/ruby_parser_factory'
require 'i18n/tasks/scanners/ast_matchers/default_i18n_subject_matcher'
require 'i18n/tasks/scanners/ast_matchers/message_receivers_matcher'
require 'i18n/tasks/scanners/ast_matchers/rails_model_matcher'
require 'parser/current'

module I18n::Tasks::Scanners
# Scan for I18n.translate calls using whitequark/parser
Expand All @@ -18,8 +18,8 @@ class RubyAstScanner < FileScanner

def initialize(**args)
super(**args)
@parser = ::Parser::CurrentRuby.new
@magic_comment_parser = ::Parser::CurrentRuby.new
@parser = RubyParserFactory.create_parser
@magic_comment_parser = RubyParserFactory.create_parser
@matchers = setup_matchers
end

Expand Down
27 changes: 27 additions & 0 deletions lib/i18n/tasks/scanners/ruby_parser_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# This module provides a factory class for creating a Ruby parser instance.
# It temporarily disables verbose mode to suppress compatibility warnings
# when loading the "parser/current" library.
#
# Example warning for the release of Ruby 3.4.1:
# warning: parser/current is loading parser/ruby34, which recognizes
# 3.4.0-compliant syntax, but you are running 3.4.1.
# Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
#
# By disabling verbose mode, these warnings are suppressed to provide a cleaner
# output and avoid confusion. The verbose mode is restored after the parser
# instance is created to maintain the original behavior.

module I18n::Tasks::Scanners
class RubyParserFactory
def self.create_parser
prev = $VERBOSE
$VERBOSE = nil
require 'parser/current'
::Parser::CurrentRuby.new
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a much nicer solution to this would be to send a PR to whitequark/parser adding an argument to Parser::CurrentRuby.new that disables the warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made whitequark/parser#1065 we will see, but yeah you are right fixing it on the parser itself it's better, than hotfixing here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They won't update their parser with Ruby >3.4 so we're stuck

ensure
$VERBOSE = prev
end
end
end
Loading