Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/error_highlight/base.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require_relative "version"

module ErrorHighlight
# Identify the code fragment at that a given exception occurred.
# Identify the code fragment where a given exception occurred.
#
# Options:
#
# point_type: :name | :args
# :name (default) points the method/variable name that the exception occurred.
# :args points the arguments of the method call that the exception occurred.
# :name (default) points to the method/variable name where the exception occurred.
# :args points to the arguments of the method call where the exception occurred.
#
# backtrace_location: Thread::Backtrace::Location
# It locates the code fragment of the given backtrace_location.
Expand Down Expand Up @@ -113,7 +113,7 @@ def initialize(node, point_type: :name, name: nil)
snippet = @node.script_lines[lineno - 1 .. last_lineno - 1].join("")
snippet += "\n" unless snippet.end_with?("\n")

# It require some work to support Unicode (or multibyte) characters.
# It requires some work to support Unicode (or multibyte) characters.
# Tentatively, we stop highlighting if the code snippet has non-ascii characters.
# See https://github.com/ruby/error_highlight/issues/4
raise NonAscii unless snippet.ascii_only?
Expand Down Expand Up @@ -504,7 +504,6 @@ def spot_fcall_for_name
def spot_fcall_for_args
_mid, nd_args = @node.children
if nd_args && nd_args.first_lineno == nd_args.last_lineno
# binary operator
fetch_line(nd_args.first_lineno)
@beg_column = nd_args.first_column
@end_column = nd_args.last_column
Expand Down
2 changes: 1 addition & 1 deletion lib/error_highlight/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module CoreExt
_, _, snippet, highlight = ErrorHighlight.formatter.message_for(spot).lines
out += "\n | #{ snippet } #{ highlight }"
else
out += "\n (cannot create a snippet of the method definition; use Ruby 3.5 or later)"
out += "\n (cannot highlight method definition; try Ruby 3.5 or later)"
end
end
ret << "\n" + out if out
Expand Down
4 changes: 2 additions & 2 deletions lib/error_highlight/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def self.max_snippet_width=(width)
end

def self.terminal_width
# lazy load io/console, so it's not loaded when 'max_snippet_width' is set
# lazy load io/console to avoid loading it when 'max_snippet_width' is manually set
require "io/console"
$stderr.winsize[1] if $stderr.tty?
rescue LoadError, NoMethodError, SystemCallError
# do not truncate when window size is not available
# skip truncation when terminal window size is unavailable
end
end

Expand Down
14 changes: 7 additions & 7 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ def test_wrong_number_of_arguments_for_method
MethodDefLocationSupported ?
"| def wrong_number_of_arguments_test(x, y)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand All @@ -1494,7 +1494,7 @@ def test_missing_keyword
MethodDefLocationSupported ?
"| def keyword_test(kw1:, kw2:, kw3:)
^^^^^^^^^^^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand All @@ -1515,7 +1515,7 @@ def test_unknown_keyword
MethodDefLocationSupported ?
"| def keyword_test(kw1:, kw2:, kw3:)
^^^^^^^^^^^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand Down Expand Up @@ -1545,7 +1545,7 @@ def test_wrong_number_of_arguments_for_method2
MethodDefLocationSupported ?
"| def wrong_number_of_arguments_test2(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand All @@ -1567,7 +1567,7 @@ def test_wrong_number_of_arguments_for_lambda_literal
MethodDefLocationSupported ?
"| v = -> {}
^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand All @@ -1589,7 +1589,7 @@ def test_wrong_number_of_arguments_for_lambda_method
MethodDefLocationSupported ?
"| v = lambda { }
^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand All @@ -1615,7 +1615,7 @@ def test_wrong_number_of_arguments_for_define_method
MethodDefLocationSupported ?
"| define_method :define_method_test do |x, y|
^^" :
"(cannot create a snippet of the method definition; use Ruby 3.5 or later)"
"(cannot highlight method definition; try Ruby 3.5 or later)"
}
END

Expand Down