ruby-changes:61592
From: Yuki <ko1@a...>
Date: Sun, 7 Jun 2020 03:13:57 +0900 (JST)
Subject: [ruby-changes:61592] 4178cbd297 (master): Remove experimental feaures and related code completely
https://git.ruby-lang.org/ruby.git/commit/?id=4178cbd297 From 4178cbd2974fc0022823392c2460e09df2517a6e Mon Sep 17 00:00:00 2001 From: Yuki Nishijima <yk.nishijima@g...> Date: Sat, 6 Jun 2020 14:13:19 -0400 Subject: Remove experimental feaures and related code completely Original pull request: https://github.com/ruby/did_you_mean/pull/147 diff --git a/lib/did_you_mean/experimental/initializer_name_correction.rb b/lib/did_you_mean/experimental/initializer_name_correction.rb deleted file mode 100644 index b59c98e..0000000 --- a/lib/did_you_mean/experimental/initializer_name_correction.rb +++ /dev/null @@ -1,20 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0 -# frozen-string-literal: true - -require_relative '../levenshtein' - -module DidYouMean - module Experimental - module InitializerNameCorrection - def method_added(name) - super - - distance = Levenshtein.distance(name.to_s, 'initialize') - if distance != 0 && distance <= 2 - warn "warning: #{name} might be misspelled, perhaps you meant initialize?" - end - end - end - - ::Class.prepend(InitializerNameCorrection) - end -end diff --git a/lib/did_you_mean/experimental/ivar_name_correction.rb b/lib/did_you_mean/experimental/ivar_name_correction.rb deleted file mode 100644 index 7b97ff4..0000000 --- a/lib/did_you_mean/experimental/ivar_name_correction.rb +++ /dev/null @@ -1,65 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0 -# frozen-string-literal: true - -require_relative '../../did_you_mean/spell_checker' -require_relative '../../did_you_mean/spell_checkers/method_name_checker' - -module DidYouMean - module Experimental #:nodoc: - class IvarNameChecker < ::DidYouMean::MethodNameChecker #:nodoc: - REPLS = { - "(irb)" => -> { Readline::HISTORY.to_a.last } - } - - TRACE = TracePoint.trace(:raise) do |tp| - e = tp.raised_exception - - if SPELL_CHECKERS.include?(e.class.to_s) && !e.instance_variable_defined?(:@frame_binding) - e.instance_variable_set(:@frame_binding, tp.binding) - end - end - - attr_reader :location, :ivar_names - - def initialize(no_method_error) - super(no_method_error) - - @location = no_method_error.backtrace_locations.first - @ivar_names = no_method_error.frame_binding.receiver.instance_variables - - no_method_error.remove_instance_variable(:@frame_binding) - end - - def corrections - super + ivar_name_corrections - end - - def ivar_name_corrections - @ivar_name_corrections ||= SpellChecker.new(dictionary: ivar_names).correct(receiver_name.to_s) - end - - private - - def receiver_name - return unless receiver.nil? - - abs_path = location.absolute_path - lineno = location.lineno - - /@(\w+)*\.#{method_name}/ =~ line(abs_path, lineno).to_s && $1 - end - - def line(abs_path, lineno) - if REPLS[abs_path] - REPLS[abs_path].call - elsif File.exist?(abs_path) - File.open(abs_path) do |file| - file.detect { file.lineno == lineno } - end - end - end - end - end - - NoMethodError.send(:attr, :frame_binding) - SPELL_CHECKERS['NoMethodError'] = Experimental::IvarNameChecker -end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/