did_you_mean 1.6.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +12 -5
- data/CHANGELOG.md +29 -0
- data/Gemfile +5 -0
- data/Rakefile +0 -7
- data/appveyor.yml +1 -0
- data/did_you_mean.gemspec +0 -2
- data/lib/did_you_mean/jaro_winkler.rb +2 -5
- data/lib/did_you_mean/spell_checkers/key_error_checker.rb +9 -1
- data/lib/did_you_mean/spell_checkers/method_name_checker.rb +7 -0
- data/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb +9 -1
- data/lib/did_you_mean/version.rb +1 -1
- data/lib/did_you_mean.rb +0 -24
- data/test/core_ext/test_name_error_extension.rb +2 -2
- data/test/lib/helper.rb +1 -1
- data/test/spell_checking/test_method_name_check.rb +18 -0
- metadata +4 -24
- data/test/lib/core_assertions.rb +0 -757
- data/test/lib/envutil.rb +0 -372
- data/test/lib/find_executable.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4bab700f00029060d2483f4e158b67d5cc27bc76ead15422904bbfff21cdf59
|
4
|
+
data.tar.gz: 8826dd9596cdaf03dfb13a0dc044ceff7a4d774cd240d3a4b45d76cea3b0800f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee82c9926dacf6600c08b16f1b7d0e0d58872a28e9dde55581c491a2abb3d3725a2fd6f3990a2bb0b6ded3936cde87806ab1c0db7f2f03f5612ff8c15c0518b
|
7
|
+
data.tar.gz: f56276fa0af2412ca6d86259b1f21e0654122ece7dd70200981594aa1d045b2fe3c115ed0495cb96ee2c7aaf25fc5daf6948be788f5f63b258691c2e5396407e
|
data/.github/workflows/ruby.yml
CHANGED
@@ -9,28 +9,35 @@ on:
|
|
9
9
|
- 'master'
|
10
10
|
|
11
11
|
jobs:
|
12
|
+
ruby-versions:
|
13
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
14
|
+
with:
|
15
|
+
engine: cruby-jruby
|
16
|
+
min_version: 2.5
|
17
|
+
|
12
18
|
build:
|
19
|
+
needs: ruby-versions
|
13
20
|
runs-on: ubuntu-latest
|
14
21
|
strategy:
|
15
22
|
matrix:
|
16
|
-
ruby:
|
23
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
17
24
|
steps:
|
18
|
-
- uses: actions/checkout@
|
25
|
+
- uses: actions/checkout@v4
|
19
26
|
- uses: ruby/setup-ruby@v1
|
20
27
|
with:
|
21
28
|
ruby-version: ${{ matrix.ruby }}
|
22
29
|
- name: Build and test with Rake
|
23
30
|
run: |
|
24
|
-
gem i test-unit
|
31
|
+
gem i test-unit test-unit-ruby-core
|
25
32
|
RUBYOPT='--disable-did_you_mean' rake
|
26
33
|
|
27
34
|
benchmark:
|
28
35
|
runs-on: ubuntu-latest
|
29
36
|
steps:
|
30
|
-
- uses: actions/checkout@
|
37
|
+
- uses: actions/checkout@v4
|
31
38
|
- uses: ruby/setup-ruby@v1
|
32
39
|
with:
|
33
|
-
ruby-version:
|
40
|
+
ruby-version: 3.3.6
|
34
41
|
- name: Test performance and accuracy
|
35
42
|
run: |
|
36
43
|
gem install bundler
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
## v2.0.0
|
2
|
+
|
3
|
+
_unreleased_
|
4
|
+
|
5
|
+
#### 🚨 Breaking Changes
|
6
|
+
|
7
|
+
- Removed deprecated constants for Ruby 3.4 (#194)
|
8
|
+
|
9
|
+
#### ⭐️ New Features
|
10
|
+
|
11
|
+
- Do not include a backtick in error messages and backtraces (#192, https://bugs.ruby-lang.org/issues/16495)
|
12
|
+
|
13
|
+
#### 🐞 Bug Fixes
|
14
|
+
|
15
|
+
- Do not use #inspect to avoid unexpected performance degradation (bd11eefd6cc724919dd645965856966744a554c6)
|
16
|
+
|
17
|
+
## v1.6.3
|
18
|
+
|
19
|
+
_<sup>released at 2022-12-19 5:57:00 UTC</sup>_
|
20
|
+
|
21
|
+
- Do not suggest #name= for #name.
|
22
|
+
|
23
|
+
## v1.6.2
|
24
|
+
|
25
|
+
_<sup>released at 2022-12-05 10:29:20 UTC</sup>_
|
26
|
+
|
27
|
+
- Define Exception#detailed_message instead of clobbering #message
|
28
|
+
- Fixed correction duplicates in VaribaleNameChecker
|
29
|
+
|
1
30
|
## v1.6.1
|
2
31
|
|
3
32
|
_<sup>released at 2020-12-22 13:22:35 UTC</sup>_
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -21,13 +21,6 @@ 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
|
-
|
31
24
|
namespace :test do
|
32
25
|
namespace :accuracy do
|
33
26
|
desc "Download Wiktionary's Simple English data and save it as a dictionary"
|
data/appveyor.yml
CHANGED
data/did_you_mean.gemspec
CHANGED
@@ -8,8 +8,7 @@ module DidYouMean
|
|
8
8
|
|
9
9
|
m = 0.0
|
10
10
|
t = 0.0
|
11
|
-
range =
|
12
|
-
range = 0 if range < 0
|
11
|
+
range = length2 > 3 ? length2 / 2 - 1 : 0
|
13
12
|
flags1 = 0
|
14
13
|
flags2 = 0
|
15
14
|
|
@@ -72,10 +71,8 @@ module DidYouMean
|
|
72
71
|
codepoints2 = str2.codepoints
|
73
72
|
prefix_bonus = 0
|
74
73
|
|
75
|
-
i = 0
|
76
74
|
str1.each_codepoint do |char1|
|
77
|
-
char1 == codepoints2[
|
78
|
-
i += 1
|
75
|
+
char1 == codepoints2[prefix_bonus] && prefix_bonus < 4 ? prefix_bonus += 1 : break
|
79
76
|
end
|
80
77
|
|
81
78
|
jaro_distance + (prefix_bonus * WEIGHT * (1 - jaro_distance))
|
@@ -14,7 +14,15 @@ module DidYouMean
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def exact_matches
|
17
|
-
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(
|
17
|
+
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_object(symbol_or_object)
|
21
|
+
if symbol_or_object.is_a?(Symbol)
|
22
|
+
":#{symbol_or_object}"
|
23
|
+
else
|
24
|
+
symbol_or_object.to_s
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
@@ -59,6 +59,13 @@ module DidYouMean
|
|
59
59
|
method_names = receiver.methods + receiver.singleton_methods
|
60
60
|
method_names += receiver.private_methods if @private_call
|
61
61
|
method_names.uniq!
|
62
|
+
# Assume that people trying to use a writer are not interested in a reader
|
63
|
+
# and vice versa
|
64
|
+
if method_name.match?(/=\Z/)
|
65
|
+
method_names.select! { |name| name.match?(/=\Z/) }
|
66
|
+
else
|
67
|
+
method_names.reject! { |name| name.match?(/=\Z/) }
|
68
|
+
end
|
62
69
|
method_names
|
63
70
|
else
|
64
71
|
[]
|
@@ -14,7 +14,15 @@ module DidYouMean
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def exact_matches
|
17
|
-
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(
|
17
|
+
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_object(symbol_or_object)
|
21
|
+
if symbol_or_object.is_a?(Symbol)
|
22
|
+
":#{symbol_or_object}"
|
23
|
+
else
|
24
|
+
symbol_or_object.to_s
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
data/lib/did_you_mean/version.rb
CHANGED
data/lib/did_you_mean.rb
CHANGED
@@ -113,30 +113,6 @@ module DidYouMean
|
|
113
113
|
correct_error LoadError, RequirePathChecker if RUBY_VERSION >= '2.8.0'
|
114
114
|
correct_error NoMatchingPatternKeyError, PatternKeyNameChecker if defined?(::NoMatchingPatternKeyError)
|
115
115
|
|
116
|
-
# TODO: Remove on 3.3:
|
117
|
-
class DeprecatedMapping # :nodoc:
|
118
|
-
def []=(key, value)
|
119
|
-
warn "Calling `DidYouMean::SPELL_CHECKERS[#{key.to_s}] = #{value.to_s}' has been deprecated. " \
|
120
|
-
"Please call `DidYouMean.correct_error(#{key.to_s}, #{value.to_s})' instead."
|
121
|
-
|
122
|
-
DidYouMean.correct_error(key, value)
|
123
|
-
end
|
124
|
-
|
125
|
-
def merge!(hash)
|
126
|
-
warn "Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. " \
|
127
|
-
"Please call `DidYouMean.correct_error(error_name, spell_checker)' instead."
|
128
|
-
|
129
|
-
hash.each do |error_class, spell_checker|
|
130
|
-
DidYouMean.correct_error(error_class, spell_checker)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# TODO: Remove on 3.3:
|
136
|
-
SPELL_CHECKERS = DeprecatedMapping.new
|
137
|
-
deprecate_constant :SPELL_CHECKERS
|
138
|
-
private_constant :DeprecatedMapping
|
139
|
-
|
140
116
|
# Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+.
|
141
117
|
def self.formatter
|
142
118
|
if defined?(Ractor)
|
@@ -49,7 +49,7 @@ class NameErrorExtensionTest < Test::Unit::TestCase
|
|
49
49
|
|
50
50
|
get_message(error)
|
51
51
|
|
52
|
-
|
53
|
-
Marshal.load(Marshal.dump(error)).original_message
|
52
|
+
assert_match(/^undefined method [`']sizee' for /,
|
53
|
+
Marshal.load(Marshal.dump(error)).original_message)
|
54
54
|
end
|
55
55
|
end
|
data/test/lib/helper.rb
CHANGED
@@ -4,6 +4,8 @@ class MethodNameCheckTest < Test::Unit::TestCase
|
|
4
4
|
include DidYouMean::TestHelper
|
5
5
|
|
6
6
|
class User
|
7
|
+
attr_writer :writer
|
8
|
+
attr_reader :reader
|
7
9
|
def friends; end
|
8
10
|
def first_name; end
|
9
11
|
def descendants; end
|
@@ -144,4 +146,20 @@ class MethodNameCheckTest < Test::Unit::TestCase
|
|
144
146
|
assert_correction [], error.corrections
|
145
147
|
assert_not_match(/Did you mean\? +yield/, get_message(error))
|
146
148
|
end if RUBY_ENGINE != "jruby"
|
149
|
+
|
150
|
+
# Do not suggest `name=` for `name`
|
151
|
+
def test_does_not_suggest_writer
|
152
|
+
error = assert_raise(NoMethodError) { @user.writer }
|
153
|
+
|
154
|
+
assert_correction [], error.corrections
|
155
|
+
assert_not_match(/Did you mean\? writer=/, get_message(error))
|
156
|
+
end
|
157
|
+
|
158
|
+
# Do not suggest `name` for `name=`
|
159
|
+
def test_does_not_suggest_reader
|
160
|
+
error = assert_raise(NoMethodError) { @user.reader = 1 }
|
161
|
+
|
162
|
+
assert_correction [], error.corrections
|
163
|
+
assert_not_match(/Did you mean\? reader/, get_message(error))
|
164
|
+
end
|
147
165
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: did_you_mean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2024-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: The gem that has been saving people from typos since 2014.
|
28
14
|
email:
|
29
15
|
- mail@yukinishijima.net
|
@@ -79,9 +65,6 @@ files:
|
|
79
65
|
- test/fixtures/mini_dir.yml
|
80
66
|
- test/fixtures/rspec_dir.yml
|
81
67
|
- test/helper.rb
|
82
|
-
- test/lib/core_assertions.rb
|
83
|
-
- test/lib/envutil.rb
|
84
|
-
- test/lib/find_executable.rb
|
85
68
|
- test/lib/helper.rb
|
86
69
|
- test/spell_checking/test_class_name_check.rb
|
87
70
|
- test/spell_checking/test_key_name_check.rb
|
@@ -117,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
100
|
- !ruby/object:Gem::Version
|
118
101
|
version: '0'
|
119
102
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.5.22
|
121
104
|
signing_key:
|
122
105
|
specification_version: 4
|
123
106
|
summary: '"Did you mean?" experience in Ruby'
|
@@ -128,9 +111,6 @@ test_files:
|
|
128
111
|
- test/fixtures/mini_dir.yml
|
129
112
|
- test/fixtures/rspec_dir.yml
|
130
113
|
- test/helper.rb
|
131
|
-
- test/lib/core_assertions.rb
|
132
|
-
- test/lib/envutil.rb
|
133
|
-
- test/lib/find_executable.rb
|
134
114
|
- test/lib/helper.rb
|
135
115
|
- test/spell_checking/test_class_name_check.rb
|
136
116
|
- test/spell_checking/test_key_name_check.rb
|