Skip to content

Commit 492a957

Browse files
authored
Merge pull request rails#53459 from zzak/guides-rubocop-stringliterals
Inherit Style/StrigLiterals cop for Guides [ci skip]
2 parents 4372bc3 + 9b0c079 commit 492a957

33 files changed

+390
-393
lines changed

guides/.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
inherit_from:
22
- '../.rubocop.yml'
33

4-
Style/StringLiterals:
5-
Enabled: false
6-
74
Layout/IndentationConsistency:
85
Enabled: false
96

guides/source/7_1_release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ development:
213213
Alternatively, integration can be achieved using the `DATABASE_URL` environment variable:
214214

215215
```ruby
216-
ENV['DATABASE_URL'] # => "trilogy://localhost/blog_development?pool=5"
216+
ENV["DATABASE_URL"] # => "trilogy://localhost/blog_development?pool=5"
217217
```
218218

219219
### Add `ActiveSupport::MessagePack`

guides/source/action_cable_overview.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ session, your session cookie is named `_session` and the user ID key is `user_id
136136
can use this approach:
137137

138138
```ruby
139-
verified_user = User.find_by(id: cookies.encrypted['_session']['user_id'])
139+
verified_user = User.find_by(id: cookies.encrypted["_session"]["user_id"])
140140
```
141141

142142
[`ActionCable::Connection::Base`]: https://api.rubyonrails.org/classes/ActionCable/Connection/Base.html
@@ -238,7 +238,7 @@ specific channel to handle raised exceptions:
238238
```ruby
239239
# app/channels/chat_channel.rb
240240
class ChatChannel < ApplicationCable::Channel
241-
rescue_from 'MyError', with: :deliver_error_message
241+
rescue_from "MyError", with: :deliver_error_message
242242

243243
private
244244
def deliver_error_message(e)
@@ -479,8 +479,8 @@ consumer.subscriptions.create({ channel: "ChatChannel", room: "Best Room" }, {
479479
ActionCable.server.broadcast(
480480
"chat_#{room}",
481481
{
482-
sent_by: 'Paul',
483-
body: 'This is a cool chat app.'
482+
sent_by: "Paul",
483+
body: "This is a cool chat app."
484484
}
485485
)
486486
```
@@ -548,7 +548,7 @@ class AppearanceChannel < ApplicationCable::Channel
548548
end
549549

550550
def appear(data)
551-
current_user.appear(on: data['appearing_on'])
551+
current_user.appear(on: data["appearing_on"])
552552
end
553553

554554
def away
@@ -697,8 +697,8 @@ application:
697697
# Somewhere in your app this is called, perhaps from a NewCommentJob
698698
WebNotificationsChannel.broadcast_to(
699699
current_user,
700-
title: 'New things!',
701-
body: 'All the news fit to print'
700+
title: "New things!",
701+
body: "All the news fit to print"
702702
)
703703
```
704704

@@ -788,7 +788,7 @@ passed to the server config as an array. The origins can be instances of
788788
strings or regular expressions, against which a check for the match will be performed.
789789

790790
```ruby
791-
config.action_cable.allowed_request_origins = ['https://rubyonrails.com', %r{http://ruby.*}]
791+
config.action_cable.allowed_request_origins = ["https://rubyonrails.com", %r{http://ruby.*}]
792792
```
793793

794794
To disable and allow requests from any origin:
@@ -842,7 +842,7 @@ the user account id if available, else "no-account" while tagging:
842842

843843
```ruby
844844
config.action_cable.log_tags = [
845-
-> request { request.env['user_account_id'] || "no-account" },
845+
-> request { request.env["user_account_id"] || "no-account" },
846846
:action_cable,
847847
-> request { request.uuid }
848848
]
@@ -866,7 +866,7 @@ listen for WebSocket requests on `/websocket`, specify that path to
866866
```ruby
867867
# config/application.rb
868868
class Application < Rails::Application
869-
config.action_cable.mount_path = '/websocket'
869+
config.action_cable.mount_path = "/websocket"
870870
end
871871
```
872872

guides/source/action_controller_overview.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ NOTE: Support for parsing XML parameters has been extracted into a gem named `ac
181181
The `params` hash will always contain the `:controller` and `:action` keys, but you should use the methods [`controller_name`][] and [`action_name`][] instead to access these values. Any other parameters defined by the routing, such as `:id`, will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route that captures the `:status` parameter in a "pretty" URL:
182182

183183
```ruby
184-
get '/clients/:status', to: 'clients#index', foo: 'bar'
184+
get "/clients/:status", to: "clients#index", foo: "bar"
185185
```
186186

187187
In this case, when a user opens the URL `/clients/active`, `params[:status]` will be set to "active". When this route is used, `params[:foo]` will also be set to "bar", as if it were passed in the query string. Your controller will also receive `params[:action]` as "index" and `params[:controller]` as "clients".
@@ -210,7 +210,7 @@ end
210210
And the following route:
211211

212212
```ruby
213-
get '/books/:id', to: 'books#show'
213+
get "/books/:id", to: "books#show"
214214
```
215215

216216
When a user opens the URL `/books/4_2`, the controller will extract the composite
@@ -469,14 +469,14 @@ Rails sets up a session key (the name of the cookie) when signing the session da
469469

470470
```ruby
471471
# Be sure to restart your server when you modify this file.
472-
Rails.application.config.session_store :cookie_store, key: '_your_app_session'
472+
Rails.application.config.session_store :cookie_store, key: "_your_app_session"
473473
```
474474

475475
You can also pass a `:domain` key and specify the domain name for the cookie:
476476

477477
```ruby
478478
# Be sure to restart your server when you modify this file.
479-
Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"
479+
Rails.application.config.session_store :cookie_store, key: "_your_app_session", domain: ".example.com"
480480
```
481481

482482
Rails sets up (for the CookieStore) a secret key used for signing the session data in `config/credentials.yml.enc`. This can be changed with `bin/rails credentials:edit`.
@@ -702,7 +702,7 @@ into `String`s:
702702
class CookiesController < ApplicationController
703703
def set_cookie
704704
cookies.encrypted[:expiration_date] = Date.tomorrow # => Thu, 20 Mar 2014
705-
redirect_to action: 'read_cookie'
705+
redirect_to action: "read_cookie"
706706
end
707707
708708
def read_cookie
@@ -1145,7 +1145,7 @@ class MyController < ActionController::Base
11451145
include ActionController::Live
11461146
11471147
def stream
1148-
response.headers['Content-Type'] = 'text/event-stream'
1148+
response.headers["Content-Type"] = "text/event-stream"
11491149
100.times {
11501150
response.stream.write "hello world\n"
11511151
sleep 1
@@ -1181,7 +1181,7 @@ class LyricsController < ActionController::Base
11811181
include ActionController::Live
11821182
11831183
def show
1184-
response.headers['Content-Type'] = 'text/event-stream'
1184+
response.headers["Content-Type"] = "text/event-stream"
11851185
song = Song.find(params[:id])
11861186
11871187
song.each do |line|
@@ -1242,13 +1242,13 @@ Sometimes it's desirable to filter out from log files some sensitive locations y
12421242
You can do that by using the `config.filter_redirect` configuration option:
12431243

12441244
```ruby
1245-
config.filter_redirect << 's3.amazonaws.com'
1245+
config.filter_redirect << "s3.amazonaws.com"
12461246
```
12471247

12481248
You can set it to a String, a Regexp, or an array of both.
12491249

12501250
```ruby
1251-
config.filter_redirect.concat ['s3.amazonaws.com', /private_path/]
1251+
config.filter_redirect.concat ["s3.amazonaws.com", /private_path/]
12521252
```
12531253

12541254
Matching URLs will be replaced with '[FILTERED]'. However, if you only wish to filter the parameters, not the whole URLs,

guides/source/action_mailbox_basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class ForwardsMailboxTest < ActionMailbox::TestCase
478478
test "directly recording a client forward for a forwarder and forwardee corresponding to one project" do
479479
assert_difference -> { people(:david).buckets.first.recordings.count } do
480480
receive_inbound_email_from_mail \
481-
481+
482482
from: people(:david).email_address,
483483
subject: "Fwd: Status update?",
484484
body: <<~BODY

guides/source/action_mailer_basics.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ used to define attributes common to all Mailers:
7171
# app/mailers/application_mailer.rb
7272
class ApplicationMailer < ActionMailer::Base
7373
default from: "[email protected]"
74-
layout 'mailer'
74+
layout "mailer"
7575
end
7676
```
7777

@@ -360,7 +360,7 @@ Action Mailer will automatically guess the `mime_type`, set the `encoding`, and
360360
create the attachment.
361361

362362
```ruby
363-
attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
363+
attachments["filename.jpg"] = File.read("/path/to/filename.jpg")
364364
```
365365

366366
When the `mail` method is triggered, it will send a multipart email with an
@@ -372,10 +372,10 @@ The other way to send attachments is to specify the file name, MIME-type and
372372
encoding headers, and content. Action Mailer will use the settings you pass in.
373373

374374
```ruby
375-
encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
376-
attachments['filename.jpg'] = {
377-
mime_type: 'application/gzip',
378-
encoding: 'SpecialEncoding',
375+
encoded_content = SpecialEncode(File.read("/path/to/filename.jpg"))
376+
attachments["filename.jpg"] = {
377+
mime_type: "application/gzip",
378+
encoding: "SpecialEncoding",
379379
content: encoded_content
380380
}
381381
```
@@ -395,7 +395,7 @@ calling `#inline`:
395395

396396
```ruby
397397
def welcome
398-
attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
398+
attachments.inline["image.jpg"] = File.read("/path/to/image.jpg")
399399
end
400400
```
401401

@@ -461,15 +461,15 @@ There is a `template_path` and `template_name` option to the `mail` method:
461461

462462
```ruby
463463
class UserMailer < ApplicationMailer
464-
default from: '[email protected]'
464+
default from: "[email protected]"
465465

466466
def welcome_email
467467
@user = params[:user]
468-
@url = 'http://example.com/login'
468+
@url = "http://example.com/login"
469469
mail(to: @user.email,
470-
subject: 'Welcome to My Awesome Site',
471-
template_path: 'notifications',
472-
template_name: 'hello')
470+
subject: "Welcome to My Awesome Site",
471+
template_path: "notifications",
472+
template_name: "hello")
473473
end
474474
end
475475
```
@@ -483,15 +483,15 @@ template. You can also render plain text inline without using a template file:
483483

484484
```ruby
485485
class UserMailer < ApplicationMailer
486-
default from: '[email protected]'
486+
default from: "[email protected]"
487487

488488
def welcome_email
489489
@user = params[:user]
490-
@url = 'http://example.com/login'
490+
@url = "http://example.com/login"
491491
mail(to: @user.email,
492-
subject: 'Welcome to My Awesome Site') do |format|
493-
format.html { render 'another_template' }
494-
format.text { render plain: 'hello' }
492+
subject: "Welcome to My Awesome Site") do |format|
493+
format.html { render "another_template" }
494+
format.text { render plain: "hello" }
495495
end
496496
end
497497
end
@@ -535,7 +535,7 @@ You can configure the default `host` across the application in
535535
`config/application.rb`:
536536

537537
```ruby
538-
config.action_mailer.default_url_options = { host: 'example.com' }
538+
config.action_mailer.default_url_options = { host: "example.com" }
539539
```
540540

541541
Once the `host` is configured, it is recommended that email views use the
@@ -595,7 +595,7 @@ Usually the `:asset_host` is consistent across the application, so you can
595595
configure it globally in `config/application.rb`:
596596

597597
```ruby
598-
config.action_mailer.asset_host = 'http://example.com'
598+
config.action_mailer.asset_host = "http://example.com"
599599
```
600600

601601
NOTE: Because we can't infer the protocol from the request, you'll need to
@@ -662,7 +662,7 @@ To use a different layout for a given mailer, call [`layout`][]:
662662

663663
```ruby
664664
class UserMailer < ApplicationMailer
665-
layout 'awesome' # Use awesome.(html|text).erb as the layout
665+
layout "awesome" # Use awesome.(html|text).erb as the layout
666666
end
667667
```
668668

@@ -673,7 +673,7 @@ To use a specific layout for a given email, you can pass in a `layout:
673673
class UserMailer < ApplicationMailer
674674
def welcome_email
675675
mail(to: params[:user].email) do |format|
676-
format.html { render layout: 'my_layout' }
676+
format.html { render layout: "my_layout" }
677677
format.text
678678
end
679679
end
@@ -700,7 +700,7 @@ For example, to inform all admins of a new registration:
700700
```ruby
701701
class AdminMailer < ApplicationMailer
702702
default to: -> { Admin.pluck(:email) },
703-
703+
704704

705705
def new_registration(user)
706706
@user = user
@@ -726,7 +726,7 @@ def welcome_email
726726
@user = params[:user]
727727
mail(
728728
to: email_address_with_name(@user.email, @user.name),
729-
subject: 'Welcome to My Awesome Site'
729+
subject: "Welcome to My Awesome Site"
730730
)
731731
end
732732
```
@@ -735,7 +735,7 @@ The same method in `from:` works to display the name of the sender:
735735

736736
```ruby
737737
class UserMailer < ApplicationMailer
738-
default from: email_address_with_name('[email protected]', 'Example Company Notifications')
738+
default from: email_address_with_name("[email protected]", "Example Company Notifications")
739739
end
740740
```
741741

@@ -904,7 +904,7 @@ class UserMailer < ApplicationMailer
904904

905905
# An Interceptor alternative.
906906
def sandbox_staging
907-
message.to = ['[email protected]'] if Rails.env.staging?
907+
message.to = ["[email protected]"] if Rails.env.staging?
908908
end
909909

910910
# A callback has more context than the comparable Observer example.
@@ -976,7 +976,7 @@ config.action_mailer.delivery_method = :sendmail
976976
# }
977977
config.action_mailer.perform_deliveries = true
978978
config.action_mailer.raise_delivery_errors = true
979-
config.action_mailer.default_options = { from: '[email protected]' }
979+
config.action_mailer.default_options = { from: "[email protected]" }
980980
```
981981

982982
### Action Mailer Configuration for Gmail
@@ -986,12 +986,12 @@ Add this to your `config/environments/$RAILS_ENV.rb` file to send via Gmail:
986986
```ruby
987987
config.action_mailer.delivery_method = :smtp
988988
config.action_mailer.smtp_settings = {
989-
address: 'smtp.gmail.com',
989+
address: "smtp.gmail.com",
990990
port: 587,
991-
domain: 'example.com',
991+
domain: "example.com",
992992
user_name: Rails.application.credentials.dig(:smtp, :user_name),
993993
password: Rails.application.credentials.dig(:smtp, :password),
994-
authentication: 'plain',
994+
authentication: "plain",
995995
enable_starttls: true,
996996
open_timeout: 5,
997997
read_timeout: 5 }
@@ -1084,7 +1084,7 @@ sent.
10841084
```ruby
10851085
class SandboxEmailInterceptor
10861086
def self.delivering_email(message)
1087-
message.to = ['[email protected]']
1087+
message.to = ["[email protected]"]
10881088
end
10891089
end
10901090
```

guides/source/action_view_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ Let's say you're displaying an article on a page which should be wrapped in a
790790
`div` for display purposes. First, you'll create a new `Article`:
791791

792792
```ruby
793-
Article.create(body: 'Partial Layouts are cool!')
793+
Article.create(body: "Partial Layouts are cool!")
794794
```
795795

796796
In the `show` template, you'll render the `_article` partial wrapped in the

guides/source/active_job_basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ GuestsCleanupJob.set(wait: 1.week).perform_later(guest)
119119
```ruby
120120
# `perform_now` and `perform_later` will call `perform` under the hood so
121121
# you can pass as many arguments as defined in the latter.
122-
GuestsCleanupJob.perform_later(guest1, guest2, filter: 'some_filter')
122+
GuestsCleanupJob.perform_later(guest1, guest2, filter: "some_filter")
123123
```
124124

125125
That's it!
@@ -255,7 +255,7 @@ The default queue name prefix delimiter is '\_'. This can be changed by setting
255255
module YourApp
256256
class Application < Rails::Application
257257
config.active_job.queue_name_prefix = Rails.env
258-
config.active_job.queue_name_delimiter = '.'
258+
config.active_job.queue_name_delimiter = "."
259259
end
260260
end
261261
```

0 commit comments

Comments
 (0)