From de841e2e28a8f721895acb1a76c7847b40cc487a Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Thu, 23 Dec 2021 10:08:07 +0900 Subject: Revert the commits for did_you_mean This reverts commit feaf4fbc3fa16382fbd07158c448c7b5bdae78b5. This reverts commit 0d4bfbdbe1f880c712b3e60de5fce423e6096f8d. This reverts commit ac4e0978ee4358430396403065eabe1aca05784f. --- lib/did_you_mean.rb | 55 +++------------------- lib/did_you_mean/core_ext/name_error.rb | 2 +- lib/did_you_mean/formatter.rb | 2 +- .../spell_checkers/method_name_checker.rb | 3 -- .../name_error_checkers/variable_name_checker.rb | 3 -- .../spell_checkers/require_path_checker.rb | 5 +- lib/did_you_mean/version.rb | 2 +- 7 files changed, 11 insertions(+), 61 deletions(-) (limited to 'lib') diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb index 2df238da06..6d3a6e8bda 100644 --- a/lib/did_you_mean.rb +++ b/lib/did_you_mean.rb @@ -86,25 +86,12 @@ require_relative 'did_you_mean/tree_spell_checker' # module DidYouMean # Map of error types and spell checker objects. - @spell_checkers = Hash.new(NullChecker) - - # Returns a sharable hash map of error types and spell checker objects. - def self.spell_checkers - @spell_checkers - end + SPELL_CHECKERS = Hash.new(NullChecker) # Adds +DidYouMean+ functionality to an error using a given spell checker def self.correct_error(error_class, spell_checker) - if defined?(Ractor) - new_mapping = { **@spell_checkers, error_class.to_s => spell_checker } - new_mapping.default = NullChecker - - @spell_checkers = Ractor.make_shareable(new_mapping) - else - spell_checkers[error_class.to_s] = spell_checker - end - - error_class.prepend(Correctable) if error_class.is_a?(Class) && !(error_class < Correctable) + SPELL_CHECKERS[error_class.name] = spell_checker + error_class.prepend(Correctable) unless error_class < Correctable end correct_error NameError, NameErrorCheckers @@ -113,43 +100,15 @@ module DidYouMean correct_error LoadError, RequirePathChecker if RUBY_VERSION >= '2.8.0' correct_error NoMatchingPatternKeyError, PatternKeyNameChecker if defined?(::NoMatchingPatternKeyError) - # TODO: Remove on 3.3: - class DeprecatedMapping # :nodoc: - def []=(key, value) - warn "Calling `DidYouMean::SPELL_CHECKERS[#{key.to_s}] = #{value.to_s}' has been deprecated. " \ - "Please call `DidYouMean.correct_error(#{key.to_s}, #{value.to_s})' instead." - - DidYouMean.correct_error(key, value) - end - - def merge!(hash) - warn "Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. " \ - "Please call `DidYouMean.correct_error(error_name, spell_checker)' instead." - - hash.each do |error_class, spell_checker| - DidYouMean.correct_error(error_class, spell_checker) - end - end - end - - # TODO: Remove on 3.3: - SPELL_CHECKERS = DeprecatedMapping.new - deprecate_constant :SPELL_CHECKERS - private_constant :DeprecatedMapping - # Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+. def self.formatter - if defined?(Ractor) - Ractor.current[:__did_you_mean_formatter__] || Formatter - else - Formatter - end + @formatter end # Updates the primary formatter used to format the suggestions. def self.formatter=(formatter) - if defined?(Ractor) - Ractor.current[:__did_you_mean_formatter__] = formatter - end + @formatter = formatter end + + @formatter = Formatter.new end diff --git a/lib/did_you_mean/core_ext/name_error.rb b/lib/did_you_mean/core_ext/name_error.rb index eb3ef117a0..7e99282b41 100644 --- a/lib/did_you_mean/core_ext/name_error.rb +++ b/lib/did_you_mean/core_ext/name_error.rb @@ -26,7 +26,7 @@ module DidYouMean end def spell_checker - DidYouMean.spell_checkers[self.class.to_s].new(self) + SPELL_CHECKERS[self.class.to_s].new(self) end end end diff --git a/lib/did_you_mean/formatter.rb b/lib/did_you_mean/formatter.rb index 02c0bc75d3..01eb59100a 100644 --- a/lib/did_you_mean/formatter.rb +++ b/lib/did_you_mean/formatter.rb @@ -26,7 +26,7 @@ module DidYouMean # # # => nil # - def self.message_for(corrections) + def message_for(corrections) corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}" end end diff --git a/lib/did_you_mean/spell_checkers/method_name_checker.rb b/lib/did_you_mean/spell_checkers/method_name_checker.rb index d8ebaa4616..0483127d6f 100644 --- a/lib/did_you_mean/spell_checkers/method_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/method_name_checker.rb @@ -6,7 +6,6 @@ module DidYouMean NAMES_TO_EXCLUDE = { NilClass => nil.methods } NAMES_TO_EXCLUDE.default = [] - Ractor.make_shareable(NAMES_TO_EXCLUDE) if defined?(Ractor) # +MethodNameChecker::RB_RESERVED_WORDS+ is the list of reserved words in # Ruby that take an argument. Unlike @@ -37,8 +36,6 @@ module DidYouMean yield ) - Ractor.make_shareable(RB_RESERVED_WORDS) if defined?(Ractor) - def initialize(exception) @method_name = exception.name @receiver = exception.receiver diff --git a/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb b/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb index 36d00349c6..3e51b4fa3a 100644 --- a/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb @@ -8,7 +8,6 @@ module DidYouMean NAMES_TO_EXCLUDE = { 'foo' => [:fork, :for] } NAMES_TO_EXCLUDE.default = [] - Ractor.make_shareable(NAMES_TO_EXCLUDE) if defined?(Ractor) # +VariableNameChecker::RB_RESERVED_WORDS+ is the list of all reserved # words in Ruby. They could be declared like methods are, and a typo would @@ -63,8 +62,6 @@ module DidYouMean __ENCODING__ ) - Ractor.make_shareable(RB_RESERVED_WORDS) if defined?(Ractor) - def initialize(exception) @name = exception.name.to_s.tr("@", "") @lvar_names = exception.respond_to?(:local_variables) ? exception.local_variables : [] diff --git a/lib/did_you_mean/spell_checkers/require_path_checker.rb b/lib/did_you_mean/spell_checkers/require_path_checker.rb index 586ced37de..e4cdb9f43d 100644 --- a/lib/did_you_mean/spell_checkers/require_path_checker.rb +++ b/lib/did_you_mean/spell_checkers/require_path_checker.rb @@ -9,10 +9,7 @@ module DidYouMean attr_reader :path INITIAL_LOAD_PATH = $LOAD_PATH.dup.freeze - Ractor.make_shareable(INITIAL_LOAD_PATH) if defined?(Ractor) - - ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}" - Ractor.make_shareable(ENV_SPECIFIC_EXT) if defined?(Ractor) + ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}" private_constant :INITIAL_LOAD_PATH, :ENV_SPECIFIC_EXT diff --git a/lib/did_you_mean/version.rb b/lib/did_you_mean/version.rb index a0ca14e9c2..8df73e1d62 100644 --- a/lib/did_you_mean/version.rb +++ b/lib/did_you_mean/version.rb @@ -1,3 +1,3 @@ module DidYouMean - VERSION = "1.6.1-alpha".freeze + VERSION = "1.6.0-alpha" end -- cgit v1.2.3