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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8872d94ffdf1a826aa542768069af9a51087bc5156e54c277ccad671088724f
4
- data.tar.gz: cd6c5001ef84b6618b488995b7c707dd88e9586df229067b25c6e4fb77c43882
3
+ metadata.gz: b4bab700f00029060d2483f4e158b67d5cc27bc76ead15422904bbfff21cdf59
4
+ data.tar.gz: 8826dd9596cdaf03dfb13a0dc044ceff7a4d774cd240d3a4b45d76cea3b0800f
5
5
  SHA512:
6
- metadata.gz: 5c18bc93c847891f6061325c0a2f1f6b067af698adbd49a6b96172c1a7cda5f4fd96fbf7e9d5b1aeb1d0851caf702c28351239edc4c62f76b2ba919e6e686f2d
7
- data.tar.gz: 9c6f42e8c30a6a803c42409192757ecf13f03398771e682d2cf98976a391e7a5976af38a8d5eea972fcc3560ff16e8dffbfa5e3cc2eef96228c2a2fbd8bea030
6
+ metadata.gz: bee82c9926dacf6600c08b16f1b7d0e0d58872a28e9dde55581c491a2abb3d3725a2fd6f3990a2bb0b6ded3936cde87806ab1c0db7f2f03f5612ff8c15c0518b
7
+ data.tar.gz: f56276fa0af2412ca6d86259b1f21e0654122ece7dd70200981594aa1d045b2fe3c115ed0495cb96ee2c7aaf25fc5daf6948be788f5f63b258691c2e5396407e
@@ -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: [ '2.5', '2.6', '2.7', '3.0', 'ruby-head', 'jruby-9.2', 'jruby-head' ]
23
+ ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
17
24
  steps:
18
- - uses: actions/checkout@v3
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@v3
37
+ - uses: actions/checkout@v4
31
38
  - uses: ruby/setup-ruby@v1
32
39
  with:
33
- ruby-version: 2.7.1
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
@@ -8,3 +8,8 @@ gem 'benchmark_driver'
8
8
  gem 'memory_profiler'
9
9
  gem 'jaro_winkler', '>= 1.4.0'
10
10
  gem 'test-unit'
11
+ gem "test-unit-ruby-core"
12
+
13
+ group :development do
14
+ gem "rake"
15
+ end
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
@@ -20,6 +20,7 @@ before_test:
20
20
  - gem -v
21
21
  - bundle -v
22
22
  - gem uni did_you_mean
23
+ - gem i test-unit-ruby-core
23
24
 
24
25
  test_script:
25
26
  - rake
data/did_you_mean.gemspec CHANGED
@@ -22,6 +22,4 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.required_ruby_version = '>= 2.5.0'
25
-
26
- spec.add_development_dependency "rake"
27
25
  end
@@ -8,8 +8,7 @@ module DidYouMean
8
8
 
9
9
  m = 0.0
10
10
  t = 0.0
11
- range = (length2 / 2).floor - 1
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[i] && i < 4 ? prefix_bonus += 1 : break
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(&:inspect)
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(&:inspect)
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
@@ -1,3 +1,3 @@
1
1
  module DidYouMean
2
- VERSION = "1.6.2".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
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
- assert_equal "undefined method `sizee' for #<File:test_name_error_extension.rb (closed)>",
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
@@ -1,3 +1,3 @@
1
1
  require "test/unit"
2
- require_relative "core_assertions"
2
+ require "core_assertions"
3
3
  Test::Unit::TestCase.include Test::Unit::CoreAssertions
@@ -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: 1.6.2
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: 2022-12-05 00:00:00.000000000 Z
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.4.0.dev
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