* run standardrb against docs

* add missing newline
This commit is contained in:
Joel Hawksley 2023-03-31 14:23:56 -06:00 коммит произвёл GitHub
Родитель 7a52625274
Коммит e26359f321
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 51 добавлений и 41 удалений

2
.github/workflows/lint.yml поставляемый
Просмотреть файл

@ -79,7 +79,7 @@ jobs:
run: |
bundle config path vendor/bundle
bundle install
bundle exec standardrb
bundle exec standardrb -r "rubocop-md"
bundle exec erblint **/*.html.erb
env:
RAILS_VERSION: '~> 7.0.0'

Просмотреть файл

@ -1,2 +1,3 @@
require:
- standard
- "rubocop-md"

Просмотреть файл

@ -1 +1,3 @@
ruby_version: 2.5
ignore:
- 'docs/CHANGELOG.md' # Rubocop doesn't like our indenting of code examples

Просмотреть файл

@ -236,6 +236,8 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-md (1.2.0)
rubocop (>= 1.0)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
@ -310,6 +312,7 @@ DEPENDENCIES
rails (~> 7.0.0)
rake (~> 13.0)
rspec-rails (~> 5)
rubocop-md (~> 1)
selenium-webdriver (~> 4)
simplecov (~> 0.18.0)
simplecov-console (~> 0.7.2)

Просмотреть файл

@ -10,6 +10,10 @@ nav_order: 5
## main
* Run `standardrb` against markdown in docs.
*Joel Hawksley*
* BREAKING: Use `ControllerCalledBeforeRenderError` in place of `ViewContextCalledBeforeRenderError`. Rename `Base::ViewContextCalledBeforeRenderError` to `ViewContextCalledBeforeRenderError`.
*Joel Hawksley*

Просмотреть файл

@ -105,18 +105,18 @@ In such cases, there are several viable workarounds:
1. Provide a lambda for each polymorphic type that adds the wrapping HTML. There is the potential for code duplication here, which could be mitigated by calling a class or helper method.
1. Manually implement a polymorphic slot using a positional `type` argument and `case` statement, as shown in the example below. This effectively replicates the behavior described in this proposal.
```ruby
renders_many :items do |type, *args, **kwargs|
content_tag :td, class: kwargs[:table_row_classes] do
case type
when :foo
RowFoo.new(*args, **kwargs)
when :bar
RowBar.new(*args, **kwargs)
end
end
```ruby
renders_many :items do |type, *args, **kwargs|
content_tag :td, class: kwargs[:table_row_classes] do
case type
when :foo
RowFoo.new(*args, **kwargs)
when :bar
RowBar.new(*args, **kwargs)
end
```
end
end
```
### Positional Type Argument vs Method Names

Просмотреть файл

@ -268,7 +268,7 @@ Internally sets `page` to be a `Capybara::Node::Simple`, allowing for
Capybara assertions to be used. All arguments are forwarded to the block.
```ruby
render_in_view_context(arg1, arg2:) do |arg1, arg2:|
render_in_view_context(arg1, arg2: "foo") do |arg1, arg2:|
render(MyComponent.new(arg1, arg2))
end

Просмотреть файл

@ -39,9 +39,7 @@ With the monkey patch disabled, use `render_component` (or `render_component_to
Using `rich_text_area` from ActionText in a ViewComponent will result in this error:
```ruby
undefined method 'rich_text_area_tag'
```
`undefined method "rich_text_area_tag"`
This is due to ViewComponent not having access to the helpers it needs via ActionText. As a workaround, add the following to your component (or base component):

Просмотреть файл

@ -116,12 +116,13 @@ When rendering the same component multiple times for later reuse, use `render_in
class PagesController < ApplicationController
def index
# Doesn't work: triggers a `AbstractController::DoubleRenderError`
# @reusable_icon = render IconComponent.new('close')
# @reusable_icon = render IconComponent.new("close")
# Doesn't work: renders the whole index view as a string
# @reusable_icon = render_to_string IconComponent.new('close')
# @reusable_icon = render_to_string IconComponent.new("close")
# Works: renders the component as a string
@reusable_icon = IconComponent.new('close').render_in(view_context)
@reusable_icon = IconComponent.new("close").render_in(view_context)
end
end
```

Просмотреть файл

@ -11,7 +11,7 @@ Helpers must be included to be used:
```ruby
module IconHelper
def icon(name)
tag.i data: { feather: name.to_s }
tag.i data: {feather: name.to_s}
end
end

Просмотреть файл

@ -69,7 +69,7 @@ Parameters can also be passed:
```ruby
class ExampleComponentTest < ViewComponent::TestCase
def test_render_preview
render_preview(:with_default_title, params: { message: "Hello, world!" })
render_preview(:with_default_title, params: {message: "Hello, world!"})
assert_text("Hello, world!")
end
@ -102,8 +102,6 @@ Previews render with the application layout by default, but can use a specific l
# test/components/previews/example_component_preview.rb
class ExampleComponentPreview < ViewComponent::Preview
layout "admin"
...
end
```
@ -163,7 +161,7 @@ To use a different location for preview templates, pass the `template` argument:
# test/components/previews/cell_component_preview.rb
class CellComponentPreview < ViewComponent::Preview
def default
render_with_template(template: 'custom_cell_component_preview/my_preview_template')
render_with_template(template: "custom_cell_component_preview/my_preview_template")
end
end
```

Просмотреть файл

@ -113,7 +113,7 @@ class BlogComponent < ViewComponent::Base
end
def call
content_tag :h1, content, { class: classes }
content_tag :h1, content, {class: classes}
end
end
end
@ -177,17 +177,17 @@ It's also possible to define a slot as a lambda that returns content to be rende
```ruby
class BlogComponent < ViewComponent::Base
renders_one :header, -> (classes:) do
renders_one :header, ->(classes:) do
# This isn't complex enough to be its own component yet, so we'll use a
# lambda slot. If it gets much bigger, it should be extracted out to a
# ViewComponent and rendered here with a component slot.
content_tag :h1 do
link_to title, root_path, { class: classes }
link_to title, root_path, {class: classes}
end
end
# It's also possible to return another ViewComponent with preset default values:
renders_many :posts, -> (title:, classes:) do
renders_many :posts, ->(title:, classes:) do
PostComponent.new(title: title, classes: "my-default-class " + classes)
end
end
@ -211,7 +211,7 @@ To provide content for a lambda slot via a block, add a block parameter. Render
```ruby
class BlogComponent < ViewComponent::Base
renders_one :header, -> (classes:, &block) do
renders_one :header, ->(classes:, &block) do
content_tag :h1, class: classes, &block
end
end

Просмотреть файл

@ -275,7 +275,7 @@ For components that depend on a layout, provide the `layout` argument:
```rb
class ViewComponentSystemTest < ViewComponent::SystemTestCase
def test_simple_js_interaction_in_browser_with_layout
with_rendered_component_path(render_inline(SimpleJavascriptInteractionWithoutJsIncludedComponent.new), layout: 'application') do |path|
with_rendered_component_path(render_inline(SimpleJavascriptInteractionWithoutJsIncludedComponent.new), layout: "application") do |path|
# ...
end
end

Просмотреть файл

@ -95,9 +95,9 @@ class MessageComponent < ViewComponent::Base
end
def call
@output_buffer.safe_append='<h1>Hello, '.freeze
@output_buffer.append=( @name )
@output_buffer.safe_append='!</h1>'.freeze
@output_buffer.safe_append = "<h1>Hello, ".freeze
@output_buffer.append = (@name)
@output_buffer.safe_append = "!</h1>".freeze
@output_buffer.to_s
end
end

Просмотреть файл

@ -100,18 +100,16 @@ Most ViewComponent instance methods can be private, as they will still be availa
```ruby
# good
class MyComponent < ViewComponent::Base
def initialize; end
private
def method_used_in_template; end
def method_used_in_template
end
end
# bad
class MyComponent < ViewComponent::Base
def initialize; end
def method_used_in_template; end
def method_used_in_template
end
end
```
@ -172,12 +170,16 @@ ViewComponents should be passed individual object attributes unless three or mor
```ruby
# good
class MyComponent < ViewComponent::Base
def initialize(repository:); end
def initialize(repository:)
#...
end
end
# bad
class MyComponent < ViewComponent::Base
def initialize(repository_name:, repository_owner:, repository_created_at:); end
def initialize(repository_name:, repository_owner:, repository_created_at:)
#...
end
end
```

Просмотреть файл

@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest", "= 5.6.0"
spec.add_development_dependency "pry", "~> 0.13"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rubocop-md", "~> 1"
spec.add_development_dependency "standard", "~> 1"
spec.add_development_dependency "simplecov", "~> 0.18.0"
spec.add_development_dependency "simplecov-console", "~> 0.7.2"