did_you_mean 1.2.2 → 1.3.0
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/.ruby-version +1 -1
- data/.travis.yml +2 -1
- data/CHANGELOG.md +28 -3
- data/README.md +39 -0
- data/lib/did_you_mean.rb +77 -37
- data/lib/did_you_mean/formatters/plain_formatter.rb +24 -0
- data/lib/did_you_mean/formatters/verbose_formatter.rb +36 -0
- data/lib/did_you_mean/spell_checkers/method_name_checker.rb +30 -1
- data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +55 -3
- data/lib/did_you_mean/version.rb +1 -1
- data/test/core_ext/name_error_extension_test.rb +0 -8
- data/test/spell_checking/method_name_check_test.rb +7 -0
- data/test/spell_checking/variable_name_check_test.rb +15 -1
- metadata +3 -6
- data/lib/did_you_mean/verbose_formatter.rb +0 -7
- data/test/deprecated_formatter_test.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50bf04523f12cc4556ea28643d05f957a6ed95288d022716bbd32b325ea10feb
|
|
4
|
+
data.tar.gz: eeb093d01d27dae887f7ecbc5e4c530db5230743de2c7280b19f139f56e11638
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0941cfdae93b66e3485c0850f2763c869971a1d7cff386fe66d51739d8869155d8ae868016210a0d2935f81aa8185477c9db162029d5a754240f210a2f3b9df8'
|
|
7
|
+
data.tar.gz: fc53dbc6ae27025325d36084b5be82f0b462addc83a3fa7a0b0b780b6aed2b2dc5f40cc3a3ad7213eeb2a03476723f0ae36681a534d27b9991c95d5ab2197b66
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.5.
|
|
1
|
+
2.5.0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
+
## [v1.2.1](https://github.com/yuki24/did_you_mean/tree/v1.2.1)
|
|
2
|
+
|
|
3
|
+
_<sup>released at 2018-04-03 04:44:47 UTC</sup>_
|
|
4
|
+
|
|
5
|
+
#### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Fixed a bug where DYM suggests the same class name in the error message ([#102](https://github.com/yuki24/did_you_mean/issues/102), [@schneems](https://github.com/schneems))
|
|
8
|
+
- Fixed a bug where the deprecated `DidYouMean::Formatter` has been removed unexpectedly ([#103](https://github.com/yuki24/did_you_mean/issues/103), [<tt>4b5ba32</tt>](https://github.com/yuki24/did_you_mean/commit/4b5ba3215975df1dd8e9c7eacffcf02abfffa92e))
|
|
9
|
+
|
|
10
|
+
#### Other Changes
|
|
11
|
+
|
|
12
|
+
- Non-production code that has a non-commercial lisence has been removed from gem releases ([#105](https://github.com/yuki24/did_you_mean/issues/105), [@jbotelho2-bb](https://github.com/jbotelho2-bb))
|
|
13
|
+
|
|
14
|
+
## [v1.2.0](https://github.com/yuki24/did_you_mean/tree/v1.2.0)
|
|
15
|
+
|
|
16
|
+
_<sup>released at 2018-01-02 20:49:35 UTC</sup>_
|
|
17
|
+
|
|
18
|
+
**This version 1.2.0 only has support for Ruby 2.5.0 and later as it uses new features that are only available in 2.5. All future patch releases under 1.2.\* will only be compatible with Ruby 2.5.0 and later as well. Versions earlier than 1.1.\* will still be maintained until Ruby 2.4 is deprecated. Any other versions below 1.0 will no longer be maintained.**
|
|
19
|
+
|
|
20
|
+
#### New features
|
|
21
|
+
|
|
22
|
+
- The `KeyError` name suggestion feature has been promoted to a stable feature and is available by default ([<tt>acf5945</tt>](https://github.com/yuki24/did_you_mean/commit/acf59450dfb67eefae9b465ccc8029af46ae7dd0), [https://bugs.ruby-lang.org/issues/12063](https://bugs.ruby-lang.org/issues/12063))
|
|
23
|
+
- Now suggests `true`, `false` or `nil` if a NameError occurs because of a typo in these names ([#94](https://github.com/yuki24/did_you_mean/pull/94), [@styd](https://github.com/styd))
|
|
24
|
+
- New Formatter API: This provides a clean way to customize DidYouMean’s formatter without overriding the default formatter. Please refer to [the built-in verbose formatter](https://github.com/yuki24/did_you_mean/blob/671cdff/lib/did_you_mean/verbose.rb) for how to use it
|
|
25
|
+
|
|
1
26
|
## [v1.1.2](https://github.com/yuki24/did_you_mean/tree/v1.1.2)
|
|
2
27
|
|
|
3
28
|
_<sup>released at 2017-09-24 07:28:48 UTC</sup>_
|
|
4
29
|
|
|
5
|
-
**This version is compatible with Ruby 2.4 and
|
|
30
|
+
**This version is only compatible with Ruby 2.4 and later.**
|
|
6
31
|
|
|
7
32
|
#### Bug Fixes
|
|
8
33
|
|
|
@@ -18,7 +43,7 @@ _<sup>released at 2017-09-24 07:24:02 UTC</sup>_
|
|
|
18
43
|
|
|
19
44
|
_<sup>released at 2016-12-19 23:19:06 UTC</sup>_
|
|
20
45
|
|
|
21
|
-
The version `1.1.0` only has support for Ruby 2.4.0 and later. Also, all patch
|
|
46
|
+
The version `1.1.0` only has support for Ruby 2.4.0 and later. Also, all patch releases under `1.1.*` will only be compatible with Ruby 2.4.0 and later as well. Versions under `1.0.*` will still be maintained until Ruby 2.3 is deprecated. Any other versions below `1.0` will no longer be maintained.
|
|
22
47
|
|
|
23
48
|
#### New Features
|
|
24
49
|
|
|
@@ -102,7 +127,7 @@ _<sup>released at 2015-12-25 05:13:04 UTC</sup>_
|
|
|
102
127
|
|
|
103
128
|
_<sup>released at 2015-12-25 05:02:25 UTC</sup>_
|
|
104
129
|
|
|
105
|
-
#### Internal
|
|
130
|
+
#### Internal Changes
|
|
106
131
|
|
|
107
132
|
- No longer uses `TracePoint` API by default. fixes [#55](https://github.com/yuki24/did_you_mean/issues/55) and [#56](https://github.com/yuki24/did_you_mean/issues/56)
|
|
108
133
|
|
data/README.md
CHANGED
|
@@ -108,6 +108,45 @@ OBject
|
|
|
108
108
|
#
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
## Disabling `did_you_mean`
|
|
112
|
+
|
|
113
|
+
Occasionally, you may want to disable the `did_you_mean` gem for e.g. debugging issues in the error object itself. You
|
|
114
|
+
can disable it entirely by specifying `--disable-did_you_mean` option to the `ruby` command:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
$ ruby --disable-did_you_mean -e "1.zeor?"
|
|
118
|
+
-e:1:in `<main>': undefined method `zeor?' for 1:Integer (NameError)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
When you do not have direct access to the `ruby` command (e.g. `rails console`, `irb`), you could applyoptions using the
|
|
122
|
+
`RUBYOPT` environment variable:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
$ RUBYOPT='--disable-did_you_mean' irb
|
|
126
|
+
irb:0> 1.zeor?
|
|
127
|
+
# => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Getting the original error message
|
|
131
|
+
|
|
132
|
+
Sometimes, you do not want to disable the gem entirely, but need to get the original error message without suggestions
|
|
133
|
+
(e.g. testing). In this case, you could use the `#original_message` method on the error object:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
no_method_error = begin
|
|
137
|
+
1.zeor?
|
|
138
|
+
rescue NoMethodError => error
|
|
139
|
+
error
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
no_method_error.message
|
|
143
|
+
# => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
144
|
+
# Did you mean? zero?
|
|
145
|
+
|
|
146
|
+
no_method_error.original_message
|
|
147
|
+
# => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
148
|
+
```
|
|
149
|
+
|
|
111
150
|
## Contributing
|
|
112
151
|
|
|
113
152
|
1. Fork it (http://github.com/yuki24/did_you_mean/fork)
|
data/lib/did_you_mean.rb
CHANGED
|
@@ -9,29 +9,83 @@ require 'did_you_mean/spell_checkers/null_checker'
|
|
|
9
9
|
|
|
10
10
|
require "did_you_mean/formatters/plain_formatter"
|
|
11
11
|
|
|
12
|
+
# The +DidYouMean+ gem adds functionality to suggest possible method/class
|
|
13
|
+
# names upon errors such as +NameError+ and +NoMethodError+. In Ruby 2.3 or
|
|
14
|
+
# later, it is automatically activated during startup.
|
|
15
|
+
#
|
|
16
|
+
# @example
|
|
17
|
+
#
|
|
18
|
+
# methosd
|
|
19
|
+
# # => NameError: undefined local variable or method `methosd' for main:Object
|
|
20
|
+
# # Did you mean? methods
|
|
21
|
+
# # method
|
|
22
|
+
#
|
|
23
|
+
# OBject
|
|
24
|
+
# # => NameError: uninitialized constant OBject
|
|
25
|
+
# # Did you mean? Object
|
|
26
|
+
#
|
|
27
|
+
# @full_name = "Yuki Nishijima"
|
|
28
|
+
# first_name, last_name = full_name.split(" ")
|
|
29
|
+
# # => NameError: undefined local variable or method `full_name' for main:Object
|
|
30
|
+
# # Did you mean? @full_name
|
|
31
|
+
#
|
|
32
|
+
# @@full_name = "Yuki Nishijima"
|
|
33
|
+
# @@full_anme
|
|
34
|
+
# # => NameError: uninitialized class variable @@full_anme in Object
|
|
35
|
+
# # Did you mean? @@full_name
|
|
36
|
+
#
|
|
37
|
+
# full_name = "Yuki Nishijima"
|
|
38
|
+
# full_name.starts_with?("Y")
|
|
39
|
+
# # => NoMethodError: undefined method `starts_with?' for "Yuki Nishijima":String
|
|
40
|
+
# # Did you mean? start_with?
|
|
41
|
+
#
|
|
42
|
+
# hash = {foo: 1, bar: 2, baz: 3}
|
|
43
|
+
# hash.fetch(:fooo)
|
|
44
|
+
# # => KeyError: key not found: :fooo
|
|
45
|
+
# # Did you mean? :foo
|
|
46
|
+
#
|
|
47
|
+
#
|
|
48
|
+
# == Disabling +did_you_mean+
|
|
49
|
+
#
|
|
50
|
+
# Occasionally, you may want to disable the +did_you_mean+ gem for e.g.
|
|
51
|
+
# debugging issues in the error object itself. You can disable it entirely by
|
|
52
|
+
# specifying +--disable-did_you_mean+ option to the +ruby+ command:
|
|
53
|
+
#
|
|
54
|
+
# $ ruby --disable-did_you_mean -e "1.zeor?"
|
|
55
|
+
# -e:1:in `<main>': undefined method `zeor?' for 1:Integer (NameError)
|
|
56
|
+
#
|
|
57
|
+
# When you do not have direct access to the +ruby+ command (e.g.
|
|
58
|
+
# +rails console+, +irb+), you could applyoptions using the +RUBYOPT+
|
|
59
|
+
# environment variable:
|
|
60
|
+
#
|
|
61
|
+
# $ RUBYOPT='--disable-did_you_mean' irb
|
|
62
|
+
# irb:0> 1.zeor?
|
|
63
|
+
# # => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
64
|
+
#
|
|
65
|
+
#
|
|
66
|
+
# == Getting the original error message
|
|
67
|
+
#
|
|
68
|
+
# Sometimes, you do not want to disable the gem entirely, but need to get the
|
|
69
|
+
# original error message without suggestions (e.g. testing). In this case, you
|
|
70
|
+
# could use the +#original_message+ method on the error object:
|
|
71
|
+
#
|
|
72
|
+
# no_method_error = begin
|
|
73
|
+
# 1.zeor?
|
|
74
|
+
# rescue NoMethodError => error
|
|
75
|
+
# error
|
|
76
|
+
# end
|
|
77
|
+
#
|
|
78
|
+
# no_method_error.message
|
|
79
|
+
# # => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
80
|
+
# # Did you mean? zero?
|
|
81
|
+
#
|
|
82
|
+
# no_method_error.original_message
|
|
83
|
+
# # => NoMethodError (undefined method `zeor?' for 1:Integer)
|
|
84
|
+
#
|
|
12
85
|
module DidYouMean
|
|
13
|
-
|
|
14
|
-
%i(
|
|
15
|
-
+
|
|
16
|
-
<<
|
|
17
|
-
[]=
|
|
18
|
-
insert
|
|
19
|
-
unshift
|
|
20
|
-
push
|
|
21
|
-
).each do |method_name|
|
|
22
|
-
eval <<-RUBY, nil, __FILE__, __LINE__ + 1
|
|
23
|
-
def #{method_name}(*)
|
|
24
|
-
warn "IGNORED_CALLERS has been deprecated and has no effect."
|
|
25
|
-
|
|
26
|
-
super
|
|
27
|
-
end
|
|
28
|
-
RUBY
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
IGNORED_CALLERS = DeprecatedIgnoredCallers.new
|
|
33
|
-
|
|
86
|
+
# Map of error types and spell checker objects.
|
|
34
87
|
SPELL_CHECKERS = Hash.new(NullChecker)
|
|
88
|
+
|
|
35
89
|
SPELL_CHECKERS.merge!({
|
|
36
90
|
"NameError" => NameErrorCheckers,
|
|
37
91
|
"NoMethodError" => MethodNameChecker,
|
|
@@ -41,29 +95,15 @@ module DidYouMean
|
|
|
41
95
|
NameError.prepend DidYouMean::Correctable
|
|
42
96
|
KeyError.prepend DidYouMean::Correctable
|
|
43
97
|
|
|
98
|
+
# Returns the currenctly set formatter. By default, it is set to +DidYouMean::Formatter+.
|
|
44
99
|
def self.formatter
|
|
45
100
|
@@formatter
|
|
46
101
|
end
|
|
47
102
|
|
|
103
|
+
# Updates the primary formatter used to format the suggestions.
|
|
48
104
|
def self.formatter=(formatter)
|
|
49
105
|
@@formatter = formatter
|
|
50
106
|
end
|
|
51
107
|
|
|
52
108
|
self.formatter = PlainFormatter.new
|
|
53
|
-
|
|
54
|
-
# Deprecated formatter
|
|
55
|
-
class Formatter #:nodoc:
|
|
56
|
-
def initialize(corrections = [])
|
|
57
|
-
@corrections = corrections
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def to_s
|
|
61
|
-
return "" if @corrections.empty?
|
|
62
|
-
|
|
63
|
-
output = "\nDid you mean? ".dup
|
|
64
|
-
output << @corrections.join("\n ")
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
deprecate_constant :Formatter
|
|
69
109
|
end
|
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
3
|
module DidYouMean
|
|
4
|
+
# The +DidYouMean::PlainFormatter+ is the basic, default formatter for the
|
|
5
|
+
# gem. The formatter responds to the +message_for+ method and it returns a
|
|
6
|
+
# human readable string.
|
|
4
7
|
class PlainFormatter
|
|
8
|
+
|
|
9
|
+
# Returns a human readable string that contains +corrections+. This
|
|
10
|
+
# formatter is designed to be less verbose to not take too much screen
|
|
11
|
+
# space while being helpful enough to the user.
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
#
|
|
15
|
+
# formatter = DidYouMean::PlainFormatter.new
|
|
16
|
+
#
|
|
17
|
+
# # displays suggestions in two lines with the leading empty line
|
|
18
|
+
# puts formatter.message_for(["methods", "method"])
|
|
19
|
+
#
|
|
20
|
+
# Did you mean? methods
|
|
21
|
+
# method
|
|
22
|
+
# # => nil
|
|
23
|
+
#
|
|
24
|
+
# # displays an empty line
|
|
25
|
+
# puts formatter.message_for([])
|
|
26
|
+
#
|
|
27
|
+
# # => nil
|
|
28
|
+
#
|
|
5
29
|
def message_for(corrections)
|
|
6
30
|
corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}"
|
|
7
31
|
end
|
|
@@ -1,7 +1,43 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
3
|
module DidYouMean
|
|
4
|
+
# The +DidYouMean::VerboseFormatter+ uses extra empty lines to make the
|
|
5
|
+
# suggestion stand out more in the error message.
|
|
6
|
+
#
|
|
7
|
+
# In order to activate the verbose formatter,
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
#
|
|
11
|
+
# OBject
|
|
12
|
+
# # => NameError: uninitialized constant OBject
|
|
13
|
+
# # Did you mean? Object
|
|
14
|
+
#
|
|
15
|
+
# require 'did_you_mean/verbose'
|
|
16
|
+
#
|
|
17
|
+
# OBject
|
|
18
|
+
# # => NameError: uninitialized constant OBject
|
|
19
|
+
# #
|
|
20
|
+
# # Did you mean? Object
|
|
21
|
+
# #
|
|
22
|
+
#
|
|
4
23
|
class VerboseFormatter
|
|
24
|
+
|
|
25
|
+
# Returns a human readable string that contains +corrections+. This
|
|
26
|
+
# formatter is designed to be less verbose to not take too much screen
|
|
27
|
+
# space while being helpful enough to the user.
|
|
28
|
+
#
|
|
29
|
+
# @example
|
|
30
|
+
#
|
|
31
|
+
# formatter = DidYouMean::PlainFormatter.new
|
|
32
|
+
#
|
|
33
|
+
# puts formatter.message_for(["methods", "method"])
|
|
34
|
+
#
|
|
35
|
+
#
|
|
36
|
+
# Did you mean? methods
|
|
37
|
+
# method
|
|
38
|
+
#
|
|
39
|
+
# # => nil
|
|
40
|
+
#
|
|
5
41
|
def message_for(corrections)
|
|
6
42
|
return "" if corrections.empty?
|
|
7
43
|
|
|
@@ -7,6 +7,35 @@ module DidYouMean
|
|
|
7
7
|
NAMES_TO_EXCLUDE = { NilClass => nil.methods }
|
|
8
8
|
NAMES_TO_EXCLUDE.default = []
|
|
9
9
|
|
|
10
|
+
# +MethodNameChecker::RB_RESERVED_WORDS+ is the list of reserved words in
|
|
11
|
+
# Ruby that take an argument. Unlike
|
|
12
|
+
# +VariableNameChecker::RB_RESERVED_WORDS+, those reserved words reqquires
|
|
13
|
+
# an argument, and a +NoMethodError+ is raised due to the presence of the
|
|
14
|
+
# argument.
|
|
15
|
+
#
|
|
16
|
+
# The +MethodNameChecker+ will use this list to suggest a reversed word if
|
|
17
|
+
# a +NoMethodError+ is raised and found closest matches.
|
|
18
|
+
#
|
|
19
|
+
# Also see +VariableNameChecker::RB_RESERVED_WORDS+.
|
|
20
|
+
RB_RESERVED_WORDS = %i(
|
|
21
|
+
alias
|
|
22
|
+
case
|
|
23
|
+
def
|
|
24
|
+
defined?
|
|
25
|
+
elsif
|
|
26
|
+
end
|
|
27
|
+
ensure
|
|
28
|
+
for
|
|
29
|
+
rescue
|
|
30
|
+
super
|
|
31
|
+
undef
|
|
32
|
+
unless
|
|
33
|
+
until
|
|
34
|
+
when
|
|
35
|
+
while
|
|
36
|
+
yield
|
|
37
|
+
)
|
|
38
|
+
|
|
10
39
|
def initialize(exception)
|
|
11
40
|
@method_name = exception.name
|
|
12
41
|
@receiver = exception.receiver
|
|
@@ -14,7 +43,7 @@ module DidYouMean
|
|
|
14
43
|
end
|
|
15
44
|
|
|
16
45
|
def corrections
|
|
17
|
-
@corrections ||= SpellChecker.new(dictionary: method_names).correct(method_name) - NAMES_TO_EXCLUDE[@receiver.class]
|
|
46
|
+
@corrections ||= SpellChecker.new(dictionary: RB_RESERVED_WORDS + method_names).correct(method_name) - NAMES_TO_EXCLUDE[@receiver.class]
|
|
18
47
|
end
|
|
19
48
|
|
|
20
49
|
def method_names
|
|
@@ -6,9 +6,61 @@ module DidYouMean
|
|
|
6
6
|
class VariableNameChecker
|
|
7
7
|
attr_reader :name, :method_names, :lvar_names, :ivar_names, :cvar_names
|
|
8
8
|
|
|
9
|
-
NAMES_TO_EXCLUDE = { 'foo' => [:fork] }
|
|
9
|
+
NAMES_TO_EXCLUDE = { 'foo' => [:fork, :for] }
|
|
10
10
|
NAMES_TO_EXCLUDE.default = []
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
# +VariableNameChecker::RB_RESERVED_WORDS+ is the list of all reserved
|
|
13
|
+
# words in Ruby. They could be declared like methods are, and a typo would
|
|
14
|
+
# cause Ruby to raise a +NameError+ because of the way they are declared.
|
|
15
|
+
#
|
|
16
|
+
# The +:VariableNameChecker+ will use this list to suggest a reversed word
|
|
17
|
+
# if a +NameError+ is raised and found closest matches, excluding:
|
|
18
|
+
#
|
|
19
|
+
# * +do+
|
|
20
|
+
# * +if+
|
|
21
|
+
# * +in+
|
|
22
|
+
# * +or+
|
|
23
|
+
#
|
|
24
|
+
# Also see +MethodNameChecker::RB_RESERVED_WORDS+.
|
|
25
|
+
RB_RESERVED_WORDS = %i(
|
|
26
|
+
BEGIN
|
|
27
|
+
END
|
|
28
|
+
alias
|
|
29
|
+
and
|
|
30
|
+
begin
|
|
31
|
+
break
|
|
32
|
+
case
|
|
33
|
+
class
|
|
34
|
+
def
|
|
35
|
+
defined?
|
|
36
|
+
else
|
|
37
|
+
elsif
|
|
38
|
+
end
|
|
39
|
+
ensure
|
|
40
|
+
false
|
|
41
|
+
for
|
|
42
|
+
module
|
|
43
|
+
next
|
|
44
|
+
nil
|
|
45
|
+
not
|
|
46
|
+
redo
|
|
47
|
+
rescue
|
|
48
|
+
retry
|
|
49
|
+
return
|
|
50
|
+
self
|
|
51
|
+
super
|
|
52
|
+
then
|
|
53
|
+
true
|
|
54
|
+
undef
|
|
55
|
+
unless
|
|
56
|
+
until
|
|
57
|
+
when
|
|
58
|
+
while
|
|
59
|
+
yield
|
|
60
|
+
__LINE__
|
|
61
|
+
__FILE__
|
|
62
|
+
__ENCODING__
|
|
63
|
+
)
|
|
12
64
|
|
|
13
65
|
def initialize(exception)
|
|
14
66
|
@name = exception.name.to_s.tr("@", "")
|
|
@@ -23,7 +75,7 @@ module DidYouMean
|
|
|
23
75
|
|
|
24
76
|
def corrections
|
|
25
77
|
@corrections ||= SpellChecker
|
|
26
|
-
.new(dictionary: (
|
|
78
|
+
.new(dictionary: (RB_RESERVED_WORDS + lvar_names + method_names + ivar_names + cvar_names))
|
|
27
79
|
.correct(name) - NAMES_TO_EXCLUDE[@name]
|
|
28
80
|
end
|
|
29
81
|
end
|
data/lib/did_you_mean/version.rb
CHANGED
|
@@ -49,11 +49,3 @@ class NameErrorExtensionTest < Minitest::Test
|
|
|
49
49
|
assert_equal "undefined method `sizee' for #<File:./tmp/.keep>", Marshal.load(Marshal.dump(error)).original_message
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
|
-
|
|
53
|
-
class DeprecatedIgnoreCallersTest < Minitest::Test
|
|
54
|
-
def test_ignore
|
|
55
|
-
assert_output nil, "IGNORED_CALLERS has been deprecated and has no effect.\n" do
|
|
56
|
-
DidYouMean::IGNORED_CALLERS << /( |`)do_not_correct_typo'/
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -116,4 +116,11 @@ class MethodNameCheckTest < Minitest::Test
|
|
|
116
116
|
|
|
117
117
|
assert_equal 1, error.to_s.scan(/Did you mean/).count
|
|
118
118
|
end
|
|
119
|
+
|
|
120
|
+
def test_suggests_yield
|
|
121
|
+
error = assert_raises(NoMethodError) { yeild(1) }
|
|
122
|
+
|
|
123
|
+
assert_correction :yield, error.corrections
|
|
124
|
+
assert_match "Did you mean? yield", error.to_s
|
|
125
|
+
end
|
|
119
126
|
end
|
|
@@ -69,7 +69,11 @@ class VariableNameCheckTest < Minitest::Test
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
nil_error = assert_raises(NameError) do
|
|
72
|
-
some_var =
|
|
72
|
+
some_var = nul
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
file_error = assert_raises(NameError) do
|
|
76
|
+
__FIEL__
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
assert_correction :false, false_error.corrections
|
|
@@ -80,6 +84,16 @@ class VariableNameCheckTest < Minitest::Test
|
|
|
80
84
|
|
|
81
85
|
assert_correction :nil, nil_error.corrections
|
|
82
86
|
assert_match "Did you mean? nil", nil_error.to_s
|
|
87
|
+
|
|
88
|
+
assert_correction :__FILE__, file_error.corrections
|
|
89
|
+
assert_match "Did you mean? __FILE__", file_error.to_s
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_suggests_yield
|
|
93
|
+
error = assert_raises(NameError) { yeild }
|
|
94
|
+
|
|
95
|
+
assert_correction :yield, error.corrections
|
|
96
|
+
assert_match "Did you mean? yield", error.to_s
|
|
83
97
|
end
|
|
84
98
|
|
|
85
99
|
def test_corrections_include_instance_variable_name
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: did_you_mean
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.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:
|
|
11
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -92,10 +92,8 @@ files:
|
|
|
92
92
|
- lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
|
|
93
93
|
- lib/did_you_mean/spell_checkers/null_checker.rb
|
|
94
94
|
- lib/did_you_mean/verbose.rb
|
|
95
|
-
- lib/did_you_mean/verbose_formatter.rb
|
|
96
95
|
- lib/did_you_mean/version.rb
|
|
97
96
|
- test/core_ext/name_error_extension_test.rb
|
|
98
|
-
- test/deprecated_formatter_test.rb
|
|
99
97
|
- test/edit_distance/jaro_winkler_test.rb
|
|
100
98
|
- test/experimental/initializer_name_correction_test.rb
|
|
101
99
|
- test/experimental/method_name_checker_test.rb
|
|
@@ -129,13 +127,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
129
127
|
version: '0'
|
|
130
128
|
requirements: []
|
|
131
129
|
rubyforge_project:
|
|
132
|
-
rubygems_version: 2.7.
|
|
130
|
+
rubygems_version: 2.7.4
|
|
133
131
|
signing_key:
|
|
134
132
|
specification_version: 4
|
|
135
133
|
summary: '"Did you mean?" experience in Ruby'
|
|
136
134
|
test_files:
|
|
137
135
|
- test/core_ext/name_error_extension_test.rb
|
|
138
|
-
- test/deprecated_formatter_test.rb
|
|
139
136
|
- test/edit_distance/jaro_winkler_test.rb
|
|
140
137
|
- test/experimental/initializer_name_correction_test.rb
|
|
141
138
|
- test/experimental/method_name_checker_test.rb
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
require 'did_you_mean'
|
|
2
|
-
require 'did_you_mean/formatters/verbose_formatter'
|
|
3
|
-
|
|
4
|
-
DidYouMean.formatter = DidYouMean::VerboseFormatter.new
|
|
5
|
-
|
|
6
|
-
warn '`require "did_you_mean/verbose_formatter"\' has been deprecated and will be removed' \
|
|
7
|
-
" in the next major Ruby version. Please require 'did_you_mean/verbose' instead."
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class DeprecatedFormatterTest < Minitest::Test
|
|
4
|
-
def test_deprecated_formatter
|
|
5
|
-
assert_output nil, /test\/deprecated_formatter_test.rb:6: warning: constant DidYouMean::Formatter is deprecated/ do
|
|
6
|
-
assert_equal "\nDid you mean? does_exist", ::DidYouMean::Formatter.new(['does_exist']).to_s
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|