did_you_mean 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5179422bf1ff107c7189cb5e75e44f1cd8d44c2e305cbd46f1c262011fe46add
4
- data.tar.gz: ea8103ee404f2bed7e002efb615b9a1c26b8080284fac57929276b72fa5cb0c5
3
+ metadata.gz: c8872d94ffdf1a826aa542768069af9a51087bc5156e54c277ccad671088724f
4
+ data.tar.gz: cd6c5001ef84b6618b488995b7c707dd88e9586df229067b25c6e4fb77c43882
5
5
  SHA512:
6
- metadata.gz: 45ee6a7e79a463743a5529f38b503c78266458b07fe2e8a85d8f4e0ece2c65dbc40baf0aaa96c4c6592bca868c4a99f9d6001f4b5b9c033bf504aedb34ba5340
7
- data.tar.gz: f259d9fef544f4071733007277c672c16f95bbe0e7d303bc6bf52fa0d7fa7108dcf615d6502e7950d2b48e4ce720034cc2d23096d52bee6f03e7206eab02569b
6
+ metadata.gz: 5c18bc93c847891f6061325c0a2f1f6b067af698adbd49a6b96172c1a7cda5f4fd96fbf7e9d5b1aeb1d0851caf702c28351239edc4c62f76b2ba919e6e686f2d
7
+ data.tar.gz: 9c6f42e8c30a6a803c42409192757ecf13f03398771e682d2cf98976a391e7a5976af38a8d5eea972fcc3560ff16e8dffbfa5e3cc2eef96228c2a2fbd8bea030
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -15,7 +15,7 @@ jobs:
15
15
  matrix:
16
16
  ruby: [ '2.5', '2.6', '2.7', '3.0', 'ruby-head', 'jruby-9.2', 'jruby-head' ]
17
17
  steps:
18
- - uses: actions/checkout@v1
18
+ - uses: actions/checkout@v3
19
19
  - uses: ruby/setup-ruby@v1
20
20
  with:
21
21
  ruby-version: ${{ matrix.ruby }}
@@ -27,7 +27,7 @@ jobs:
27
27
  benchmark:
28
28
  runs-on: ubuntu-latest
29
29
  steps:
30
- - uses: actions/checkout@v1
30
+ - uses: actions/checkout@v3
31
31
  - uses: ruby/setup-ruby@v1
32
32
  with:
33
33
  ruby-version: 2.7.1
data/CHANGELOG.md CHANGED
@@ -5,7 +5,7 @@ _<sup>released at 2020-12-22 13:22:35 UTC</sup>_
5
5
  #### Deprecations
6
6
 
7
7
  - Deprecate custom formatters to reduce complexity for Ractor support.
8
- - Deprecate access to the `DidYouMean::SPELL_CHECEKRS` constant for Ractor support.
8
+ - Deprecate access to the `DidYouMean::SPELL_CHECKERS` constant for Ractor support.
9
9
 
10
10
  #### Features
11
11
 
data/Rakefile CHANGED
@@ -2,12 +2,12 @@ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |task|
5
- task.libs << "test"
5
+ task.libs << "test/lib" << "test"
6
6
 
7
7
  task.test_files = Dir['test/**/test_*.rb'].reject {|path| path.end_with?("test_explore.rb") }
8
8
  task.verbose = true
9
9
  task.warning = true
10
- task.ruby_opts = %w[ --disable-did_you_mean ]
10
+ task.ruby_opts = %w[ --disable-did_you_mean -rhelper ]
11
11
  end
12
12
 
13
13
  Rake::TestTask.new("test:explore") do |task|
@@ -21,6 +21,13 @@ end
21
21
 
22
22
  task default: %i(test)
23
23
 
24
+ task :sync_tool do
25
+ require 'fileutils'
26
+ FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
27
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
28
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
29
+ end
30
+
24
31
  namespace :test do
25
32
  namespace :accuracy do
26
33
  desc "Download Wiktionary's Simple English data and save it as a dictionary"
@@ -1,24 +1,49 @@
1
1
  module DidYouMean
2
2
  module Correctable
3
- SKIP_TO_S_FOR_SUPER_LOOKUP = true
4
- private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP
3
+ if Exception.method_defined?(:detailed_message)
4
+ # just for compatibility
5
+ def original_message
6
+ # we cannot use alias here because
7
+ to_s
8
+ end
9
+
10
+ def detailed_message(highlight: true, did_you_mean: true, **)
11
+ msg = super.dup
12
+
13
+ return msg unless did_you_mean
14
+
15
+ suggestion = DidYouMean.formatter.message_for(corrections)
16
+
17
+ if highlight
18
+ suggestion = suggestion.gsub(/.+/) { "\e[1m" + $& + "\e[m" }
19
+ end
5
20
 
6
- def original_message
7
- meth = method(:to_s)
8
- while meth.owner.const_defined?(:SKIP_TO_S_FOR_SUPER_LOOKUP)
9
- meth = meth.super_method
21
+ msg << suggestion
22
+ msg
23
+ rescue
24
+ super
25
+ end
26
+ else
27
+ SKIP_TO_S_FOR_SUPER_LOOKUP = true
28
+ private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP
29
+
30
+ def original_message
31
+ meth = method(:to_s)
32
+ while meth.owner.const_defined?(:SKIP_TO_S_FOR_SUPER_LOOKUP)
33
+ meth = meth.super_method
34
+ end
35
+ meth.call
10
36
  end
11
- meth.call
12
- end
13
37
 
14
- def to_s
15
- msg = super.dup
16
- suggestion = DidYouMean.formatter.message_for(corrections)
38
+ def to_s
39
+ msg = super.dup
40
+ suggestion = DidYouMean.formatter.message_for(corrections)
17
41
 
18
- msg << suggestion if !msg.include?(suggestion)
19
- msg
20
- rescue
21
- super
42
+ msg << suggestion if !msg.include?(suggestion)
43
+ msg
44
+ rescue
45
+ super
46
+ end
22
47
  end
23
48
 
24
49
  def corrections
@@ -1,8 +1,9 @@
1
+ # frozen-string-literal: true
2
+
1
3
  warn "`require 'did_you_mean/formatters/verbose_formatter'` is deprecated and falls back to the default formatter. "
2
4
 
3
5
  require_relative '../formatter'
4
6
 
5
- # frozen-string-literal: true
6
7
  module DidYouMean
7
8
  # For compatibility:
8
9
  VerboseFormatter = Formatter
@@ -79,7 +79,7 @@ module DidYouMean
79
79
  def corrections
80
80
  @corrections ||= SpellChecker
81
81
  .new(dictionary: (RB_RESERVED_WORDS + lvar_names + method_names + ivar_names + cvar_names))
82
- .correct(name) - NAMES_TO_EXCLUDE[@name]
82
+ .correct(name).uniq - NAMES_TO_EXCLUDE[@name]
83
83
  end
84
84
  end
85
85
  end
@@ -1,3 +1,3 @@
1
1
  module DidYouMean
2
- VERSION = "1.6.1".freeze
2
+ VERSION = "1.6.2".freeze
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require_relative '../helper'
2
2
 
3
3
  class NameErrorExtensionTest < Test::Unit::TestCase
4
+ include DidYouMean::TestHelper
5
+
4
6
  SPELL_CHECKERS = DidYouMean.spell_checkers
5
7
 
6
8
  class TestSpellChecker
@@ -20,8 +22,12 @@ class NameErrorExtensionTest < Test::Unit::TestCase
20
22
  end
21
23
 
22
24
  def test_message
23
- assert_match(/Did you mean\? does_exist/, @error.to_s)
24
- assert_match(/Did you mean\? does_exist/, @error.message)
25
+ if Exception.method_defined?(:detailed_message)
26
+ assert_match(/Did you mean\? does_exist/, @error.detailed_message)
27
+ else
28
+ assert_match(/Did you mean\? does_exist/, @error.to_s)
29
+ assert_match(/Did you mean\? does_exist/, @error.message)
30
+ end
25
31
  end
26
32
 
27
33
  def test_to_s_does_not_make_disruptive_changes_to_error_message
@@ -29,8 +35,8 @@ class NameErrorExtensionTest < Test::Unit::TestCase
29
35
  raise NameError, "uninitialized constant Object"
30
36
  end
31
37
 
32
- error.to_s
33
- assert_equal 1, error.to_s.scan("Did you mean?").count
38
+ get_message(error)
39
+ assert_equal 1, get_message(error).scan("Did you mean?").count
34
40
  end
35
41
 
36
42
  def test_correctable_error_objects_are_dumpable
@@ -41,7 +47,7 @@ class NameErrorExtensionTest < Test::Unit::TestCase
41
47
  e
42
48
  end
43
49
 
44
- error.to_s
50
+ get_message(error)
45
51
 
46
52
  assert_equal "undefined method `sizee' for #<File:test_name_error_extension.rb (closed)>",
47
53
  Marshal.load(Marshal.dump(error)).original_message
data/test/helper.rb CHANGED
@@ -29,5 +29,15 @@ module DidYouMean
29
29
  def assert_correction(expected, array)
30
30
  assert_equal Array(expected), array, "Expected #{array.inspect} to only include #{expected.inspect}"
31
31
  end
32
+
33
+ def get_message(err)
34
+ if err.respond_to?(:detailed_message)
35
+ err.detailed_message(highlight: false)
36
+ else
37
+ err.to_s
38
+ end
39
+ end
40
+
41
+ module_function :get_message
32
42
  end
33
43
  end