Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Prefer to_fs" rule #314

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 19, 2022

Follow up rails/rails#44354.

Also, the deprecated warning for to_s(:db) is to_fs(:db) instead of to_formatted_s(:db).

DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.

koic added a commit to koic/rubocop-rails that referenced this pull request Apr 19, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 19, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 19, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 19, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
README.adoc Outdated
@@ -1575,6 +1575,25 @@ hash.exclude?(:key)
string.exclude?('substring')
----

=== Prefer `to_fs` [[prefer-to-fs]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give the header a bit more context, how about:

Suggested change
=== Prefer `to_fs` [[prefer-to-fs]]
=== Prefer `to_fs` for Formatted Strings[[prefer-to-fs]]

README.adoc Outdated
@@ -1575,6 +1575,25 @@ hash.exclude?(:key)
string.exclude?('substring')
----

=== Prefer `to_fs` [[prefer-to-fs]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give the header a bit more context, how about:

Suggested change
=== Prefer `to_fs` [[prefer-to-fs]]
=== Prefer `to_fs` for Formatted Strings[[prefer-to-fs]]

Follow up rails/rails#44354.

Also, the deprecated warning for `to_s(:db)` is `to_fs(:db)` instead of `to_formatted_s(:db)`.

> DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 20, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 20, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
@koic koic merged commit 5f6b716 into rubocop:master Apr 20, 2022
@koic koic deleted the add_to_formatted_s_rule branch April 20, 2022 16:19
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 21, 2022
Follow up rubocop/rails-style-guide#314.

This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
depending on the cop's configuration.

## EnforcedStyle: to_fs (default)

```ruby
# bad
time.to_formatted_s(:db)

# good
time.to_fs(:db)
```

## EnforcedStyle: to_formatted_s

```
# bad
time.to_fs(:db)

# good
time.to_formatted_s(:db)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants