Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit e22d293.
- Loading branch information
Showing
10 changed files
with
134 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
require_relative '../formatter' | ||
# frozen-string-literal: true | ||
|
||
warn "`require 'did_you_mean/formatters/plain_formatter'` is deprecated. Please `require 'did_you_mean/formatter'` " \ | ||
"instead." | ||
module DidYouMean | ||
# The +DidYouMean::PlainFormatter+ is the basic, default formatter for the | ||
# gem. The formatter responds to the +message_for+ method and it returns a | ||
# human readable string. | ||
class PlainFormatter | ||
|
||
# Returns a human readable string that contains +corrections+. This | ||
# formatter is designed to be less verbose to not take too much screen | ||
# space while being helpful enough to the user. | ||
# | ||
# @example | ||
# | ||
# formatter = DidYouMean::PlainFormatter.new | ||
# | ||
# # displays suggestions in two lines with the leading empty line | ||
# puts formatter.message_for(["methods", "method"]) | ||
# | ||
# Did you mean? methods | ||
# method | ||
# # => nil | ||
# | ||
# # displays an empty line | ||
# puts formatter.message_for([]) | ||
# | ||
# # => nil | ||
# | ||
def message_for(corrections) | ||
corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
warn "`require 'did_you_mean/formatters/verbose_formatter'` is deprecated and falls back to the default formatter. " | ||
|
||
require_relative '../formatter' | ||
|
||
# frozen-string-literal: true | ||
|
||
module DidYouMean | ||
# For compatibility: | ||
VerboseFormatter = Formatter | ||
# The +DidYouMean::VerboseFormatter+ uses extra empty lines to make the | ||
# suggestion stand out more in the error message. | ||
# | ||
# In order to activate the verbose formatter, | ||
# | ||
# @example | ||
# | ||
# OBject | ||
# # => NameError: uninitialized constant OBject | ||
# # Did you mean? Object | ||
# | ||
# require 'did_you_mean/verbose' | ||
# | ||
# OBject | ||
# # => NameError: uninitialized constant OBject | ||
# # | ||
# # Did you mean? Object | ||
# # | ||
# | ||
class VerboseFormatter | ||
|
||
# Returns a human readable string that contains +corrections+. This | ||
# formatter is designed to be less verbose to not take too much screen | ||
# space while being helpful enough to the user. | ||
# | ||
# @example | ||
# | ||
# formatter = DidYouMean::PlainFormatter.new | ||
# | ||
# puts formatter.message_for(["methods", "method"]) | ||
# | ||
# | ||
# Did you mean? methods | ||
# method | ||
# | ||
# # => nil | ||
# | ||
def message_for(corrections) | ||
return "" if corrections.empty? | ||
|
||
output = "\n\n Did you mean? ".dup | ||
output << corrections.join("\n ") | ||
output << "\n " | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
warn "The verbose formatter has been removed and now `require 'did_you_mean/verbose'` has no effect. Please " \ | ||
"remove this call." | ||
require_relative '../did_you_mean' | ||
require_relative 'formatters/verbose_formatter' | ||
|
||
DidYouMean.formatter = DidYouMean::VerboseFormatter.new |
20 changes: 0 additions & 20 deletions
20
test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_relative './helper' | ||
|
||
class VerboseFormatterTest < Test::Unit::TestCase | ||
class ErrorHighlightDummyFormatter | ||
def message_for(spot) | ||
"" | ||
end | ||
end | ||
|
||
def setup | ||
require_relative File.join(DidYouMean::TestHelper.root, 'verbose') | ||
|
||
DidYouMean.formatter = DidYouMean::VerboseFormatter.new | ||
|
||
if defined?(ErrorHighlight) | ||
@error_highlight_old_formatter = ErrorHighlight.formatter | ||
ErrorHighlight.formatter = ErrorHighlightDummyFormatter.new | ||
end | ||
end | ||
|
||
def teardown | ||
DidYouMean.formatter = DidYouMean::PlainFormatter.new | ||
|
||
if defined?(ErrorHighlight) | ||
ErrorHighlight.formatter = @error_highlight_old_formatter | ||
end | ||
end | ||
|
||
def test_message | ||
@error = assert_raise(NoMethodError){ 1.zeor? } | ||
|
||
assert_match <<~MESSAGE.strip, @error.message | ||
undefined method `zeor?' for 1:Integer | ||
Did you mean? zero? | ||
MESSAGE | ||
end | ||
end |