Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence parser warning and patch version mismatch when loading parser/current #613

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

navidemad
Copy link

Description

This pull request adds a factory class RubyParserFactory to temporarily disable verbose mode when loading the "parser/current" library. The purpose is to suppress compatibility warnings that are displayed when the library is loaded with a different Ruby version than the one it recognizes.

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.

References

Changes

  • Added a new module I18n::Tasks::Scanners to encapsulate the factory class.
  • Implemented the RubyParserFactory class with a create_parser method that temporarily disables verbose mode, loads the "parser/current" library, creates a new parser instance, and restores the verbose mode.
  • Added descriptive comments to explain the purpose of the module and provide an example of the warning being suppressed.

Benefits

  • Suppresses compatibility warnings when loading the "parser/current" library, providing a cleaner output for users.
  • Encapsulates the logic for creating a parser instance within a dedicated factory class, promoting code organization and reusability.
  • Maintains the original behavior of the Ruby environment by restoring the verbose mode after the parser instance is created.

Issues

Please let me know if you have any questions or feedback regarding this pull request.
Thank you for considering this contribution to the gem!

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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants