mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Suppress warnings except for when last evaluation
Co-authored-by: Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
This commit is contained in:
parent
c33d29fba5
commit
a5b6d7bca8
4 changed files with 23 additions and 5 deletions
|
@ -766,7 +766,10 @@ module IRB
|
|||
# s-expression where the second selement of the top level array is an
|
||||
# array of parsed expressions. The first element of each expression is the
|
||||
# expression's type.
|
||||
ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
result = ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
|
||||
$VERBOSE = verbose
|
||||
result
|
||||
end
|
||||
|
||||
ATTR_TTY = "\e[%sm"
|
||||
|
|
|
@ -154,6 +154,7 @@ module IRB # :nodoc:
|
|||
def scan(code, allow_last_error:)
|
||||
pos = [1, 0]
|
||||
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
lexer = Ripper::Lexer.new(code)
|
||||
if lexer.respond_to?(:scan) # Ruby 2.7+
|
||||
lexer.scan.each do |elem|
|
||||
|
@ -177,6 +178,7 @@ module IRB # :nodoc:
|
|||
yield(elem.event, elem.tok, elem.state)
|
||||
end
|
||||
end
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
def dispatch_seq(token, expr, str, in_symbol:)
|
||||
|
|
|
@ -71,20 +71,27 @@ class RubyLex
|
|||
end
|
||||
end
|
||||
|
||||
def ripper_lex_without_warning(code)
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
tokens = Ripper.lex(code)
|
||||
$VERBOSE = verbose
|
||||
tokens
|
||||
end
|
||||
|
||||
def set_auto_indent(context)
|
||||
if @io.respond_to?(:auto_indent) and context.auto_indent_mode
|
||||
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
|
||||
if is_newline
|
||||
md = lines[line_index - 1].match(/(\A +)/)
|
||||
prev_spaces = md.nil? ? 0 : md[1].count(' ')
|
||||
@tokens = Ripper.lex(lines[0..line_index].join("\n"))
|
||||
@tokens = ripper_lex_without_warning(lines[0..line_index].join("\n"))
|
||||
depth_difference = check_newline_depth_difference
|
||||
prev_spaces + depth_difference * 2
|
||||
else
|
||||
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
|
||||
last_line = lines[line_index]&.byteslice(0, byte_pointer)
|
||||
code += last_line if last_line
|
||||
@tokens = Ripper.lex(code)
|
||||
@tokens = ripper_lex_without_warning(code)
|
||||
corresponding_token_depth = check_corresponding_token_depth
|
||||
if corresponding_token_depth
|
||||
corresponding_token_depth
|
||||
|
@ -97,7 +104,7 @@ class RubyLex
|
|||
end
|
||||
|
||||
def check_state(code)
|
||||
@tokens = Ripper.lex(code)
|
||||
@tokens = ripper_lex_without_warning(code)
|
||||
ltype = process_literal_type
|
||||
indent = process_nesting_level
|
||||
continue = process_continue
|
||||
|
@ -160,7 +167,7 @@ class RubyLex
|
|||
end
|
||||
code = @line + (line.nil? ? '' : line)
|
||||
code.gsub!(/\s*\z/, '').concat("\n")
|
||||
@tokens = Ripper.lex(code)
|
||||
@tokens = ripper_lex_without_warning(code)
|
||||
@continue = process_continue
|
||||
@code_block_open = check_code_block(code)
|
||||
@indent = process_nesting_level
|
||||
|
|
|
@ -63,6 +63,12 @@ module TestIRB
|
|||
assert_not_match(/rescue _\.class/, e.message)
|
||||
end
|
||||
|
||||
def test_evaluate_with_onigmo_warning
|
||||
assert_warning("(irb):1: warning: character class has duplicated range: /[aa]/\n") do
|
||||
@context.evaluate('/[aa]/', 1)
|
||||
end
|
||||
end
|
||||
|
||||
def test_eval_input
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
input = TestInputMethod.new([
|
||||
|
|
Loading…
Reference in a new issue