did_you_mean 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ruby.yml +2 -2
- data/CHANGELOG.md +1 -1
- data/Rakefile +9 -2
- data/lib/did_you_mean/core_ext/name_error.rb +40 -15
- data/lib/did_you_mean/formatters/verbose_formatter.rb +2 -1
- data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +1 -1
- data/lib/did_you_mean/version.rb +1 -1
- data/test/core_ext/test_name_error_extension.rb +11 -5
- data/test/helper.rb +10 -0
- data/test/lib/core_assertions.rb +757 -0
- data/test/lib/envutil.rb +372 -0
- data/test/lib/find_executable.rb +22 -0
- data/test/lib/helper.rb +3 -0
- data/test/spell_checking/test_key_name_check.rb +7 -7
- data/test/spell_checking/test_method_name_check.rb +10 -10
- data/test/spell_checking/test_pattern_key_name_check.rb +1 -1
- data/test/spell_checking/test_require_path_check.rb +3 -3
- data/test/spell_checking/test_variable_name_check.rb +24 -12
- data/test/test_ractor_compatibility.rb +86 -71
- metadata +12 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8872d94ffdf1a826aa542768069af9a51087bc5156e54c277ccad671088724f
|
|
4
|
+
data.tar.gz: cd6c5001ef84b6618b488995b7c707dd88e9586df229067b25c6e4fb77c43882
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c18bc93c847891f6061325c0a2f1f6b067af698adbd49a6b96172c1a7cda5f4fd96fbf7e9d5b1aeb1d0851caf702c28351239edc4c62f76b2ba919e6e686f2d
|
|
7
|
+
data.tar.gz: 9c6f42e8c30a6a803c42409192757ecf13f03398771e682d2cf98976a391e7a5976af38a8d5eea972fcc3560ff16e8dffbfa5e3cc2eef96228c2a2fbd8bea030
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -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@
|
|
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@
|
|
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::
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
38
|
+
def to_s
|
|
39
|
+
msg = super.dup
|
|
40
|
+
suggestion = DidYouMean.formatter.message_for(corrections)
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
data/lib/did_you_mean/version.rb
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
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
|
|
33
|
-
assert_equal 1, error.
|
|
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
|
|
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
|