Skip to content

Commit

Permalink
run rubocop against markdown (#1699)
Browse files Browse the repository at this point in the history
* run standardrb against docs

* add missing newline
  • Loading branch information
joelhawksley authored Mar 31, 2023
1 parent 7a52625 commit e26359f
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require:
- standard
- "rubocop-md"
2 changes: 2 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ruby_version: 2.5
ignore:
- 'docs/CHANGELOG.md' # Rubocop doesn't like our indenting of code examples
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
22 changes: 11 additions & 11 deletions docs/adrs/0003-polymorphic-slot-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
7 changes: 4 additions & 3 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion docs/guide/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions docs/guide/previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -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
```
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/slots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions docs/viewcomponents-at-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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
```

Expand Down
1 change: 1 addition & 0 deletions view_component.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e26359f

Please sign in to comment.