Skip to content

Commit

Permalink
Enable raising when running rubocop-md against invalid ruby snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Sep 27, 2023
1 parent 01743dd commit a7ee313
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 88 deletions.
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ AllCops:
- 'activestorage/test/dummy/**/*'
- 'actiontext/test/dummy/**/*'
- 'tools/rail_inspector/test/fixtures/*'
- guides/source/debugging_rails_applications.md
- guides/source/active_support_instrumentation.md
- '**/node_modules/**/*'
- '**/CHANGELOG.md'
- '**/2_*_release_notes.md'
Expand Down Expand Up @@ -365,6 +367,6 @@ Minitest/UnreachableAssertion:

Markdown:
# Whether to run RuboCop against non-valid snippets
WarnInvalid: false
WarnInvalid: true
# Whether to lint codeblocks without code attributes
Autodetect: false
2 changes: 1 addition & 1 deletion activestorage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
```
2. Annotate file inputs with the direct upload URL.

```ruby
```erb
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
```
3. That's it! Uploads begin upon form submission.
Expand Down
6 changes: 3 additions & 3 deletions guides/source/action_cable_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ChatChannel < ApplicationCable::Channel

private
def deliver_error_message(e)
broadcast_to(...)
# broadcast_to(...)
end
end
```
Expand All @@ -276,7 +276,7 @@ class ChatChannel < ApplicationCable::Channel

private
def send_welcome_message
broadcast_to(...)
# broadcast_to(...)
end

def track_subscription
Expand Down Expand Up @@ -847,7 +847,7 @@ You can change that in `config/database.yml` through the `pool` attribute.

Client-side logging is disabled by default. You can enable this by setting the `ActionCable.logger.enabled` to true.

```ruby
```js
import * as ActionCable from '@rails/actioncable'
ActionCable.logger.enabled = true
Expand Down
6 changes: 3 additions & 3 deletions guides/source/active_record_encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ You can use `ActiveRecord::Encryption.with_encryption_context` to set an encrypt

```ruby
ActiveRecord::Encryption.with_encryption_context(encryptor: ActiveRecord::Encryption::NullEncryptor.new) do
...
# ...
end
```

Expand All @@ -549,7 +549,7 @@ You can run code without encryption:

```ruby
ActiveRecord::Encryption.without_encryption do
...
# ...
end
```

Expand All @@ -561,7 +561,7 @@ You can run code without encryption but prevent overwriting encrypted content:

```ruby
ActiveRecord::Encryption.protecting_encrypted_data do
...
# ...
end
```

Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_record_multiple_databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ parameters it's based on. Let's say you want to use a cookie instead of a sessio
decide when to swap connections. You can write your own class:

```ruby
class MyCookieResolver << ActiveRecord::Middleware::DatabaseSelector::Resolver
class MyCookieResolver < ActiveRecord::Middleware::DatabaseSelector::Resolver
def self.call(request)
new(request.cookies)
end
Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_record_postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ To add a new value you can use `add_enum_value`:
```ruby
# db/migrate/20150720144913_add_new_state_to_articles.rb
def up
add_enum_value :article_state, "archived", # will be at the end after published
add_enum_value :article_state, "archived" # will be at the end after published
add_enum_value :article_state, "in review", before: "published"
add_enum_value :article_state, "approved", after: "in review"
end
Expand Down
5 changes: 3 additions & 2 deletions guides/source/active_record_querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,12 @@ If a query has a hash condition with non-nil values on a nullable column, the re
```ruby
Customer.create!(nullable_country: nil)
Customer.where.not(nullable_country: "UK")
=> []
# => []

# But
Customer.create!(nullable_country: "UK")
Customer.where.not(nullable_country: nil)
=> [#<Customer id: 2, nullable_country: "UK">]
# => [#<Customer id: 2, nullable_country: "UK">]
```

[`where.not`]: https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-not
Expand Down
8 changes: 4 additions & 4 deletions guides/source/active_storage_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ end

or if you are using Rails 6.0+, you can run a model generator command like this:

```ruby
bin/rails generate model User avatar:attachment
```bash
$ bin/rails generate model User avatar:attachment
```

You can create a user with an avatar:
Expand Down Expand Up @@ -482,8 +482,8 @@ end

or if you are using Rails 6.0+, you can run a model generator command like this:

```ruby
bin/rails generate model Message images:attachments
```bash
$ bin/rails generate model Message images:attachments
```

You can create a message with images:
Expand Down
4 changes: 3 additions & 1 deletion guides/source/active_support_core_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,9 @@ Instance methods are created as well for convenience, they are just proxies to t
```ruby
module ActionView
class Base
cattr_accessor :field_error_proc, default: Proc.new { ... }
cattr_accessor :field_error_proc, default: Proc.new {
# ...
}
end
end
```
Expand Down
2 changes: 2 additions & 0 deletions guides/source/asset_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ Example:
# config/importmap.rb
pin "@github/hotkey", to: "https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js", preload: true
pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
```
```erb
# app/views/layouts/application.html.erb
<%= javascript_importmap_tags %>
Expand Down
4 changes: 2 additions & 2 deletions guides/source/association_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ end

Each instance of the `Author` model will have these methods:

```ruby
```
books
books<<(object, ...)
books.delete(object, ...)
Expand Down Expand Up @@ -2321,7 +2321,7 @@ end

Each instance of the `Part` model will have these methods:

```ruby
```
assemblies
assemblies<<(object, ...)
assemblies.delete(object, ...)
Expand Down
4 changes: 2 additions & 2 deletions guides/source/autoloading_and_reloading_constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module MyApp
lib.join("generators")
)

...
# ...
end
end
```
Expand Down Expand Up @@ -223,7 +223,7 @@ module MyApp
lib.join("generators")
)

...
# ...
end
end
```
Expand Down
12 changes: 6 additions & 6 deletions guides/source/caching_with_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ render "comments/comments"
render 'comments/comments'
render('comments/comments')

render "header" translates to render("comments/header")
render "header" # translates to render("comments/header")

render(@topic) translates to render("topics/topic")
render(topics) translates to render("topics/topic")
render(message.topics) translates to render("topics/topic")
render(@topic) # translates to render("topics/topic")
render(topics) # translates to render("topics/topic")
render(message.topics) # translates to render("topics/topic")
```

On the other hand, some calls need to be changed to make caching work properly.
Expand Down Expand Up @@ -381,13 +381,13 @@ you can have multiple threads performing queries to the cache store at the same
If you want to disable connection pooling, set `:pool` option to `false` when configuring the cache store:

```ruby
config.cache_store = :mem_cache_store, "cache.example.com", pool: false
config.cache_store = :mem_cache_store, "cache.example.com", { pool: false }
```

You can also override default pool settings by providing individual options to the `:pool` option:

```ruby
config.cache_store = :mem_cache_store, "cache.example.com", pool: { size: 32, timeout: 1 }
config.cache_store = :mem_cache_store, "cache.example.com", { pool: { size: 32, timeout: 1 } }
```

* `:size` - This option sets the number of connections per process (defaults to 5).
Expand Down
61 changes: 23 additions & 38 deletions guides/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -1904,40 +1904,23 @@ Configures what exceptions are assigned to an HTTP status. It accepts a hash and
```ruby
config.action_dispatch.rescue_responses = {
'ActionController::RoutingError'
=> :not_found,
'AbstractController::ActionNotFound'
=> :not_found,
'ActionController::MethodNotAllowed'
=> :method_not_allowed,
'ActionController::UnknownHttpMethod'
=> :method_not_allowed,
'ActionController::NotImplemented'
=> :not_implemented,
'ActionController::UnknownFormat'
=> :not_acceptable,
'ActionController::InvalidAuthenticityToken'
=> :unprocessable_entity,
'ActionController::InvalidCrossOriginRequest'
=> :unprocessable_entity,
'ActionDispatch::Http::Parameters::ParseError'
=> :bad_request,
'ActionController::BadRequest'
=> :bad_request,
'ActionController::ParameterMissing'
=> :bad_request,
'Rack::QueryParser::ParameterTypeError'
=> :bad_request,
'Rack::QueryParser::InvalidParameterError'
=> :bad_request,
'ActiveRecord::RecordNotFound'
=> :not_found,
'ActiveRecord::StaleObjectError'
=> :conflict,
'ActiveRecord::RecordInvalid'
=> :unprocessable_entity,
'ActiveRecord::RecordNotSaved'
=> :unprocessable_entity
'ActionController::RoutingError' => :not_found,
'AbstractController::ActionNotFound' => :not_found,
'ActionController::MethodNotAllowed' => :method_not_allowed,
'ActionController::UnknownHttpMethod'=> :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
'ActionController::UnknownFormat'=> :not_acceptable,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
'ActionController::InvalidCrossOriginRequest'=> :unprocessable_entity,
'ActionDispatch::Http::Parameters::ParseError' => :bad_request,
'ActionController::BadRequest' => :bad_request,
'ActionController::ParameterMissing' => :bad_request,
'Rack::QueryParser::ParameterTypeError'=> :bad_request,
'Rack::QueryParser::InvalidParameterError' => :bad_request,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid'=> :unprocessable_entity,
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
}
```
Expand Down Expand Up @@ -2260,10 +2243,12 @@ Specifies whether mail will actually be delivered and is `true` by default. It c
Configures Action Mailer defaults. Use to set options like `from` or `reply_to` for every mailer. These default to:

```ruby
mime_version: "1.0",
charset: "UTF-8",
content_type: "text/plain",
parts_order: ["text/plain", "text/enriched", "text/html"]
{
mime_version: "1.0",
charset: "UTF-8",
content_type: "text/plain",
parts_order: ["text/plain", "text/enriched", "text/html"]
}
```

Assign a hash to set additional options:
Expand Down
4 changes: 2 additions & 2 deletions guides/source/contributing_to_ruby_on_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ To set the new framework default, set the new value in
def load_defaults(target_version)
case target_version.to_s
when "7.1"
...
# ...
if respond_to?(:active_job)
active_job.existing_behavior = false
end
...
# ...
end
end
```
Expand Down
4 changes: 2 additions & 2 deletions guides/source/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2038,22 +2038,21 @@ so we write that:

```ruby
class ArticlesController < ApplicationController

http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]

def index
@articles = Article.all
end

# snippet for brevity
end
```

We also want to allow only authenticated users to delete comments, so in the
`CommentsController` (`app/controllers/comments_controller.rb`) we write:

```ruby
class CommentsController < ApplicationController

http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy

def create
Expand All @@ -2062,6 +2061,7 @@ class CommentsController < ApplicationController
end

# snippet for brevity
end
```

Now if you try to create a new article, you will be greeted with a basic HTTP
Expand Down
4 changes: 2 additions & 2 deletions guides/source/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ end

The key for the error message in this case is `:blank`. Active Record will look up this key in the namespaces:

```ruby
```
activerecord.errors.models.[model_name].attributes.[attribute_name]
activerecord.errors.models.[model_name]
activerecord.errors.messages
Expand All @@ -927,7 +927,7 @@ errors.messages

Thus, in our example it will try the following keys in this order and return the first result:

```ruby
```
activerecord.errors.models.user.attributes.name.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
Expand Down
2 changes: 1 addition & 1 deletion guides/source/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ Rails.application.config.hosts << "product.com"

Rails.application.config.host_authorization = {
# Exclude requests for the /healthcheck/ path from host checking
exclude: ->(request) { request.path =~ /healthcheck/ }
exclude: ->(request) { request.path.include?("healthcheck") },
# Add custom Rack application for the response
response_app: -> env do
[400, { "Content-Type" => "text/plain" }, ["Bad Request"]]
Expand Down
Loading

0 comments on commit a7ee313

Please sign in to comment.