From e795e1de1c9e748e319076d05e0a1776a1585b79 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 7 Oct 2025 18:01:02 +0900 Subject: [PATCH] Improve English comments and messages --- lib/error_highlight/base.rb | 9 ++++----- lib/error_highlight/core_ext.rb | 2 +- lib/error_highlight/formatter.rb | 4 ++-- test/test_error_highlight.rb | 14 +++++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb index a4c65c6..22e0bf0 100644 --- a/lib/error_highlight/base.rb +++ b/lib/error_highlight/base.rb @@ -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. @@ -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? @@ -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 diff --git a/lib/error_highlight/core_ext.rb b/lib/error_highlight/core_ext.rb index 2fb07f2..d4f91e1 100644 --- a/lib/error_highlight/core_ext.rb +++ b/lib/error_highlight/core_ext.rb @@ -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 diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb index 5180576..d2fad9e 100644 --- a/lib/error_highlight/formatter.rb +++ b/lib/error_highlight/formatter.rb @@ -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 diff --git a/test/test_error_highlight.rb b/test/test_error_highlight.rb index be3e360..208dea8 100644 --- a/test/test_error_highlight.rb +++ b/test/test_error_highlight.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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