ruby-changes:61211
From: Nobuyoshi <ko1@a...>
Date: Tue, 12 May 2020 16:29:25 +0900 (JST)
Subject: [ruby-changes:61211] ee518cf077 (master): Revert "Sync did_you_mean"
https://git.ruby-lang.org/ruby.git/commit/?id=ee518cf077 From ee518cf077b856fddea7dfae5d85f3c3117dd616 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 12 May 2020 16:22:41 +0900 Subject: Revert "Sync did_you_mean" This reverts commit 946dadd3f479198e87873a863d15c7660a8e2b56, which broke `TestGemRequire` and others. diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb index 2dbd2fb..b8f9257 100644 --- a/lib/did_you_mean.rb +++ b/lib/did_you_mean.rb @@ -6,7 +6,6 @@ require_relative 'did_you_mean/spell_checkers/name_error_checkers' https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean.rb#L6 require_relative 'did_you_mean/spell_checkers/method_name_checker' require_relative 'did_you_mean/spell_checkers/key_error_checker' require_relative 'did_you_mean/spell_checkers/null_checker' -require_relative 'did_you_mean/spell_checkers/require_path_checker' require_relative 'did_you_mean/formatters/plain_formatter' require_relative 'did_you_mean/tree_spell_checker' @@ -96,9 +95,8 @@ module DidYouMean https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean.rb#L95 correct_error NameError, NameErrorCheckers correct_error KeyError, KeyErrorChecker correct_error NoMethodError, MethodNameChecker - correct_error LoadError, RequirePathChecker - # Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+. + # Returns the currenctly set formatter. By default, it is set to +DidYouMean::Formatter+. def self.formatter @@formatter 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 0483127..3a38245 100644 --- a/lib/did_you_mean/spell_checkers/method_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/method_name_checker.rb @@ -43,12 +43,7 @@ module DidYouMean https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean/spell_checkers/method_name_checker.rb#L43 end def corrections - @corrections ||= begin - dictionary = method_names - dictionary = RB_RESERVED_WORDS + dictionary if @private_call - - SpellChecker.new(dictionary: dictionary).correct(method_name) - names_to_exclude - end + @corrections ||= SpellChecker.new(dictionary: RB_RESERVED_WORDS + method_names).correct(method_name) - names_to_exclude end def method_names diff --git a/lib/did_you_mean/spell_checkers/require_path_checker.rb b/lib/did_you_mean/spell_checkers/require_path_checker.rb deleted file mode 100644 index 1023994..0000000 --- a/lib/did_you_mean/spell_checkers/require_path_checker.rb +++ /dev/null @@ -1,33 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean/spell_checkers/method_name_checker.rb#L0 -# frozen-string-literal: true - -require_relative "../spell_checker" -require_relative "../tree_spell_checker" - -module DidYouMean - class RequirePathChecker - attr_reader :path - - INITIAL_LOAD_PATH = $LOAD_PATH.dup.freeze - ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}" - - private_constant :INITIAL_LOAD_PATH, :ENV_SPECIFIC_EXT - - def self.requireables - @requireables ||= INITIAL_LOAD_PATH - .flat_map {|path| Dir.glob("**/???*{.rb,#{ENV_SPECIFIC_EXT}}", base: path) } - .map {|path| path.chomp!(".rb") || path.chomp!(ENV_SPECIFIC_EXT) } - end - - def initialize(exception) - @path = exception.path - end - - def corrections - threshold = path.size * 2 - dictionary = self.class.requireables.reject {|str| str.size >= threshold } - spell_checker = path.include?("/") ? TreeSpellChecker : SpellChecker - - spell_checker.new(dictionary: dictionary).correct(path) - end - end -end diff --git a/test/did_you_mean/spell_checking/test_method_name_check.rb b/test/did_you_mean/spell_checking/test_method_name_check.rb index 6e14e6a..f3a6b1c 100644 --- a/test/did_you_mean/spell_checking/test_method_name_check.rb +++ b/test/did_you_mean/spell_checking/test_method_name_check.rb @@ -137,11 +137,4 @@ class MethodNameCheckTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/did_you_mean/spell_checking/test_method_name_check.rb#L137 assert_correction :yield, error.corrections assert_match "Did you mean? yield", error.to_s end - - def test_does_not_suggest_yield - error = assert_raise(NoMethodError) { 1.yeild } - - assert_correction [], error.corrections - assert_not_match(/Did you mean\? +yield/, error.to_s) - end if RUBY_ENGINE != "jruby" end diff --git a/test/did_you_mean/spell_checking/test_require_path_check.rb b/test/did_you_mean/spell_checking/test_require_path_check.rb deleted file mode 100644 index 8c4da6e..0000000 --- a/test/did_you_mean/spell_checking/test_require_path_check.rb +++ /dev/null @@ -1,30 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/test/did_you_mean/spell_checking/test_method_name_check.rb#L0 -require_relative '../helper' - -class RequirePathCheckTest < Test::Unit::TestCase - include DidYouMean::TestHelper - - def test_load_error_from_require_has_suggestions - error = assert_raise LoadError do - require 'open_struct' - end - - assert_correction 'ostruct', error.corrections - assert_match "Did you mean? ostruct", error.to_s - end - - def test_load_error_from_require_for_nested_files_has_suggestions - error = assert_raise LoadError do - require 'net/htt' - end - - assert_correction 'net/http', error.corrections - assert_match "Did you mean? net/http", error.to_s - - error = assert_raise LoadError do - require 'net-http' - end - - assert_correction ['net/http', 'net/https'], error.corrections - assert_match "Did you mean? net/http", error.to_s - end -end diff --git a/test/did_you_mean/test_verbose_formatter.rb b/test/did_you_mean/test_verbose_formatter.rb index d8f2f46..92ea9a1 100644 --- a/test/did_you_mean/test_verbose_formatter.rb +++ b/test/did_you_mean/test_verbose_formatter.rb @@ -3,7 +3,6 @@ require_relative './helper' https://github.com/ruby/ruby/blob/trunk/test/did_you_mean/test_verbose_formatter.rb#L3 class VerboseFormatterTest < Test::Unit::TestCase def setup require_relative File.join(DidYouMean::TestHelper.root, 'verbose') - DidYouMean.formatter = DidYouMean::VerboseFormatter.new end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/