-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
When running rubocop for the following code, an error occurred.
code (saved as tmp01.rb):
@file.write(sprintf("%-*s", rs, '') * (i - n)).rubocop.yml:
AllCops:
NewCops: enable
Log (file path prefix masked):
$ rubocop -d tmp01.rb
For /XXXXXXXXXX/YYYYYYYY: configuration from /XXXXXXXXXX/YYYYYYYY/.rubocop.yml
Default configuration from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /XXXXXXXXXX/YYYYYYYY/tmp01.rb
An error occurred while Style/RedundantFormat cop was inspecting /XXXXXXXXXX/YYYYYYYY/tmp01.rb:1:12.
/XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/style/redundant_format.rb:126:in 'Kernel#format': no implicit conversion of String into Integer (TypeError)
formatted_string = format(string, *format_arguments)
^^^^^^^^^^^^^^^^^^^^^^^^^
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/style/redundant_format.rb:126:in 'RuboCop::Cop::Style::RedundantFormat#register_all_fields_literal'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/style/redundant_format.rb:118:in 'RuboCop::Cop::Style::RedundantFormat#detect_unnecessary_fields'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/style/redundant_format.rb:100:in 'RuboCop::Cop::Style::RedundantFormat#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:143:in 'Kernel#public_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:143:in 'block (2 levels) in RuboCop::Cop::Commissioner#trigger_restricted_cops'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:171:in 'RuboCop::Cop::Commissioner#with_cop_error_handling'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:142:in 'block in RuboCop::Cop::Commissioner#trigger_restricted_cops'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:141:in 'Array#each'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:141:in 'RuboCop::Cop::Commissioner#trigger_restricted_cops'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:70:in 'RuboCop::Cop::Commissioner#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:169:in 'block in RuboCop::AST::Traversal#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'Array#each'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'Enumerable#each_with_index'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'RuboCop::AST::Traversal#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:169:in 'block in RuboCop::AST::Traversal#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'Array#each'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'Enumerable#each_with_index'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:166:in 'RuboCop::AST::Traversal#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_send'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.46.0/lib/rubocop/ast/traversal.rb:20:in 'RuboCop::AST::Traversal#walk'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/commissioner.rb:87:in 'RuboCop::Cop::Commissioner#investigate'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/team.rb:174:in 'RuboCop::Cop::Team#investigate_partial'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/team.rb:108:in 'RuboCop::Cop::Team#investigate'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:350:in 'block in RuboCop::Runner#inspect_file'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:349:in 'Array#each'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:349:in 'Enumerable#flat_map'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:349:in 'RuboCop::Runner#inspect_file'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:291:in 'block in RuboCop::Runner#do_inspection_loop'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:326:in 'block in RuboCop::Runner#iterate_until_no_changes'
from <internal:kernel>:168:in 'Kernel#loop'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:319:in 'RuboCop::Runner#iterate_until_no_changes'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:287:in 'RuboCop::Runner#do_inspection_loop'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:167:in 'block in RuboCop::Runner#file_offenses'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:192:in 'RuboCop::Runner#file_offense_cache'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:166:in 'RuboCop::Runner#file_offenses'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:154:in 'RuboCop::Runner#process_file'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:135:in 'block in RuboCop::Runner#each_inspected_file'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:134:in 'Array#each'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:134:in 'Enumerable#reduce'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:134:in 'RuboCop::Runner#each_inspected_file'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:120:in 'RuboCop::Runner#inspect_files'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/runner.rb:73:in 'RuboCop::Runner#run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/command/execute_runner.rb:26:in 'block in RuboCop::CLI::Command::ExecuteRunner#execute_runner'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/command/execute_runner.rb:52:in 'RuboCop::CLI::Command::ExecuteRunner#with_redirect'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/command/execute_runner.rb:25:in 'RuboCop::CLI::Command::ExecuteRunner#execute_runner'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/command/execute_runner.rb:17:in 'RuboCop::CLI::Command::ExecuteRunner#run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/command.rb:11:in 'RuboCop::CLI::Command.run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli/environment.rb:18:in 'RuboCop::CLI::Environment#run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:128:in 'RuboCop::CLI#run_command'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:135:in 'RuboCop::CLI#execute_runners'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:54:in 'block in RuboCop::CLI#run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:87:in 'RuboCop::CLI#profile_if_needed'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:45:in 'RuboCop::CLI#run'
from /XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/exe/rubocop:15:in '<top (required)>'
from /XXXXXXXXXX/NNNNNN/3.4.6/bin/rubocop:25:in 'Kernel#load'
from /XXXXXXXXXX/NNNNNN/3.4.6/bin/rubocop:25:in '<main>'
C
Offenses:
tmp01.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
@file.write(sprintf("%-*s", rs, '') * (i - n))
^
tmp01.rb:1:13: C: [Correctable] Style/FormatString: Favor format over sprintf.
@file.write(sprintf("%-*s", rs, '') * (i - n))
^^^^^^^
tmp01.rb:1:21: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
@file.write(sprintf("%-*s", rs, '') * (i - n))
^^^^^^
1 file inspected, 3 offenses detected, 3 offenses autocorrectable
1 error occurred:
An error occurred while Style/RedundantFormat cop was inspecting /XXXXXXXXXX/YYYYYYYY/tmp01.rb:1:12.
configuration from /XXXXXXXXXX/YYYYYYYY/.rubocop.yml
Errors are usually caused by RuboCop bugs.
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.80.2 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.4.6) [x86_64-linux]
Finished in 0.5087977449875325 seconds
Expected behavior
Finish without error
Actual behavior
The following error occurred.
An error occurred while Style/RedundantFormat cop was inspecting /XXXXXXXXXX/YYYYYYYY/tmp01.rb:1:12.
/XXXXXXXXXX/NNNNNN/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.80.2/lib/rubocop/cop/style/redundant_format.rb:126:in 'Kernel#format': no implicit conversion of String into Integer (TypeError)
formatted_string = format(string, *format_arguments)
^^^^^^^^^^^^^^^^^^^^^^^^^
Steps to reproduce the problem
See above execution logs.
RuboCop version
$ rubocop -V
1.80.2 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.4.6) [x86_64-linux]
$ ruby --version
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [x86_64-linux]