did_you_mean 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +0 -1
- data/CHANGELOG.md +84 -27
- data/README.md +13 -13
- data/Rakefile +4 -15
- data/did_you_mean.gemspec +1 -1
- data/evaluation/incorrect_words.yaml +2 -0
- data/lib/did_you_mean.rb +37 -3
- data/lib/did_you_mean/core_ext/name_error.rb +4 -7
- data/lib/did_you_mean/experimental.rb +0 -15
- data/lib/did_you_mean/experimental/initializer_name_correction.rb +2 -0
- data/lib/did_you_mean/experimental/ivar_name_correction.rb +36 -9
- data/lib/did_you_mean/formatters/plain_formatter.rb +9 -0
- data/lib/did_you_mean/formatters/verbose_formatter.rb +13 -0
- data/lib/did_you_mean/spell_checkers/key_error_checker.rb +14 -0
- data/lib/did_you_mean/spell_checkers/method_name_checker.rb +2 -0
- data/lib/did_you_mean/spell_checkers/name_error_checkers.rb +2 -6
- data/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb +3 -5
- data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +4 -1
- data/lib/did_you_mean/verbose.rb +4 -0
- data/lib/did_you_mean/verbose_formatter.rb +5 -14
- data/lib/did_you_mean/version.rb +1 -1
- data/test/core_ext/name_error_extension_test.rb +5 -43
- data/test/edit_distance/jaro_winkler_test.rb +7 -0
- data/test/spell_checking/{class_name_test.rb → class_name_check_test.rb} +1 -13
- data/test/spell_checking/key_name_check_test.rb +44 -0
- data/test/spell_checking/{method_name_test.rb → method_name_check_test.rb} +1 -1
- data/test/spell_checking/{uncorrectable_name_test.rb → uncorrectable_name_check_test.rb} +1 -1
- data/test/spell_checking/{variable_name_test.rb → variable_name_check_test.rb} +26 -1
- data/test/verbose_formatter_test.rb +7 -1
- metadata +18 -19
- data/lib/did_you_mean/experimental/key_error_name_correction.rb +0 -32
- data/lib/did_you_mean/formatter.rb +0 -16
- data/test/experimental/key_error_test.rb +0 -15
- data/test/fixtures/book.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a0131dfb1348a1f49293ca29cbfa12eab5f896
|
4
|
+
data.tar.gz: 274dd39aacc7583c0877cb3313cd938390d11003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31fc5df24553e10482afff9bd425c055f4b0ffbf4d4267927979b3c314a589ff40e13b6597a1e22f5415a221a6e6e0853e0a608d6aab7dafd2b6f71551d23490
|
7
|
+
data.tar.gz: 5739306a3ddbed14ffe321a114ce5eda17513303d3e6d887da1978c781e694994addb383faf5c178bf46405fa49cc7e5630ad281b33caccdc66ba455eae297ff
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0-dev
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,64 @@
|
|
1
|
+
## [v1.1.2](https://github.com/yuki24/did_you_mean/tree/v1.1.2)
|
2
|
+
|
3
|
+
_<sup>released at 2017-09-24 07:28:48 UTC</sup>_
|
4
|
+
|
5
|
+
**This version is compatible with Ruby 2.4 and older**
|
6
|
+
|
7
|
+
#### Bug Fixes
|
8
|
+
|
9
|
+
- Fixed a bug where `did_you_mean` shows duplicate suggestions when the exception is raised multiple times ([#84](https://github.com/yuki24/did_you_mean/pull/84), [<tt>c2e4008</tt>](https://github.com/yuki24/did_you_mean/commit/c2e40083cef604c00ccd10efc6d7a5036ad9eb5b))
|
10
|
+
|
11
|
+
## [v1.1.1](https://github.com/yuki24/did_you_mean/tree/v1.1.1)
|
12
|
+
|
13
|
+
_<sup>released at 2017-09-24 07:24:02 UTC</sup>_
|
14
|
+
|
15
|
+
### This version has been yanked from Rubygems.org and is not available.
|
16
|
+
|
17
|
+
## [v1.1.0](https://github.com/yuki24/did_you_mean/tree/v1.1.0)
|
18
|
+
|
19
|
+
_<sup>released at 2016-12-19 23:19:06 UTC</sup>_
|
20
|
+
|
21
|
+
The version `1.1.0` only has support for Ruby 2.4.0 and later. Also, all patch releasess 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
|
+
|
23
|
+
#### New Features
|
24
|
+
|
25
|
+
- Suggest a method name on a NameError from the `Struct#[]` or `Struct#[]=` method ([#73](https://github.com/yuki24/did_you_mean/pull/73)):
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Struct.new(:foo).new[:fooo]
|
29
|
+
# => NameError: no member 'fooo' in struct
|
30
|
+
# Did you mean? foo
|
31
|
+
# foo=
|
32
|
+
```
|
33
|
+
|
34
|
+
- Added a public interface for the gem's spell checker:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
DidYouMean::SpellChecker.new(dictionary: ['email', 'fail', 'eval']).correct('meail')
|
38
|
+
# => ['email']
|
39
|
+
```
|
40
|
+
|
41
|
+
- Methods defined on `nil` by default are no longer suggested. Note that methods, defined after the gem is loaded, will still be suggested (e.g. ActiveSupport).
|
42
|
+
|
43
|
+
#### Bug Fixes
|
44
|
+
|
45
|
+
- Fixed a bug where private method names were added to the dictionary when an argument was passed in to a public method. Use the `NoMethodError#private_call?` method instead ([<tt>0a1b761</tt>](https://github.com/yuki24/did_you_mean/commit/0a1b7612252055e583a373b473932f789381ca0f))
|
46
|
+
|
47
|
+
## [v1.0.3](https://github.com/yuki24/did_you_mean/tree/v1.0.3)
|
48
|
+
|
49
|
+
_<sup>released at 2017-09-24 07:22:07 UTC</sup>_
|
50
|
+
|
51
|
+
**This version is compatible with Ruby 2.3 and older**
|
52
|
+
|
53
|
+
#### Bug Fixes
|
54
|
+
|
55
|
+
- Fixed a bug where `did_you_mean` shows duplicate suggestions when the exception is raised multiple times ([#84](https://github.com/yuki24/did_you_mean/pull/84), [<tt>c2e4008</tt>](https://github.com/yuki24/did_you_mean/commit/c2e40083cef604c00ccd10efc6d7a5036ad9eb5b))
|
56
|
+
|
1
57
|
## [v1.0.2](https://github.com/yuki24/did_you_mean/tree/v1.0.2)
|
2
58
|
|
3
|
-
_<sup>released
|
59
|
+
_<sup>released at 2016-11-20 18:03:07 UTC</sup>_
|
60
|
+
|
61
|
+
**This version is compatible with Ruby 2.3 and older**
|
4
62
|
|
5
63
|
#### Features
|
6
64
|
|
@@ -16,17 +74,16 @@ _<sup>released on 2016-06-20 18:03:07 UTC</sup>_
|
|
16
74
|
|
17
75
|
## [v1.0.1](https://github.com/yuki24/did_you_mean/tree/v1.0.1)
|
18
76
|
|
19
|
-
_<sup>released
|
77
|
+
_<sup>released at 2016-05-15 05:17:22 UTC</sup>_
|
20
78
|
|
21
79
|
#### Bug Fixes
|
22
80
|
|
23
81
|
- Fixed a bug where the gem suggests what is actually typed by the user: [<tt>1c52c88</tt>](https://github.com/yuki24/did_you_mean/commit/1c52c887c62b0921e799f94bcc4a846dc7cbc057)
|
24
82
|
- Fixed features that didn't work on JRuby 9.1.0.0: [<tt>dc48dde</tt>](https://github.com/yuki24/did_you_mean/commit/dc48dde1b2a8f05aab1fcf897e1cb3075a206f53), [<tt>4de23f8</tt>](https://github.com/yuki24/did_you_mean/commit/4de23f880502c80c5f321371d39c08bb0fa34040), [<tt>00e3059</tt>](https://github.com/yuki24/did_you_mean/commit/00e305971060d150fae4817b5e895d6478b37579). The local variable name correction is still disabled. Also see: [jruby/jruby#3480](https://github.com/jruby/jruby/issues/3480)
|
25
83
|
|
26
|
-
|
27
84
|
## [v1.0.0](https://github.com/yuki24/did_you_mean/tree/v1.0.0)
|
28
85
|
|
29
|
-
_<sup>released
|
86
|
+
_<sup>released at 2015-12-25 05:13:04 UTC</sup>_
|
30
87
|
|
31
88
|
#### Features
|
32
89
|
|
@@ -43,7 +100,7 @@ _<sup>released on 2015-12-25 05:13:04 UTC</sup>_
|
|
43
100
|
|
44
101
|
## [v1.0.0.rc1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.rc1)
|
45
102
|
|
46
|
-
_<sup>released
|
103
|
+
_<sup>released at 2015-12-25 05:02:25 UTC</sup>_
|
47
104
|
|
48
105
|
#### Internal Chagens
|
49
106
|
|
@@ -51,7 +108,7 @@ _<sup>released on 2015-12-25 05:02:25 UTC</sup>_
|
|
51
108
|
|
52
109
|
## [v1.0.0.beta3](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta3)
|
53
110
|
|
54
|
-
_<sup>released
|
111
|
+
_<sup>released at 2015-12-25 04:56:13 UTC</sup>_
|
55
112
|
|
56
113
|
#### Internal Changes
|
57
114
|
|
@@ -61,7 +118,7 @@ _<sup>released on 2015-12-25 04:56:13 UTC</sup>_
|
|
61
118
|
|
62
119
|
## [v1.0.0.beta2](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta2)
|
63
120
|
|
64
|
-
_<sup>released
|
121
|
+
_<sup>released at 2015-12-25 04:50:36 UTC</sup>_
|
65
122
|
|
66
123
|
#### Bug Fixes
|
67
124
|
|
@@ -69,7 +126,7 @@ _<sup>released on 2015-12-25 04:50:36 UTC</sup>_
|
|
69
126
|
|
70
127
|
## [v1.0.0.beta1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta1)
|
71
128
|
|
72
|
-
_<sup>released
|
129
|
+
_<sup>released at 2015-12-25 05:27:53 UTC</sup>_
|
73
130
|
|
74
131
|
#### Breaking Changes
|
75
132
|
|
@@ -83,7 +140,7 @@ _<sup>released on 2015-12-25 05:27:53 UTC</sup>_
|
|
83
140
|
|
84
141
|
## [v0.10.0](https://github.com/yuki24/did_you_mean/tree/v0.10.0)
|
85
142
|
|
86
|
-
_<sup>released
|
143
|
+
_<sup>released at 2015-08-21 06:44:11 UTC</sup>_
|
87
144
|
|
88
145
|
#### Features
|
89
146
|
|
@@ -108,7 +165,7 @@ _<sup>released on 2015-08-21 06:44:11 UTC</sup>_
|
|
108
165
|
|
109
166
|
## [v0.9.10](https://github.com/yuki24/did_you_mean/tree/v0.9.10)
|
110
167
|
|
111
|
-
_<sup>released
|
168
|
+
_<sup>released at 2015-05-14 03:04:47 UTC</sup>_
|
112
169
|
|
113
170
|
#### Bug Fixes
|
114
171
|
|
@@ -116,7 +173,7 @@ _<sup>released on 2015-05-14 03:04:47 UTC</sup>_
|
|
116
173
|
|
117
174
|
## [v0.9.9](https://github.com/yuki24/did_you_mean/tree/v0.9.9)
|
118
175
|
|
119
|
-
_<sup>released
|
176
|
+
_<sup>released at 2015-05-13 03:48:19 UTC</sup>_
|
120
177
|
|
121
178
|
#### Features
|
122
179
|
|
@@ -130,7 +187,7 @@ _<sup>released on 2015-05-13 03:48:19 UTC</sup>_
|
|
130
187
|
|
131
188
|
## [v0.9.8](https://github.com/yuki24/did_you_mean/tree/v0.9.8)
|
132
189
|
|
133
|
-
_<sup>released
|
190
|
+
_<sup>released at 2015-04-12 01:55:27 UTC</sup>_
|
134
191
|
|
135
192
|
#### Internal Changes
|
136
193
|
|
@@ -138,7 +195,7 @@ _<sup>released on 2015-04-12 01:55:27 UTC</sup>_
|
|
138
195
|
|
139
196
|
## [v0.9.7](https://github.com/yuki24/did_you_mean/tree/v0.9.7)
|
140
197
|
|
141
|
-
_<sup>released
|
198
|
+
_<sup>released at 2015-04-02 04:20:26 UTC</sup>_
|
142
199
|
|
143
200
|
#### Bug Fixes
|
144
201
|
|
@@ -146,7 +203,7 @@ _<sup>released on 2015-04-02 04:20:26 UTC</sup>_
|
|
146
203
|
|
147
204
|
## [v0.9.6](https://github.com/yuki24/did_you_mean/tree/v0.9.6)
|
148
205
|
|
149
|
-
_<sup>released
|
206
|
+
_<sup>released at 2015-01-24 23:19:27 UTC</sup>_
|
150
207
|
|
151
208
|
#### Bug Fixes
|
152
209
|
|
@@ -154,7 +211,7 @@ _<sup>released on 2015-01-24 23:19:27 UTC</sup>_
|
|
154
211
|
|
155
212
|
## [v0.9.5](https://github.com/yuki24/did_you_mean/tree/v0.9.5)
|
156
213
|
|
157
|
-
_<sup>released
|
214
|
+
_<sup>released at 2015-01-07 12:41:23 UTC</sup>_
|
158
215
|
|
159
216
|
#### Bug Fixes
|
160
217
|
|
@@ -162,7 +219,7 @@ _<sup>released on 2015-01-07 12:41:23 UTC</sup>_
|
|
162
219
|
|
163
220
|
## [v0.9.4](https://github.com/yuki24/did_you_mean/tree/v0.9.4)
|
164
221
|
|
165
|
-
_<sup>released
|
222
|
+
_<sup>released at 2014-11-19 20:00:00 UTC</sup>_
|
166
223
|
|
167
224
|
#### Bug Fixes
|
168
225
|
|
@@ -170,7 +227,7 @@ _<sup>released on 2014-11-19 20:00:00 UTC</sup>_
|
|
170
227
|
|
171
228
|
## [v0.9.3](https://github.com/yuki24/did_you_mean/tree/v0.9.3)
|
172
229
|
|
173
|
-
_<sup>released
|
230
|
+
_<sup>released at 2014-11-18 03:50:11 UTC</sup>_
|
174
231
|
|
175
232
|
**This version has been yanked from rubygems.org as it doesn't work with jRuby at all. Please upgrade to 0.9.4 or higher as soon as possible.**
|
176
233
|
|
@@ -180,7 +237,7 @@ _<sup>released on 2014-11-18 03:50:11 UTC</sup>_
|
|
180
237
|
|
181
238
|
## [v0.9.2](https://github.com/yuki24/did_you_mean/tree/v0.9.2)
|
182
239
|
|
183
|
-
_<sup>released
|
240
|
+
_<sup>released at 2014-11-17 15:32:33 UTC</sup>_
|
184
241
|
|
185
242
|
#### Bug Fixes
|
186
243
|
|
@@ -188,7 +245,7 @@ _<sup>released on 2014-11-17 15:32:33 UTC</sup>_
|
|
188
245
|
|
189
246
|
## [v0.9.1](https://github.com/yuki24/did_you_mean/tree/v0.9.1)
|
190
247
|
|
191
|
-
_<sup>released
|
248
|
+
_<sup>released at 2014-11-16 18:54:24 UTC</sup>_
|
192
249
|
|
193
250
|
**This version has been yanked from rubygems.org as it doesn't compile on Ruby 2.1.2 and 2.1.5. Please upgrade to 0.9.4 or higher as soon as possible.**
|
194
251
|
|
@@ -199,7 +256,7 @@ _<sup>released on 2014-11-16 18:54:24 UTC</sup>_
|
|
199
256
|
|
200
257
|
## [v0.9.0](https://github.com/yuki24/did_you_mean/tree/v0.9.0)
|
201
258
|
|
202
|
-
_<sup>released
|
259
|
+
_<sup>released at 2014-11-09 01:26:31 UTC</sup>_
|
203
260
|
|
204
261
|
#### Features
|
205
262
|
|
@@ -221,7 +278,7 @@ first_name, last_name = full_name.split(" ")
|
|
221
278
|
|
222
279
|
## [v0.8.0](https://github.com/yuki24/did_you_mean/tree/v0.8.0)
|
223
280
|
|
224
|
-
_<sup>released
|
281
|
+
_<sup>released at 2014-10-27 02:03:13 UTC</sup>_
|
225
282
|
|
226
283
|
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
227
284
|
|
@@ -237,7 +294,7 @@ _<sup>released on 2014-10-27 02:03:13 UTC</sup>_
|
|
237
294
|
|
238
295
|
## [v0.7.0](https://github.com/yuki24/did_you_mean/tree/v0.7.0)
|
239
296
|
|
240
|
-
_<sup>released
|
297
|
+
_<sup>released at 2014-09-26 03:37:18 UTC</sup>_
|
241
298
|
|
242
299
|
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
243
300
|
|
@@ -255,7 +312,7 @@ _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
|
|
255
312
|
|
256
313
|
## [v0.6.0](https://github.com/yuki24/did_you_mean/tree/v0.6.0)
|
257
314
|
|
258
|
-
_<sup>released
|
315
|
+
_<sup>released at 2014-05-18 00:23:24 UTC</sup>_
|
259
316
|
|
260
317
|
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
261
318
|
|
@@ -277,7 +334,7 @@ _<sup>released on 2014-05-18 00:23:24 UTC</sup>_
|
|
277
334
|
|
278
335
|
## [v0.5.0](https://github.com/yuki24/did_you_mean/tree/v0.5.0)
|
279
336
|
|
280
|
-
_<sup>released
|
337
|
+
_<sup>released at 2014-05-10 17:59:54 UTC</sup>_
|
281
338
|
|
282
339
|
#### Features
|
283
340
|
|
@@ -285,7 +342,7 @@ _<sup>released on 2014-05-10 17:59:54 UTC</sup>_
|
|
285
342
|
|
286
343
|
## [v0.4.0](https://github.com/yuki24/did_you_mean/tree/v0.4.0)
|
287
344
|
|
288
|
-
_<sup>released
|
345
|
+
_<sup>released at 2014-04-20 02:10:31 UTC</sup>_
|
289
346
|
|
290
347
|
#### Features
|
291
348
|
|
@@ -305,7 +362,7 @@ User.new(flrst_name: "wrong flrst name")
|
|
305
362
|
|
306
363
|
## [v0.3.1](https://github.com/yuki24/did_you_mean/tree/v0.3.1)
|
307
364
|
|
308
|
-
_<sup>released
|
365
|
+
_<sup>released at 2014-03-20 23:16:20 UTC</sup>_
|
309
366
|
|
310
367
|
#### Features
|
311
368
|
|
@@ -314,7 +371,7 @@ _<sup>released on 2014-03-20 23:16:20 UTC</sup>_
|
|
314
371
|
|
315
372
|
## [v0.3.0](https://github.com/yuki24/did_you_mean/tree/v0.3.0)
|
316
373
|
|
317
|
-
_<sup>released
|
374
|
+
_<sup>released at 2014-03-20 23:13:13 UTC</sup>_
|
318
375
|
|
319
376
|
#### Features
|
320
377
|
|
data/README.md
CHANGED
@@ -52,13 +52,22 @@ full_name.starts_with?("Y")
|
|
52
52
|
# Did you mean? start_with?
|
53
53
|
```
|
54
54
|
|
55
|
+
### KeyError
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
hash = {foo: 1, bar: 2, baz: 3}
|
59
|
+
hash.fetch(:fooo)
|
60
|
+
# => KeyError: key not found: :fooo
|
61
|
+
# Did you mean? :foo
|
62
|
+
```
|
63
|
+
|
55
64
|
## Experimental Features
|
56
65
|
|
57
66
|
Aside from the basic features above, the `did_you_mean` gem comes with experimental features. They can be enabled by calling `require 'did_you_mean/experimental'`.
|
58
67
|
|
59
|
-
|
68
|
+
Note that **these experimental features should never be enabled in production as they would impact Ruby's performance and use some unstable Ruby APIs.**
|
60
69
|
|
61
|
-
### Correcting an Instance Variable When It's Incorrectly
|
70
|
+
### Correcting an Instance Variable When It's Incorrectly Spelled
|
62
71
|
|
63
72
|
```ruby
|
64
73
|
require 'did_you_mean/experimental'
|
@@ -69,16 +78,7 @@ require 'did_you_mean/experimental'
|
|
69
78
|
# Did you mean? @full_name
|
70
79
|
```
|
71
80
|
|
72
|
-
###
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
hash = {foo: 1, bar: 2, baz: 3}
|
76
|
-
hash.fetch(:fooo)
|
77
|
-
# KeyError: key not found: :fooo
|
78
|
-
# Did you mean? :foo
|
79
|
-
```
|
80
|
-
|
81
|
-
### Displaying a Warning When `initialize` is Incorrectly Typed
|
81
|
+
### Displaying a Warning When `initialize` is Incorrectly Spelled
|
82
82
|
|
83
83
|
```ruby
|
84
84
|
require 'did_you_mean/experimental'
|
@@ -100,7 +100,7 @@ OBject
|
|
100
100
|
# => NameError: uninitialized constant OBject
|
101
101
|
# Did you mean? Object
|
102
102
|
|
103
|
-
require 'did_you_mean/
|
103
|
+
require 'did_you_mean/verbose'
|
104
104
|
OBject
|
105
105
|
# => NameError: uninitialized constant OBject
|
106
106
|
#
|
data/Rakefile
CHANGED
@@ -4,20 +4,9 @@ require 'rake/testtask'
|
|
4
4
|
Rake::TestTask.new do |task|
|
5
5
|
task.libs << "test"
|
6
6
|
|
7
|
-
task.test_files = Dir['test/**/*_test.rb'].reject
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
task.verbose = true
|
12
|
-
task.warning = true
|
13
|
-
end
|
14
|
-
|
15
|
-
Rake::TestTask.new("test:verbose_formatter") do |task|
|
16
|
-
task.libs << "test"
|
17
|
-
task.pattern = 'test/verbose_formatter_test.rb'
|
18
|
-
task.verbose = true
|
19
|
-
task.warning = true
|
20
|
-
task.ruby_opts << "-rdid_you_mean/verbose_formatter"
|
7
|
+
task.test_files = Dir['test/**/*_test.rb'].reject {|path| /(experimental)/ =~ path }
|
8
|
+
task.verbose = true
|
9
|
+
task.warning = true
|
21
10
|
end
|
22
11
|
|
23
12
|
Rake::TestTask.new("test:experimental") do |task|
|
@@ -28,7 +17,7 @@ Rake::TestTask.new("test:experimental") do |task|
|
|
28
17
|
task.ruby_opts << "-rdid_you_mean/experimental"
|
29
18
|
end
|
30
19
|
|
31
|
-
task default: %i(test test:
|
20
|
+
task default: %i(test test:experimental)
|
32
21
|
|
33
22
|
namespace :test do
|
34
23
|
namespace :accuracy do
|
data/did_you_mean.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = '>= 2.
|
20
|
+
spec.required_ruby_version = '>= 2.5.0dev'
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler"
|
23
23
|
spec.add_development_dependency "rake"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# This data is based on Birkbeck Spelling Error Corpus: http://ota.ox.ac.uk/headers/0643.xml
|
2
2
|
# More specifically, this is a yaml version of the data in FAWTHROP1DAT.643 and FAWTHROP2DAT.643.
|
3
|
+
# released under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
4
|
+
# https://creativecommons.org/licenses/by-nc-sa/3.0/
|
3
5
|
---
|
4
6
|
abattoir: abbatoir
|
5
7
|
abhorrence: abhorence
|
data/lib/did_you_mean.rb
CHANGED
@@ -4,16 +4,50 @@ require "did_you_mean/core_ext/name_error"
|
|
4
4
|
require "did_you_mean/spell_checker"
|
5
5
|
require 'did_you_mean/spell_checkers/name_error_checkers'
|
6
6
|
require 'did_you_mean/spell_checkers/method_name_checker'
|
7
|
+
require 'did_you_mean/spell_checkers/key_error_checker'
|
7
8
|
require 'did_you_mean/spell_checkers/null_checker'
|
8
9
|
|
9
|
-
require "did_you_mean/
|
10
|
+
require "did_you_mean/formatters/plain_formatter"
|
10
11
|
|
11
12
|
module DidYouMean
|
12
|
-
|
13
|
+
class DeprecatedIgnoredCallers < Array
|
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
|
13
33
|
|
14
34
|
SPELL_CHECKERS = Hash.new(NullChecker)
|
15
35
|
SPELL_CHECKERS.merge!({
|
16
36
|
"NameError" => NameErrorCheckers,
|
17
|
-
"NoMethodError" => MethodNameChecker
|
37
|
+
"NoMethodError" => MethodNameChecker,
|
38
|
+
"KeyError" => KeyErrorChecker
|
18
39
|
})
|
40
|
+
|
41
|
+
NameError.prepend DidYouMean::Correctable
|
42
|
+
KeyError.prepend DidYouMean::Correctable
|
43
|
+
|
44
|
+
def self.formatter
|
45
|
+
@@formatter
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.formatter=(formatter)
|
49
|
+
@@formatter = formatter
|
50
|
+
end
|
51
|
+
|
52
|
+
self.formatter = PlainFormatter.new
|
19
53
|
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
module DidYouMean
|
2
2
|
module Correctable
|
3
|
-
prepend_features NameError
|
4
|
-
|
5
3
|
def original_message
|
6
4
|
method(:to_s).super_method.call
|
7
5
|
end
|
8
6
|
|
9
7
|
def to_s
|
10
8
|
msg = super.dup
|
11
|
-
bt = caller(1, 6)
|
12
9
|
|
13
|
-
if
|
14
|
-
msg <<
|
10
|
+
if !cause.respond_to?(:corrections) || cause.corrections.empty?
|
11
|
+
msg << DidYouMean.formatter.message_for(corrections)
|
15
12
|
end
|
16
13
|
|
17
14
|
msg
|
@@ -20,11 +17,11 @@ module DidYouMean
|
|
20
17
|
end
|
21
18
|
|
22
19
|
def corrections
|
23
|
-
|
20
|
+
spell_checker.corrections
|
24
21
|
end
|
25
22
|
|
26
23
|
def spell_checker
|
27
|
-
SPELL_CHECKERS[self.class.to_s].new(self)
|
24
|
+
@spell_checker ||= SPELL_CHECKERS[self.class.to_s].new(self)
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
@@ -1,17 +1,2 @@
|
|
1
|
-
require 'did_you_mean'
|
2
|
-
|
3
|
-
module DidYouMean
|
4
|
-
TRACE = TracePoint.trace(:raise) do |tp|
|
5
|
-
e = tp.raised_exception
|
6
|
-
|
7
|
-
if SPELL_CHECKERS.include?(e.class.to_s) && !e.instance_variable_defined?(:@frame_binding)
|
8
|
-
e.instance_variable_set(:@frame_binding, tp.binding)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
NameError.send(:attr, :frame_binding)
|
13
|
-
end
|
14
|
-
|
15
1
|
require 'did_you_mean/experimental/initializer_name_correction'
|
16
2
|
require 'did_you_mean/experimental/ivar_name_correction'
|
17
|
-
require 'did_you_mean/experimental/key_error_name_correction'
|
@@ -1,19 +1,45 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require 'did_you_mean'
|
4
|
+
|
1
5
|
module DidYouMean
|
2
|
-
module Experimental
|
3
|
-
|
6
|
+
module Experimental #:nodoc:
|
7
|
+
class IvarNameCheckerBuilder #:nodoc:
|
8
|
+
attr_reader :original_checker
|
9
|
+
|
10
|
+
def initialize(original_checker) #:nodoc:
|
11
|
+
@original_checker = original_checker
|
12
|
+
end
|
13
|
+
|
14
|
+
def new(no_method_error) #:nodoc:
|
15
|
+
IvarNameChecker.new(no_method_error, original_checker: @original_checker)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class IvarNameChecker #:nodoc:
|
4
20
|
REPLS = {
|
5
21
|
"(irb)" => -> { Readline::HISTORY.to_a.last }
|
6
22
|
}
|
7
23
|
|
8
|
-
|
9
|
-
|
24
|
+
TRACE = TracePoint.trace(:raise) do |tp|
|
25
|
+
e = tp.raised_exception
|
26
|
+
|
27
|
+
if SPELL_CHECKERS.include?(e.class.to_s) && !e.instance_variable_defined?(:@frame_binding)
|
28
|
+
e.instance_variable_set(:@frame_binding, tp.binding)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :original_checker
|
33
|
+
|
34
|
+
def initialize(no_method_error, original_checker: )
|
35
|
+
@original_checker = original_checker.new(no_method_error)
|
10
36
|
|
11
37
|
@location = no_method_error.backtrace_locations.first
|
12
38
|
@ivar_names = no_method_error.frame_binding.receiver.instance_variables
|
13
39
|
end
|
14
40
|
|
15
41
|
def corrections
|
16
|
-
|
42
|
+
original_checker.corrections + ivar_name_corrections
|
17
43
|
end
|
18
44
|
|
19
45
|
def ivar_name_corrections
|
@@ -23,12 +49,12 @@ module DidYouMean
|
|
23
49
|
private
|
24
50
|
|
25
51
|
def receiver_name
|
26
|
-
return unless receiver.nil?
|
52
|
+
return unless @original_checker.receiver.nil?
|
27
53
|
|
28
54
|
abs_path = @location.absolute_path
|
29
55
|
lineno = @location.lineno
|
30
56
|
|
31
|
-
/@(\w+)*\.#{method_name}/ =~ line(abs_path, lineno).to_s && $1
|
57
|
+
/@(\w+)*\.#{@original_checker.method_name}/ =~ line(abs_path, lineno).to_s && $1
|
32
58
|
end
|
33
59
|
|
34
60
|
def line(abs_path, lineno)
|
@@ -41,7 +67,8 @@ module DidYouMean
|
|
41
67
|
end
|
42
68
|
end
|
43
69
|
end
|
44
|
-
|
45
|
-
SPELL_CHECKERS['NoMethodError'].prepend(IvarNameCorrection)
|
46
70
|
end
|
71
|
+
|
72
|
+
NameError.send(:attr, :frame_binding)
|
73
|
+
SPELL_CHECKERS['NoMethodError'] = Experimental::IvarNameCheckerBuilder.new(SPELL_CHECKERS['NoMethodError'])
|
47
74
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module DidYouMean
|
4
|
+
class VerboseFormatter
|
5
|
+
def message_for(corrections)
|
6
|
+
return "" if corrections.empty?
|
7
|
+
|
8
|
+
output = "\n\n Did you mean? ".dup
|
9
|
+
output << corrections.join("\n ")
|
10
|
+
output << "\n "
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "did_you_mean/spell_checker"
|
2
|
+
|
3
|
+
module DidYouMean
|
4
|
+
class KeyErrorChecker
|
5
|
+
def initialize(key_error)
|
6
|
+
@key = key_error.key
|
7
|
+
@keys = key_error.receiver.keys
|
8
|
+
end
|
9
|
+
|
10
|
+
def corrections
|
11
|
+
@corrections ||= SpellChecker.new(dictionary: @keys).correct(@key).map(&:inspect)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,12 +2,8 @@ require 'did_you_mean/spell_checkers/name_error_checkers/class_name_checker'
|
|
2
2
|
require 'did_you_mean/spell_checkers/name_error_checkers/variable_name_checker'
|
3
3
|
|
4
4
|
module DidYouMean
|
5
|
-
|
6
|
-
def
|
7
|
-
raise "Do not include this module since it overrides Class.new method."
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.new(exception)
|
5
|
+
class << (NameErrorCheckers = Object.new)
|
6
|
+
def new(exception)
|
11
7
|
case exception.original_message
|
12
8
|
when /uninitialized constant/
|
13
9
|
ClassNameChecker
|
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
require 'delegate'
|
3
|
+
require "did_you_mean/spell_checker"
|
3
4
|
|
4
5
|
module DidYouMean
|
5
6
|
class ClassNameChecker
|
6
7
|
attr_reader :class_name
|
7
8
|
|
8
9
|
def initialize(exception)
|
9
|
-
@class_name, @receiver
|
10
|
+
@class_name, @receiver = exception.name, exception.receiver
|
10
11
|
end
|
11
12
|
|
12
13
|
def corrections
|
13
|
-
@corrections ||= SpellChecker.new(dictionary: class_names)
|
14
|
-
.correct(class_name)
|
15
|
-
.map(&:full_name)
|
16
|
-
.reject {|qualified_name| @original_message.include?(qualified_name) }
|
14
|
+
@corrections ||= SpellChecker.new(dictionary: class_names).correct(class_name).map(&:full_name)
|
17
15
|
end
|
18
16
|
|
19
17
|
def class_names
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
+
require "did_you_mean/spell_checker"
|
4
|
+
|
3
5
|
module DidYouMean
|
4
6
|
class VariableNameChecker
|
5
7
|
attr_reader :name, :method_names, :lvar_names, :ivar_names, :cvar_names
|
6
8
|
|
7
9
|
NAMES_TO_EXCLUDE = { 'foo' => [:fork] }
|
8
10
|
NAMES_TO_EXCLUDE.default = []
|
11
|
+
RB_PREDEFINED_OBJECTS = [:false, :true, :nil]
|
9
12
|
|
10
13
|
def initialize(exception)
|
11
14
|
@name = exception.name.to_s.tr("@", "")
|
@@ -20,7 +23,7 @@ module DidYouMean
|
|
20
23
|
|
21
24
|
def corrections
|
22
25
|
@corrections ||= SpellChecker
|
23
|
-
.new(dictionary: (lvar_names + method_names + ivar_names + cvar_names))
|
26
|
+
.new(dictionary: (RB_PREDEFINED_OBJECTS + lvar_names + method_names + ivar_names + cvar_names))
|
24
27
|
.correct(name) - NAMES_TO_EXCLUDE[@name]
|
25
28
|
end
|
26
29
|
end
|
@@ -1,16 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'did_you_mean/
|
1
|
+
require 'did_you_mean'
|
2
|
+
require 'did_you_mean/formatters/verbose_formatter'
|
3
3
|
|
4
|
-
|
5
|
-
module VerboseFormatter
|
6
|
-
prepend_features DidYouMean::Formatter
|
4
|
+
DidYouMean.formatter = DidYouMean::VerboseFormatter.new
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
output = "\n\n Did you mean? ".dup
|
12
|
-
output << @corrections.join("\n ")
|
13
|
-
output << "\n "
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
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."
|
data/lib/did_you_mean/version.rb
CHANGED
@@ -20,7 +20,7 @@ class NameErrorExtensionTest < Minitest::Test
|
|
20
20
|
|
21
21
|
def test_message
|
22
22
|
message = <<~MESSAGE.chomp
|
23
|
-
undefined local variable or method `doesnt_exist' for #{to_s}
|
23
|
+
undefined local variable or method `doesnt_exist' for #{method(:to_s).super_method.call}
|
24
24
|
Did you mean? does_exist
|
25
25
|
MESSAGE
|
26
26
|
|
@@ -36,50 +36,12 @@ class NameErrorExtensionTest < Minitest::Test
|
|
36
36
|
error.to_s
|
37
37
|
assert_equal 1, error.to_s.scan("Did you mean?").count
|
38
38
|
end
|
39
|
-
|
40
|
-
def test_correctable_error_objects_are_dumpable
|
41
|
-
error = begin
|
42
|
-
File.open('./tmp/.keep').sizee
|
43
|
-
rescue NoMethodError => e
|
44
|
-
e
|
45
|
-
end
|
46
|
-
|
47
|
-
error.to_s
|
48
|
-
|
49
|
-
assert_equal "undefined method `sizee' for #<File:./tmp/.keep>", Marshal.load(Marshal.dump(error)).original_message
|
50
|
-
end
|
51
39
|
end
|
52
40
|
|
53
|
-
class
|
54
|
-
SPELL_CHECKERS = DidYouMean::SPELL_CHECKERS
|
55
|
-
|
56
|
-
class Boomer
|
57
|
-
def initialize(*)
|
58
|
-
raise Exception, "spell checker was created when it shouldn't!"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def setup
|
63
|
-
@org, SPELL_CHECKERS['NameError'] = SPELL_CHECKERS['NameError'], Boomer
|
64
|
-
DidYouMean::IGNORED_CALLERS << /( |`)do_not_correct_typo'/
|
65
|
-
|
66
|
-
@error = assert_raises(NameError){ doesnt_exist }
|
67
|
-
end
|
68
|
-
|
69
|
-
def teardown
|
70
|
-
SPELL_CHECKERS['NameError'] = @org
|
71
|
-
DidYouMean::IGNORED_CALLERS.clear
|
72
|
-
end
|
73
|
-
|
41
|
+
class DeprecatedIgnoreCallersTest < Minitest::Test
|
74
42
|
def test_ignore
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def do_not_correct_typo; @error.message end
|
81
|
-
|
82
|
-
def assert_nothing_raised
|
83
|
-
yield
|
43
|
+
assert_output nil, "IGNORED_CALLERS has been deprecated and has no effect.\n" do
|
44
|
+
DidYouMean::IGNORED_CALLERS << /( |`)do_not_correct_typo'/
|
45
|
+
end
|
84
46
|
end
|
85
47
|
end
|
@@ -1,5 +1,12 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'test_helper'
|
2
3
|
|
4
|
+
# These tests were originally written by Jian Weihang (簡煒航) as part of his work
|
5
|
+
# on the jaro_winkler gem. The original code could be found here:
|
6
|
+
# https://github.com/tonytonyjan/jaro_winkler/blob/9bd12421/spec/jaro_winkler_spec.rb
|
7
|
+
#
|
8
|
+
# Copyright (c) 2014 Jian Weihang
|
9
|
+
|
3
10
|
class JaroWinklerTest < Minitest::Test
|
4
11
|
def test_jaro_winkler_distance
|
5
12
|
assert_distance 0.9667, 'henka', 'henkan'
|
@@ -27,7 +27,7 @@ class Book
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
class
|
30
|
+
class ClassNameCheckTest < Minitest::Test
|
31
31
|
def test_corrections
|
32
32
|
error = assert_raises(NameError) { ::Bo0k }
|
33
33
|
assert_correction "Book", error.corrections
|
@@ -62,16 +62,4 @@ class ClassNameTest < Minitest::Test
|
|
62
62
|
error = assert_raises(NameError) { ::Book::Page.new.tableof_contents }
|
63
63
|
assert_correction "Book::TableOfContents", error.corrections
|
64
64
|
end
|
65
|
-
|
66
|
-
def test_does_not_suggest_user_input
|
67
|
-
error = assert_raises(NameError) { ::Book::Cover }
|
68
|
-
|
69
|
-
# This is a weird require, but in a multi-threaded condition, a constant may
|
70
|
-
# be loaded between when a NameError occurred and when the spell checker
|
71
|
-
# attemps to find a possible suggestion. The manual require here simulates
|
72
|
-
# a race condition a single test.
|
73
|
-
require_relative '../fixtures/book'
|
74
|
-
|
75
|
-
assert_empty error.corrections
|
76
|
-
end
|
77
65
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class KeyNameCheckTest < Minitest::Test
|
4
|
+
def test_corrects_hash_key_name_with_fetch
|
5
|
+
hash = { "foo" => 1, bar: 2 }
|
6
|
+
|
7
|
+
error = assert_raises(KeyError) { hash.fetch(:bax) }
|
8
|
+
assert_correction ":bar", error.corrections
|
9
|
+
assert_match "Did you mean? :bar", error.to_s
|
10
|
+
|
11
|
+
error = assert_raises(KeyError) { hash.fetch("fooo") }
|
12
|
+
assert_correction %("foo"), error.corrections
|
13
|
+
assert_match %(Did you mean? "foo"), error.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_corrects_hash_key_name_with_fetch_values
|
17
|
+
hash = { "foo" => 1, bar: 2 }
|
18
|
+
|
19
|
+
error = assert_raises(KeyError) { hash.fetch_values("foo", :bar, :bax) }
|
20
|
+
assert_correction ":bar", error.corrections
|
21
|
+
assert_match "Did you mean? :bar", error.to_s
|
22
|
+
|
23
|
+
error = assert_raises(KeyError) { hash.fetch_values("foo", :bar, "fooo") }
|
24
|
+
assert_correction %("foo"), error.corrections
|
25
|
+
assert_match %(Did you mean? "foo"), error.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_corrects_sprintf_key_name
|
29
|
+
error = assert_raises(KeyError) { sprintf("%<foo>d", {fooo: 1}) }
|
30
|
+
assert_correction ":fooo", error.corrections
|
31
|
+
assert_match "Did you mean? :fooo", error.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_corrects_env_key_name
|
35
|
+
ENV["FOO"] = "1"
|
36
|
+
ENV["BAR"] = "2"
|
37
|
+
error = assert_raises(KeyError) { ENV.fetch("BAX") }
|
38
|
+
assert_correction %("BAR"), error.corrections
|
39
|
+
assert_match %(Did you mean? "BAR"), error.to_s
|
40
|
+
ensure
|
41
|
+
ENV.delete("FOO")
|
42
|
+
ENV.delete("BAR")
|
43
|
+
end
|
44
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class VariableNameCheckTest < Minitest::Test
|
4
4
|
class User
|
5
5
|
def initialize
|
6
6
|
@email_address = 'email_address@address.net'
|
@@ -57,6 +57,31 @@ class VariableNameTest < Minitest::Test
|
|
57
57
|
assert_match "Did you mean? person", error.to_s
|
58
58
|
end
|
59
59
|
|
60
|
+
def test_corrections_include_ruby_predefined_objects
|
61
|
+
some_var = nil
|
62
|
+
|
63
|
+
false_error = assert_raises(NameError) do
|
64
|
+
some_var = fals
|
65
|
+
end
|
66
|
+
|
67
|
+
true_error = assert_raises(NameError) do
|
68
|
+
some_var = treu
|
69
|
+
end
|
70
|
+
|
71
|
+
nil_error = assert_raises(NameError) do
|
72
|
+
some_var = nol
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_correction :false, false_error.corrections
|
76
|
+
assert_match "Did you mean? false", false_error.to_s
|
77
|
+
|
78
|
+
assert_correction :true, true_error.corrections
|
79
|
+
assert_match "Did you mean? true", true_error.to_s
|
80
|
+
|
81
|
+
assert_correction :nil, nil_error.corrections
|
82
|
+
assert_match "Did you mean? nil", nil_error.to_s
|
83
|
+
end
|
84
|
+
|
60
85
|
def test_corrections_include_instance_variable_name
|
61
86
|
error = assert_raises(NameError){ @user.to_s }
|
62
87
|
|
@@ -2,13 +2,19 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class VerboseFormatterTest < Minitest::Test
|
4
4
|
def setup
|
5
|
+
require 'did_you_mean/verbose'
|
6
|
+
|
5
7
|
does_exist = does_exist = nil
|
6
8
|
@error = assert_raises(NameError){ doesnt_exist }
|
7
9
|
end
|
8
10
|
|
11
|
+
def teardown
|
12
|
+
DidYouMean.formatter = DidYouMean::PlainFormatter.new
|
13
|
+
end
|
14
|
+
|
9
15
|
def test_message
|
10
16
|
assert_equal <<~MESSAGE.chomp, @error.message
|
11
|
-
undefined local variable or method `doesnt_exist' for #{to_s}
|
17
|
+
undefined local variable or method `doesnt_exist' for #{method(:to_s).super_method.call}
|
12
18
|
|
13
19
|
Did you mean? does_exist
|
14
20
|
|
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.2.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: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,32 +83,32 @@ files:
|
|
83
83
|
- lib/did_you_mean/experimental.rb
|
84
84
|
- lib/did_you_mean/experimental/initializer_name_correction.rb
|
85
85
|
- lib/did_you_mean/experimental/ivar_name_correction.rb
|
86
|
-
- lib/did_you_mean/
|
87
|
-
- lib/did_you_mean/
|
86
|
+
- lib/did_you_mean/formatters/plain_formatter.rb
|
87
|
+
- lib/did_you_mean/formatters/verbose_formatter.rb
|
88
88
|
- lib/did_you_mean/jaro_winkler.rb
|
89
89
|
- lib/did_you_mean/levenshtein.rb
|
90
90
|
- lib/did_you_mean/spell_checker.rb
|
91
|
+
- lib/did_you_mean/spell_checkers/key_error_checker.rb
|
91
92
|
- lib/did_you_mean/spell_checkers/method_name_checker.rb
|
92
93
|
- lib/did_you_mean/spell_checkers/name_error_checkers.rb
|
93
94
|
- lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
|
94
95
|
- lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
|
95
96
|
- lib/did_you_mean/spell_checkers/null_checker.rb
|
97
|
+
- lib/did_you_mean/verbose.rb
|
96
98
|
- lib/did_you_mean/verbose_formatter.rb
|
97
99
|
- lib/did_you_mean/version.rb
|
98
100
|
- test/core_ext/name_error_extension_test.rb
|
99
101
|
- test/edit_distance/jaro_winkler_test.rb
|
100
102
|
- test/experimental/initializer_name_correction_test.rb
|
101
|
-
- test/experimental/key_error_test.rb
|
102
103
|
- test/experimental/method_name_checker_test.rb
|
103
|
-
- test/fixtures/book.rb
|
104
104
|
- test/spell_checker_test.rb
|
105
|
-
- test/spell_checking/
|
106
|
-
- test/spell_checking/
|
107
|
-
- test/spell_checking/
|
108
|
-
- test/spell_checking/
|
105
|
+
- test/spell_checking/class_name_check_test.rb
|
106
|
+
- test/spell_checking/key_name_check_test.rb
|
107
|
+
- test/spell_checking/method_name_check_test.rb
|
108
|
+
- test/spell_checking/uncorrectable_name_check_test.rb
|
109
|
+
- test/spell_checking/variable_name_check_test.rb
|
109
110
|
- test/test_helper.rb
|
110
111
|
- test/verbose_formatter_test.rb
|
111
|
-
- tmp/.keep
|
112
112
|
homepage: https://github.com/yuki24/did_you_mean
|
113
113
|
licenses:
|
114
114
|
- MIT
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
124
|
+
version: 2.5.0dev
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.6.
|
132
|
+
rubygems_version: 2.6.13
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: '"Did you mean?" experience in Ruby'
|
@@ -137,13 +137,12 @@ test_files:
|
|
137
137
|
- test/core_ext/name_error_extension_test.rb
|
138
138
|
- test/edit_distance/jaro_winkler_test.rb
|
139
139
|
- test/experimental/initializer_name_correction_test.rb
|
140
|
-
- test/experimental/key_error_test.rb
|
141
140
|
- test/experimental/method_name_checker_test.rb
|
142
|
-
- test/fixtures/book.rb
|
143
141
|
- test/spell_checker_test.rb
|
144
|
-
- test/spell_checking/
|
145
|
-
- test/spell_checking/
|
146
|
-
- test/spell_checking/
|
147
|
-
- test/spell_checking/
|
142
|
+
- test/spell_checking/class_name_check_test.rb
|
143
|
+
- test/spell_checking/key_name_check_test.rb
|
144
|
+
- test/spell_checking/method_name_check_test.rb
|
145
|
+
- test/spell_checking/uncorrectable_name_check_test.rb
|
146
|
+
- test/spell_checking/variable_name_check_test.rb
|
148
147
|
- test/test_helper.rb
|
149
148
|
- test/verbose_formatter_test.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module DidYouMean
|
2
|
-
module Experimental
|
3
|
-
module KeyErrorWithNameAndKeys
|
4
|
-
FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}"
|
5
|
-
|
6
|
-
def fetch(name, *)
|
7
|
-
super
|
8
|
-
rescue KeyError => e
|
9
|
-
e.instance_variable_set(:@name, name)
|
10
|
-
e.instance_variable_set(:@keys, keys)
|
11
|
-
$@.delete_if { |s| FILE_REGEXP =~ s } if $@
|
12
|
-
|
13
|
-
raise e
|
14
|
-
end
|
15
|
-
end
|
16
|
-
Hash.prepend KeyErrorWithNameAndKeys
|
17
|
-
|
18
|
-
class KeyNameChecker
|
19
|
-
def initialize(key_error)
|
20
|
-
@name = key_error.instance_variable_get(:@name)
|
21
|
-
@keys = key_error.instance_variable_get(:@keys)
|
22
|
-
end
|
23
|
-
|
24
|
-
def corrections
|
25
|
-
@corrections ||= SpellChecker.new(dictionary: @keys).correct(@name).map(&:inspect)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
SPELL_CHECKERS["KeyError"] = KeyNameChecker
|
30
|
-
KeyError.prepend DidYouMean::Correctable
|
31
|
-
end
|
32
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
module DidYouMean
|
4
|
-
class Formatter
|
5
|
-
def initialize(corrections = [])
|
6
|
-
@corrections = corrections
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
return "" if @corrections.empty?
|
11
|
-
|
12
|
-
output = "\nDid you mean? ".dup
|
13
|
-
output << @corrections.join("\n ")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ExperimentalKeyErrorNameCorrectionTest < Minitest::Test
|
4
|
-
def test_corrects_hash_key_name
|
5
|
-
hash = { "foo" => 1, bar: 2 }
|
6
|
-
|
7
|
-
error = assert_raises(KeyError) { hash.fetch(:bax) }
|
8
|
-
assert_correction ":bar", error.corrections
|
9
|
-
assert_match "Did you mean? :bar", error.to_s
|
10
|
-
|
11
|
-
error = assert_raises(KeyError) { hash.fetch("fooo") }
|
12
|
-
assert_correction %("foo"), error.corrections
|
13
|
-
assert_match %(Did you mean? "foo"), error.to_s
|
14
|
-
end
|
15
|
-
end
|
data/test/fixtures/book.rb
DELETED