Skip to content

Commit

Permalink
[ruby/prism] Deprecate TargetRubyVersion: 80_82_73_83_77.xx
Browse files Browse the repository at this point in the history
Prism has been directly supported as a parser engine since RuboCop 1.62:
https://github.com/rubocop/rubocop/releases/tag/v1.62.0

This makes specifying `TargetRubyVersion` with special values like `80_82_73_83_77.33`
using the `prism/translation/parser/rubocop` file unnecessary.
As a result, it would be possible to deprecate this approach.

OTOH, early users might be surprised if `prism/translation/parser/rubocop` were to be suddenly removed.
Therefore, this PR deprecates the parameters related to `prism/translation/parser/rubocop`.

```console
$ bundle exec ruby -rrubocop -rprism/translation/parser/rubocop -e "RuboCop::AST::ProcessedSource.new('42', 80_82_73_83_77.33).ast"
WARN: Prism is directly supported since RuboCop 1.62. The `prism/translation/parser/rubocop` file is deprecated.
WARN: Setting `TargetRubyVersion: 80_82_73_83_77.33` is deprecated. Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.3` instead.

$ bundle exec ruby -rrubocop -rprism/translation/parser/rubocop -e "RuboCop::AST::ProcessedSource.new('42', 80_82_73_83_77.34).ast"
WARN: Prism is directly supported since RuboCop 1.62. The `prism/translation/parser/rubocop` file is deprecated.
WARN: Setting `TargetRubyVersion: 80_82_73_83_77.34` is deprecated. Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.4` instead.
```

Eventually, it will be possible to remove it at some point.

Regarding documentation, it has been updated to not show the old, discouraged usage but rather
the new way of specifying it in RuboCop.

ruby/prism@0e4bc31463
  • Loading branch information
koic authored and matzbot committed Mar 6, 2024
1 parent 7d3304e commit 4d04e1b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/prism/translation/parser/rubocop.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
# typed: ignore

warn "WARN: Prism is directly supported since RuboCop 1.62. The `prism/translation/parser/rubocop` file is deprecated."

require "parser"
require "rubocop"

Expand All @@ -27,9 +29,13 @@ module ProcessedSource
# list of known parsers.
def parser_class(ruby_version)
if ruby_version == Prism::Translation::Parser::VERSION_3_3
warn "WARN: Setting `TargetRubyVersion: 80_82_73_83_77.33` is deprecated. " \
"Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.3` instead."
require "prism/translation/parser33"
Prism::Translation::Parser33
elsif ruby_version == Prism::Translation::Parser::VERSION_3_4
warn "WARN: Setting `TargetRubyVersion: 80_82_73_83_77.34` is deprecated. " \
"Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.4` instead."
require "prism/translation/parser34"
Prism::Translation::Parser34
else
Expand All @@ -41,9 +47,13 @@ def parser_class(ruby_version)
# list of known parsers.
def parser_class(ruby_version, _parser_engine)
if ruby_version == Prism::Translation::Parser::VERSION_3_3
warn "WARN: Setting `TargetRubyVersion: 80_82_73_83_77.33` is deprecated. " \
"Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.3` instead."
require "prism/translation/parser33"
Prism::Translation::Parser33
elsif ruby_version == Prism::Translation::Parser::VERSION_3_4
warn "WARN: Setting `TargetRubyVersion: 80_82_73_83_77.34` is deprecated. " \
"Set to `ParserEngine: parser_prism` and `TargetRubyVersion: 3.4` instead."
require "prism/translation/parser34"
Prism::Translation::Parser34
else
Expand Down

0 comments on commit 4d04e1b

Please sign in to comment.