Skip to content

Commit

Permalink
Add new "String#chars" rule
Browse files Browse the repository at this point in the history
Follow rubocop/rubocop#9615.

This PR adds "String#chars" rule.

```ruby
# bad
string.split(//)
string.split('')

# good
string.chars
```
  • Loading branch information
koic committed Mar 19, 2021
1 parent 087185f commit 0760bea
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.adoc
Expand Up @@ -4487,6 +4487,20 @@ url.sub('http://', 'https://')
str.tr('-', '_')
----

=== `String#chars` [[string-chars]]

Prefer the use of `String#chars` over `String#split` with empty string or regexp literal argument.

[source,ruby]
----
# bad
string.split(//)
string.split('')
# good
string.chars
----

=== `sprintf` [[sprintf]]

Prefer the use of `sprintf` and its alias `format` over the fairly cryptic `String#%` method.
Expand Down

0 comments on commit 0760bea

Please sign in to comment.