KEMBAR78
RedundantStringChars gives invalid code advice · Issue #517 · rubocop/rubocop-performance · GitHub
Skip to content

RedundantStringChars gives invalid code advice #517

@forthrin

Description

@forthrin

Expected behavior

Use [0, 2] instead of .chars[0, 2].join if anything.

Actual behavior

a.rb:1:7: C: [Correctable] Performance/RedundantStringChars: Use [0] instead of chars[0, 2].
'foo'.chars[0, 2].join
      ^^^^^^^^^^^

Following the advice as given will produce invalid code.

(Issue was found while trying different techniques to make printf indent correctly for multibyte chars.)

Steps to reproduce the problem

'foo'.chars[0, 2].join

RuboCop version

ruby      2025-08-01 30a20bc16
rubocop   2025-10-04 a08091813
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions