did_you_mean 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +110 -28
  5. data/README.md +52 -13
  6. data/Rakefile +4 -15
  7. data/did_you_mean.gemspec +2 -2
  8. data/doc/CHANGELOG.md.erb +1 -1
  9. data/lib/did_you_mean/core_ext/name_error.rb +6 -6
  10. data/lib/did_you_mean/experimental/initializer_name_correction.rb +2 -0
  11. data/lib/did_you_mean/experimental/ivar_name_correction.rb +36 -9
  12. data/lib/did_you_mean/experimental.rb +0 -15
  13. data/lib/did_you_mean/formatters/plain_formatter.rb +33 -0
  14. data/lib/did_you_mean/formatters/verbose_formatter.rb +49 -0
  15. data/lib/did_you_mean/spell_checkers/key_error_checker.rb +14 -0
  16. data/lib/did_you_mean/spell_checkers/method_name_checker.rb +32 -1
  17. data/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb +6 -2
  18. data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +57 -2
  19. data/lib/did_you_mean/spell_checkers/name_error_checkers.rb +2 -6
  20. data/lib/did_you_mean/verbose.rb +4 -0
  21. data/lib/did_you_mean/version.rb +1 -1
  22. data/lib/did_you_mean.rb +94 -4
  23. data/test/core_ext/name_error_extension_test.rb +9 -31
  24. data/test/edit_distance/jaro_winkler_test.rb +6 -1
  25. data/test/fixtures/book.rb +4 -0
  26. data/test/spell_checking/{class_name_test.rb → class_name_check_test.rb} +13 -1
  27. data/test/spell_checking/key_name_check_test.rb +44 -0
  28. data/test/spell_checking/{method_name_test.rb → method_name_check_test.rb} +38 -1
  29. data/test/spell_checking/{uncorrectable_name_test.rb → uncorrectable_name_check_test.rb} +1 -1
  30. data/test/spell_checking/{variable_name_test.rb → variable_name_check_test.rb} +40 -1
  31. data/test/verbose_formatter_test.rb +7 -1
  32. data/tmp/.keep +0 -0
  33. metadata +21 -20
  34. data/evaluation/calculator.rb +0 -105
  35. data/evaluation/dictionary_generator.rb +0 -37
  36. data/evaluation/incorrect_words.yaml +0 -1159
  37. data/lib/did_you_mean/experimental/key_error_name_correction.rb +0 -32
  38. data/lib/did_you_mean/formatter.rb +0 -16
  39. data/lib/did_you_mean/verbose_formatter.rb +0 -16
  40. data/test/experimental/key_error_test.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 70f21af56b6f4e14b5c5984d3ce5180a779c81c9
4
- data.tar.gz: 1f73d774f056a90eadace8401876b6f35ea54177
2
+ SHA256:
3
+ metadata.gz: 50bf04523f12cc4556ea28643d05f957a6ed95288d022716bbd32b325ea10feb
4
+ data.tar.gz: eeb093d01d27dae887f7ecbc5e4c530db5230743de2c7280b19f139f56e11638
5
5
  SHA512:
6
- metadata.gz: 17fbd60b5fd5a951b241b1b0277b1888c3495849825fd699dd1da24a8ac9b4b0a7366505f3584a3a41c125e785b6be556ae0a7f736168e39cb3b6d6b36a3cfa5
7
- data.tar.gz: 6a63b180eb98df8cfd4c59c209e9ff676d07e80b548d3d07c05e5e619cacd2725097d9f3da0037b34b517fcedb6c605229c0c4ab5c4fd68a68f124e03d85e9c1
6
+ metadata.gz: '0941cfdae93b66e3485c0850f2763c869971a1d7cff386fe66d51739d8869155d8ae868016210a0d2935f81aa8185477c9db162029d5a754240f210a2f3b9df8'
7
+ data.tar.gz: fc53dbc6ae27025325d36084b5be82f0b462addc83a3fa7a0b0b780b6aed2b2dc5f40cc3a3ad7213eeb2a03476723f0ae36681a534d27b9991c95d5ab2197b66
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.0-dev
1
+ 2.5.0
data/.travis.yml CHANGED
@@ -11,4 +11,5 @@ after_success:
11
11
  - bundle exec rake benchmark:memory
12
12
 
13
13
  rvm:
14
+ - 2.5.3
14
15
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,6 +1,89 @@
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&nbsp;1.2.0&nbsp;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&nbsp;1.2.\*&nbsp;will only be compatible with Ruby 2.5.0 and later as well. Versions earlier than&nbsp;1.1.\*&nbsp;will still be maintained until Ruby 2.4 is deprecated. Any other versions below&nbsp;1.0&nbsp;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),&nbsp;[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
+
26
+ ## [v1.1.2](https://github.com/yuki24/did_you_mean/tree/v1.1.2)
27
+
28
+ _<sup>released at 2017-09-24 07:28:48 UTC</sup>_
29
+
30
+ **This version is only compatible with Ruby 2.4 and later.**
31
+
32
+ #### Bug Fixes
33
+
34
+ - 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))
35
+
36
+ ## [v1.1.1](https://github.com/yuki24/did_you_mean/tree/v1.1.1)
37
+
38
+ _<sup>released at 2017-09-24 07:24:02 UTC</sup>_
39
+
40
+ ### This version has been yanked from Rubygems.org and is not available.
41
+
42
+ ## [v1.1.0](https://github.com/yuki24/did_you_mean/tree/v1.1.0)
43
+
44
+ _<sup>released at 2016-12-19 23:19:06 UTC</sup>_
45
+
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.
47
+
48
+ #### New Features
49
+
50
+ - Suggest a method name on a NameError from the `Struct#[]` or `Struct#[]=` method ([#73](https://github.com/yuki24/did_you_mean/pull/73)):
51
+
52
+ ```ruby
53
+ Struct.new(:foo).new[:fooo]
54
+ # => NameError: no member 'fooo' in struct
55
+ # Did you mean? foo
56
+ # foo=
57
+ ```
58
+
59
+ - Added a public interface for the gem's spell checker:
60
+
61
+ ```ruby
62
+ DidYouMean::SpellChecker.new(dictionary: ['email', 'fail', 'eval']).correct('meail')
63
+ # => ['email']
64
+ ```
65
+
66
+ - 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).
67
+
68
+ #### Bug Fixes
69
+
70
+ - 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))
71
+
72
+ ## [v1.0.3](https://github.com/yuki24/did_you_mean/tree/v1.0.3)
73
+
74
+ _<sup>released at 2017-09-24 07:22:07 UTC</sup>_
75
+
76
+ **This version is compatible with Ruby 2.3 and older**
77
+
78
+ #### Bug Fixes
79
+
80
+ - 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))
81
+
1
82
  ## [v1.0.2](https://github.com/yuki24/did_you_mean/tree/v1.0.2)
2
83
 
3
- _<sup>released on 2016-06-20 18:03:07 UTC</sup>_
84
+ _<sup>released at 2016-11-20 18:03:07 UTC</sup>_
85
+
86
+ **This version is compatible with Ruby 2.3 and older**
4
87
 
5
88
  #### Features
6
89
 
@@ -16,17 +99,16 @@ _<sup>released on 2016-06-20 18:03:07 UTC</sup>_
16
99
 
17
100
  ## [v1.0.1](https://github.com/yuki24/did_you_mean/tree/v1.0.1)
18
101
 
19
- _<sup>released on 2016-05-15 05:17:22 UTC</sup>_
102
+ _<sup>released at 2016-05-15 05:17:22 UTC</sup>_
20
103
 
21
104
  #### Bug Fixes
22
105
 
23
106
  - 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
107
  - 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
108
 
26
-
27
109
  ## [v1.0.0](https://github.com/yuki24/did_you_mean/tree/v1.0.0)
28
110
 
29
- _<sup>released on 2015-12-25 05:13:04 UTC</sup>_
111
+ _<sup>released at 2015-12-25 05:13:04 UTC</sup>_
30
112
 
31
113
  #### Features
32
114
 
@@ -43,15 +125,15 @@ _<sup>released on 2015-12-25 05:13:04 UTC</sup>_
43
125
 
44
126
  ## [v1.0.0.rc1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.rc1)
45
127
 
46
- _<sup>released on 2015-12-25 05:02:25 UTC</sup>_
128
+ _<sup>released at 2015-12-25 05:02:25 UTC</sup>_
47
129
 
48
- #### Internal Chagens
130
+ #### Internal Changes
49
131
 
50
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)
51
133
 
52
134
  ## [v1.0.0.beta3](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta3)
53
135
 
54
- _<sup>released on 2015-12-25 04:56:13 UTC</sup>_
136
+ _<sup>released at 2015-12-25 04:56:13 UTC</sup>_
55
137
 
56
138
  #### Internal Changes
57
139
 
@@ -61,7 +143,7 @@ _<sup>released on 2015-12-25 04:56:13 UTC</sup>_
61
143
 
62
144
  ## [v1.0.0.beta2](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta2)
63
145
 
64
- _<sup>released on 2015-12-25 04:50:36 UTC</sup>_
146
+ _<sup>released at 2015-12-25 04:50:36 UTC</sup>_
65
147
 
66
148
  #### Bug Fixes
67
149
 
@@ -69,7 +151,7 @@ _<sup>released on 2015-12-25 04:50:36 UTC</sup>_
69
151
 
70
152
  ## [v1.0.0.beta1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta1)
71
153
 
72
- _<sup>released on 2015-12-25 05:27:53 UTC</sup>_
154
+ _<sup>released at 2015-12-25 05:27:53 UTC</sup>_
73
155
 
74
156
  #### Breaking Changes
75
157
 
@@ -83,7 +165,7 @@ _<sup>released on 2015-12-25 05:27:53 UTC</sup>_
83
165
 
84
166
  ## [v0.10.0](https://github.com/yuki24/did_you_mean/tree/v0.10.0)
85
167
 
86
- _<sup>released on 2015-08-21 06:44:11 UTC</sup>_
168
+ _<sup>released at 2015-08-21 06:44:11 UTC</sup>_
87
169
 
88
170
  #### Features
89
171
 
@@ -108,7 +190,7 @@ _<sup>released on 2015-08-21 06:44:11 UTC</sup>_
108
190
 
109
191
  ## [v0.9.10](https://github.com/yuki24/did_you_mean/tree/v0.9.10)
110
192
 
111
- _<sup>released on 2015-05-14 03:04:47 UTC</sup>_
193
+ _<sup>released at 2015-05-14 03:04:47 UTC</sup>_
112
194
 
113
195
  #### Bug Fixes
114
196
 
@@ -116,7 +198,7 @@ _<sup>released on 2015-05-14 03:04:47 UTC</sup>_
116
198
 
117
199
  ## [v0.9.9](https://github.com/yuki24/did_you_mean/tree/v0.9.9)
118
200
 
119
- _<sup>released on 2015-05-13 03:48:19 UTC</sup>_
201
+ _<sup>released at 2015-05-13 03:48:19 UTC</sup>_
120
202
 
121
203
  #### Features
122
204
 
@@ -130,7 +212,7 @@ _<sup>released on 2015-05-13 03:48:19 UTC</sup>_
130
212
 
131
213
  ## [v0.9.8](https://github.com/yuki24/did_you_mean/tree/v0.9.8)
132
214
 
133
- _<sup>released on 2015-04-12 01:55:27 UTC</sup>_
215
+ _<sup>released at 2015-04-12 01:55:27 UTC</sup>_
134
216
 
135
217
  #### Internal Changes
136
218
 
@@ -138,7 +220,7 @@ _<sup>released on 2015-04-12 01:55:27 UTC</sup>_
138
220
 
139
221
  ## [v0.9.7](https://github.com/yuki24/did_you_mean/tree/v0.9.7)
140
222
 
141
- _<sup>released on 2015-04-02 04:20:26 UTC</sup>_
223
+ _<sup>released at 2015-04-02 04:20:26 UTC</sup>_
142
224
 
143
225
  #### Bug Fixes
144
226
 
@@ -146,7 +228,7 @@ _<sup>released on 2015-04-02 04:20:26 UTC</sup>_
146
228
 
147
229
  ## [v0.9.6](https://github.com/yuki24/did_you_mean/tree/v0.9.6)
148
230
 
149
- _<sup>released on 2015-01-24 23:19:27 UTC</sup>_
231
+ _<sup>released at 2015-01-24 23:19:27 UTC</sup>_
150
232
 
151
233
  #### Bug Fixes
152
234
 
@@ -154,7 +236,7 @@ _<sup>released on 2015-01-24 23:19:27 UTC</sup>_
154
236
 
155
237
  ## [v0.9.5](https://github.com/yuki24/did_you_mean/tree/v0.9.5)
156
238
 
157
- _<sup>released on 2015-01-07 12:41:23 UTC</sup>_
239
+ _<sup>released at 2015-01-07 12:41:23 UTC</sup>_
158
240
 
159
241
  #### Bug Fixes
160
242
 
@@ -162,7 +244,7 @@ _<sup>released on 2015-01-07 12:41:23 UTC</sup>_
162
244
 
163
245
  ## [v0.9.4](https://github.com/yuki24/did_you_mean/tree/v0.9.4)
164
246
 
165
- _<sup>released on 2014-11-19 20:00:00 UTC</sup>_
247
+ _<sup>released at 2014-11-19 20:00:00 UTC</sup>_
166
248
 
167
249
  #### Bug Fixes
168
250
 
@@ -170,7 +252,7 @@ _<sup>released on 2014-11-19 20:00:00 UTC</sup>_
170
252
 
171
253
  ## [v0.9.3](https://github.com/yuki24/did_you_mean/tree/v0.9.3)
172
254
 
173
- _<sup>released on 2014-11-18 03:50:11 UTC</sup>_
255
+ _<sup>released at 2014-11-18 03:50:11 UTC</sup>_
174
256
 
175
257
  **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
258
 
@@ -180,7 +262,7 @@ _<sup>released on 2014-11-18 03:50:11 UTC</sup>_
180
262
 
181
263
  ## [v0.9.2](https://github.com/yuki24/did_you_mean/tree/v0.9.2)
182
264
 
183
- _<sup>released on 2014-11-17 15:32:33 UTC</sup>_
265
+ _<sup>released at 2014-11-17 15:32:33 UTC</sup>_
184
266
 
185
267
  #### Bug Fixes
186
268
 
@@ -188,7 +270,7 @@ _<sup>released on 2014-11-17 15:32:33 UTC</sup>_
188
270
 
189
271
  ## [v0.9.1](https://github.com/yuki24/did_you_mean/tree/v0.9.1)
190
272
 
191
- _<sup>released on 2014-11-16 18:54:24 UTC</sup>_
273
+ _<sup>released at 2014-11-16 18:54:24 UTC</sup>_
192
274
 
193
275
  **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
276
 
@@ -199,7 +281,7 @@ _<sup>released on 2014-11-16 18:54:24 UTC</sup>_
199
281
 
200
282
  ## [v0.9.0](https://github.com/yuki24/did_you_mean/tree/v0.9.0)
201
283
 
202
- _<sup>released on 2014-11-09 01:26:31 UTC</sup>_
284
+ _<sup>released at 2014-11-09 01:26:31 UTC</sup>_
203
285
 
204
286
  #### Features
205
287
 
@@ -221,7 +303,7 @@ first_name, last_name = full_name.split(" ")
221
303
 
222
304
  ## [v0.8.0](https://github.com/yuki24/did_you_mean/tree/v0.8.0)
223
305
 
224
- _<sup>released on 2014-10-27 02:03:13 UTC</sup>_
306
+ _<sup>released at 2014-10-27 02:03:13 UTC</sup>_
225
307
 
226
308
  **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
309
 
@@ -237,7 +319,7 @@ _<sup>released on 2014-10-27 02:03:13 UTC</sup>_
237
319
 
238
320
  ## [v0.7.0](https://github.com/yuki24/did_you_mean/tree/v0.7.0)
239
321
 
240
- _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
322
+ _<sup>released at 2014-09-26 03:37:18 UTC</sup>_
241
323
 
242
324
  **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
325
 
@@ -255,7 +337,7 @@ _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
255
337
 
256
338
  ## [v0.6.0](https://github.com/yuki24/did_you_mean/tree/v0.6.0)
257
339
 
258
- _<sup>released on 2014-05-18 00:23:24 UTC</sup>_
340
+ _<sup>released at 2014-05-18 00:23:24 UTC</sup>_
259
341
 
260
342
  **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
343
 
@@ -277,7 +359,7 @@ _<sup>released on 2014-05-18 00:23:24 UTC</sup>_
277
359
 
278
360
  ## [v0.5.0](https://github.com/yuki24/did_you_mean/tree/v0.5.0)
279
361
 
280
- _<sup>released on 2014-05-10 17:59:54 UTC</sup>_
362
+ _<sup>released at 2014-05-10 17:59:54 UTC</sup>_
281
363
 
282
364
  #### Features
283
365
 
@@ -285,7 +367,7 @@ _<sup>released on 2014-05-10 17:59:54 UTC</sup>_
285
367
 
286
368
  ## [v0.4.0](https://github.com/yuki24/did_you_mean/tree/v0.4.0)
287
369
 
288
- _<sup>released on 2014-04-20 02:10:31 UTC</sup>_
370
+ _<sup>released at 2014-04-20 02:10:31 UTC</sup>_
289
371
 
290
372
  #### Features
291
373
 
@@ -305,7 +387,7 @@ User.new(flrst_name: "wrong flrst name")
305
387
 
306
388
  ## [v0.3.1](https://github.com/yuki24/did_you_mean/tree/v0.3.1)
307
389
 
308
- _<sup>released on 2014-03-20 23:16:20 UTC</sup>_
390
+ _<sup>released at 2014-03-20 23:16:20 UTC</sup>_
309
391
 
310
392
  #### Features
311
393
 
@@ -314,7 +396,7 @@ _<sup>released on 2014-03-20 23:16:20 UTC</sup>_
314
396
 
315
397
  ## [v0.3.0](https://github.com/yuki24/did_you_mean/tree/v0.3.0)
316
398
 
317
- _<sup>released on 2014-03-20 23:13:13 UTC</sup>_
399
+ _<sup>released at 2014-03-20 23:13:13 UTC</sup>_
318
400
 
319
401
  #### Features
320
402
 
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
- **Keep in mind that these experimental features should never be enabled in production as they would impact Ruby's performance and use some unstable Ruby APIs.**
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 Typed
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
- ### Correcting a Hash Key Name
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/verbose_formatter'
103
+ require 'did_you_mean/verbose'
104
104
  OBject
105
105
  # => NameError: uninitialized constant OBject
106
106
  #
@@ -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/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 do |path|
8
- /(verbose_formatter|experimental)/ =~ path
9
- end
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:verbose_formatter test:experimental)
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
@@ -13,11 +13,11 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/yuki24/did_you_mean"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($/).reject{|path| path.start_with?('evaluation/') }
17
17
  spec.test_files = spec.files.grep(%r{^(test)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.required_ruby_version = '>= 2.4.0dev'
20
+ spec.required_ruby_version = '>= 2.5.0'
21
21
 
22
22
  spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake"
data/doc/CHANGELOG.md.erb CHANGED
@@ -1,7 +1,7 @@
1
1
  <% releases.each do |release| %>
2
2
  ## [<%= release.name %>](https://github.com/<%= repository %>/tree/<%= release.tag_name %>)
3
3
 
4
- _<sup>released on <%= release.published_at %></sup>_
4
+ _<sup>released at <%= release.published_at %></sup>_
5
5
 
6
6
  <%= release.body.gsub(/\r\n/, "\n") %>
7
7
 
@@ -1,27 +1,27 @@
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
- msg << Formatter.new(corrections).to_s if IGNORED_CALLERS.all? {|ignored| bt.grep(ignored).empty? }
10
+ if !cause.respond_to?(:corrections) || cause.corrections.empty?
11
+ msg << DidYouMean.formatter.message_for(corrections)
12
+ end
13
+
14
14
  msg
15
15
  rescue
16
16
  super
17
17
  end
18
18
 
19
19
  def corrections
20
- spell_checker.corrections
20
+ @corrections ||= spell_checker.corrections
21
21
  end
22
22
 
23
23
  def spell_checker
24
- @spell_checker ||= SPELL_CHECKERS[self.class.to_s].new(self)
24
+ SPELL_CHECKERS[self.class.to_s].new(self)
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ require 'did_you_mean/levenshtein'
4
+
3
5
  module DidYouMean
4
6
  module Experimental
5
7
  module InitializerNameCorrection
@@ -1,19 +1,45 @@
1
+ # frozen-string-literal: true
2
+
3
+ require 'did_you_mean'
4
+
1
5
  module DidYouMean
2
- module Experimental
3
- module IvarNameCorrection
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
- def initialize(no_method_error)
9
- super
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
- super + ivar_name_corrections
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
@@ -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'
@@ -0,0 +1,33 @@
1
+ # frozen-string-literal: true
2
+
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.
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
+ #
29
+ def message_for(corrections)
30
+ corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}"
31
+ end
32
+ end
33
+ end