did_you_mean 1.6.1 → 1.6.3

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: efe3eda9f13dc6e837711f29799ee6701771200e75f11017c1f18cc521de10ca
4
+ data.tar.gz: 96476669d502e64083fa91cbbb7c91c583228b86f34ea0b22929bf38c931ee6e
5
5
  SHA512:
6
- metadata.gz: 45ee6a7e79a463743a5529f38b503c78266458b07fe2e8a85d8f4e0ece2c65dbc40baf0aaa96c4c6592bca868c4a99f9d6001f4b5b9c033bf504aedb34ba5340
7
- data.tar.gz: f259d9fef544f4071733007277c672c16f95bbe0e7d303bc6bf52fa0d7fa7108dcf615d6502e7950d2b48e4ce720034cc2d23096d52bee6f03e7206eab02569b
6
+ metadata.gz: 2697751c0b6ba2afa9153b41c306118fddd7ce584cdb9de9f71974cf924d83208fdb47a307e1ee4ea6161b63641334ea7ff1ca58fff0e141116809d6690e254b
7
+ data.tar.gz: 1cd6e82755d1d66c9503fc5ff3f6c42931860edb3fbb11c94c1411317ddffaa1ba1f0e7020cc1ad553cb0ad26195e6ab897a0c88a8fad58cad779d008f38bbb1
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -13,9 +13,9 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby: [ '2.5', '2.6', '2.7', '3.0', 'ruby-head', 'jruby-9.2', 'jruby-head' ]
16
+ ruby: [ '2.5', '2.6', '2.7', '3.0', '3.1', 'ruby-head', 'jruby-9.2', 'jruby-9.3', '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,10 +27,10 @@ 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
- ruby-version: 2.7.1
33
+ ruby-version: 3.1.3
34
34
  - name: Test performance and accuracy
35
35
  run: |
36
36
  gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## v1.6.3
2
+
3
+ _<sup>released at 2022-12-19 5:57:00 UTC</sup>_
4
+
5
+ - Do not suggest #name= for #name.
6
+
7
+ ## v1.6.2
8
+
9
+ _<sup>released at 2022-12-05 10:29:20 UTC</sup>_
10
+
11
+ - Define Exception#detailed_message instead of clobbering #message
12
+ - Fixed correction duplicates in VaribaleNameChecker
13
+
1
14
  ## v1.6.1
2
15
 
3
16
  _<sup>released at 2020-12-22 13:22:35 UTC</sup>_
@@ -5,7 +18,7 @@ _<sup>released at 2020-12-22 13:22:35 UTC</sup>_
5
18
  #### Deprecations
6
19
 
7
20
  - Deprecate custom formatters to reduce complexity for Ractor support.
8
- - Deprecate access to the `DidYouMean::SPELL_CHECEKRS` constant for Ractor support.
21
+ - Deprecate access to the `DidYouMean::SPELL_CHECKERS` constant for Ractor support.
9
22
 
10
23
  #### Features
11
24
 
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
@@ -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
  []
@@ -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.3".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