Skip to content

Commit c3a8be6

Browse files
committed
Use new good cop rules
1 parent 13c3a17 commit c3a8be6

20 files changed

+82
-83
lines changed

fixtures/components/article.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class Components::Article < Phlex::HTML
4-
def view_template(&block)
5-
article(&block)
4+
def view_template(&)
5+
article(&)
66
end
77
end

lib/phlex/csv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def column(header = nil, value)
8484
@_current_column_index += 1
8585
end
8686

87-
def each_item(&block)
88-
collection.each(&block)
87+
def each_item(&)
88+
collection.each(&)
8989
end
9090

9191
def yielder(record)

lib/phlex/element_clobbering_guard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Phlex::ElementClobberingGuard
55
def method_added(method_name)
66
if method_name[0] == "_" && element_method?(method_name[1..].to_sym)
7-
raise Phlex::NameError, "👋 Redefining the method `#{name}##{method_name}` is not a good idea."
7+
raise Phlex::NameError.new("👋 Redefining the method `#{name}##{method_name}` is not a good idea.")
88
else
99
super
1010
end

lib/phlex/helpers.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ module Phlex::Helpers
2121
def tokens(*tokens, **conditional_tokens)
2222
conditional_tokens.each do |condition, token|
2323
truthy = case condition
24-
when Symbol then send(condition)
24+
when Symbol then __send__(condition)
2525
when Proc then condition.call
26-
else raise ArgumentError, "The class condition must be a Symbol or a Proc."
26+
else raise ArgumentError.new("The class condition must be a Symbol or a Proc.")
2727
end
2828

2929
if truthy
@@ -51,8 +51,7 @@ def __append_token__(tokens, token)
5151
when String then tokens << token
5252
when Symbol then tokens << token.name
5353
when Array then tokens.concat(token)
54-
else raise ArgumentError,
55-
"Conditional classes must be Symbols, Strings, or Arrays of Symbols or Strings."
54+
else raise ArgumentError.new("Conditional classes must be Symbols, Strings, or Arrays of Symbols or Strings.")
5655
end
5756
end
5857

lib/phlex/kit.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
module Phlex::Kit
44
module LazyLoader
5-
def method_missing(name, *args, **kwargs, &block)
5+
def method_missing(name, ...)
66
if name[0] == name[0].upcase && __phlex_kit_constants__.include?(name) && __get_phlex_kit_constant__(name) && methods.include?(name)
7-
public_send(name, *args, **kwargs, &block)
7+
public_send(name, ...)
88
else
99
super
1010
end
@@ -42,9 +42,9 @@ def const_added(name)
4242

4343
if Class === constant && constant < Phlex::SGML
4444
if instance_methods.include?(name)
45-
raise NameError, "The instance method `#{name}' is already defined on `#{inspect}`."
45+
raise NameError.new("The instance method `#{name}' is already defined on `#{inspect}`.")
4646
elsif methods.include?(name)
47-
raise NameError, "The method `#{name}' is already defined on `#{inspect}`."
47+
raise NameError.new("The method `#{name}' is already defined on `#{inspect}`.")
4848
end
4949

5050
constant.include(self)

lib/phlex/sgml.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def call(...)
1313

1414
# Create a new instance of the component.
1515
# @note The block will not be delegated {#initialize}. Instead, it will be sent to {#template} when rendering.
16-
def new(*args, **kwargs, &block)
16+
def new(*, **, &block)
1717
if block
18-
object = super(*args, **kwargs, &nil)
18+
object = super(*, **, &nil)
1919
object.instance_exec { @_content_block = block }
2020
object
2121
else
@@ -72,7 +72,7 @@ def await(task)
7272
flush if task.running?
7373
task.wait
7474
else
75-
raise ArgumentError, "Expected an asynchronous task / promise."
75+
raise ArgumentError.new("Expected an asynchronous task / promise.")
7676
end
7777
end
7878

@@ -83,7 +83,7 @@ def call(buffer = +"", context: Phlex::Context.new, view_context: nil, parent: n
8383
@_view_context = view_context
8484
@_parent = parent
8585

86-
raise Phlex::DoubleRenderError, "You can't render a #{self.class.name} more than once." if @_rendered
86+
raise Phlex::DoubleRenderError.new("You can't render a #{self.class.name} more than once.") if @_rendered
8787
@_rendered = true
8888

8989
if fragments
@@ -140,7 +140,7 @@ def context
140140
# @see #format_object
141141
def plain(content)
142142
unless __text__(content)
143-
raise ArgumentError, "You've passed an object to plain that is not handled by format_object. See https://rubydoc.info/gems/phlex/Phlex/SGML#format_object-instance_method for more information"
143+
raise ArgumentError.new("You've passed an object to plain that is not handled by format_object. See https://rubydoc.info/gems/phlex/Phlex/SGML#format_object-instance_method for more information")
144144
end
145145

146146
nil
@@ -149,7 +149,7 @@ def plain(content)
149149
# Output a whitespace character. This is useful for getting inline elements to wrap. If you pass a block, a whitespace will be output before and after yielding the block.
150150
# @return [nil]
151151
# @yield If a block is given, it yields the block with no arguments.
152-
def whitespace(&block)
152+
def whitespace(&)
153153
context = @_context
154154
return if context.fragments && !context.in_target_fragment
155155

@@ -158,7 +158,7 @@ def whitespace(&block)
158158
buffer << " "
159159

160160
if block_given?
161-
yield_content(&block)
161+
yield_content(&)
162162
buffer << " "
163163
end
164164

@@ -167,14 +167,14 @@ def whitespace(&block)
167167

168168
# Output an HTML comment.
169169
# @return [nil]
170-
def comment(&block)
170+
def comment(&)
171171
context = @_context
172172
return if context.fragments && !context.in_target_fragment
173173

174174
buffer = context.buffer
175175

176176
buffer << "<!-- "
177-
yield_content(&block)
177+
yield_content(&)
178178
buffer << " -->"
179179

180180
nil
@@ -233,16 +233,16 @@ def flush
233233
# @param enumerable [Enumerable]
234234
# @example
235235
# render @items
236-
def render(renderable, &block)
236+
def render(renderable, &)
237237
case renderable
238238
when Phlex::SGML
239-
renderable.call(@_buffer, context: @_context, view_context: @_view_context, parent: self, &block)
239+
renderable.call(@_buffer, context: @_context, view_context: @_view_context, parent: self, &)
240240
when Class
241241
if renderable < Phlex::SGML
242-
renderable.new.call(@_buffer, context: @_context, view_context: @_view_context, parent: self, &block)
242+
renderable.new.call(@_buffer, context: @_context, view_context: @_view_context, parent: self, &)
243243
end
244244
when Enumerable
245-
renderable.each { |r| render(r, &block) }
245+
renderable.each { |r| render(r, &) }
246246
when Proc, Method
247247
if renderable.arity == 0
248248
yield_content_with_no_args(&renderable)
@@ -252,7 +252,7 @@ def render(renderable, &block)
252252
when String
253253
plain(renderable)
254254
else
255-
raise ArgumentError, "You can't render a #{renderable.inspect}."
255+
raise ArgumentError.new("You can't render a #{renderable.inspect}.")
256256
end
257257

258258
nil
@@ -385,15 +385,15 @@ def __attributes__(attributes, buffer = +"")
385385
name = case k
386386
when String then k
387387
when Symbol then k.name.tr("_", "-")
388-
else raise ArgumentError, "Attribute keys should be Strings or Symbols."
388+
else raise ArgumentError.new("Attribute keys should be Strings or Symbols.")
389389
end
390390

391391
lower_name = name.downcase
392392
next if lower_name == "href" && v.to_s.downcase.delete("^a-z:").start_with?("javascript:")
393393

394394
# Detect unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters.
395395
if HTML::EVENT_ATTRIBUTES.include?(lower_name.delete("^a-z-")) || name.match?(/[<>&"']/)
396-
raise ArgumentError, "Unsafe attribute name detected: #{k}."
396+
raise ArgumentError.new("Unsafe attribute name detected: #{k}.")
397397
end
398398

399399
case v
@@ -406,11 +406,11 @@ def __attributes__(attributes, buffer = +"")
406406
when Integer, Float
407407
buffer << " " << name << '="' << v.to_s << '"'
408408
when Hash
409-
case k
409+
case k
410410
when :class
411411
buffer << " " << name << '="' << __classes__(v).gsub('"', "&quot;") << '"'
412412
when :style
413-
buffer << " " << name << '="' << __styles__(v).gsub('"', "&quot;") << '"'
413+
buffer << " " << name << '="' << __styles__(v).gsub('"', "&quot;") << '"'
414414
else
415415
__attributes__(
416416
v.transform_keys { |subkey|
@@ -422,11 +422,11 @@ def __attributes__(attributes, buffer = +"")
422422
)
423423
end
424424
when Array
425-
value = case k
425+
value = case k
426426
when :class
427427
__classes__(v)
428428
when :style
429-
__styles__(v)
429+
__styles__(v)
430430
else
431431
v.compact.join(" ")
432432
end
@@ -465,7 +465,7 @@ def __classes__(c)
465465
case c
466466
when String then c
467467
when Symbol then c.name.tr("_", "-").delete_suffix("?")
468-
else raise ArgumentError, "Class keys should be Strings or Symbols."
468+
else raise ArgumentError.new("Class keys should be Strings or Symbols.")
469469
end
470470
}.join(" ")
471471
when nil, false
@@ -498,7 +498,7 @@ def __styles__(s)
498498
prop = case k
499499
when String then k
500500
when Symbol then k.name.tr("_", "-")
501-
else raise ArgumentError, "Style keys should be Strings or Symbols."
501+
else raise ArgumentError.new("Style keys should be Strings or Symbols.")
502502
end
503503

504504
value = __styles__(v)
@@ -520,7 +520,7 @@ def __styles__(s)
520520
end
521521
end
522522

523-
style.end_with?(";") ? style : style + ";"
523+
style.end_with?(";") ? style : "#{style};"
524524
end
525525
end
526526
end

lib/phlex/testing/view_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
module Phlex::Testing
44
module ViewHelper
5-
def render(view, &block)
5+
def render(view, &)
66
if view.is_a?(Class) && view < Phlex::SGML
77
view = view.new
88
end
99

10-
view.call(view_context:, &block)
10+
view.call(view_context:, &)
1111
end
1212

1313
def view_context

lib/phlex/unbuffered.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def respond_to_missing?(...)
2121
@object.respond_to?(...)
2222
end
2323

24-
def method_missing(name, *args, **kwargs, &block)
24+
def method_missing(name, ...)
2525
if @object.respond_to?(name)
2626

2727
__class__.define_method(name) do |*a, **k, &b|
2828
@object.capture { @object.public_send(name, *a, **k, &b) }
2929
end
3030

3131
# Now we've defined this missing method, we can call it.
32-
__public_send__(name, *args, **kwargs, &block)
32+
__public_send__(name, ...)
3333
else
3434
super
3535
end
@@ -40,8 +40,8 @@ def call(...)
4040
@object.call(...)
4141
end
4242

43-
def send(...)
44-
@object.send(...)
43+
def __send__(...)
44+
@object.__send__(...)
4545
end
4646

4747
def public_send(...)

quickdraw/csv.test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def render_headers?
2323
test "renders a CSV" do
2424
products = [
2525
Product.new("Apple", 1.00),
26-
Product.new("Banana", 2.00)
26+
Product.new("Banana", 2.00),
2727
]
2828

2929
csv = Example.new(products).call
@@ -68,7 +68,7 @@ def render_headers?
6868
test "renders without headers" do
6969
products = [
7070
Product.new("Apple", 1.00),
71-
Product.new("Banana", 2.00)
71+
Product.new("Banana", 2.00),
7272
]
7373

7474
csv = ExampleWithoutHeaders.new(products).call

quickdraw/helpers/mix.test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
test "supports hash concatenation" do
2626
output = mix(
2727
{ data: { controller: "foo" } },
28-
{ data: { controller: "bar" } }
28+
{ data: { controller: "bar" } },
2929
)
3030

3131
expect(output) == { data: { controller: "foo bar" } }
@@ -34,7 +34,7 @@
3434
test "supports hash override" do
3535
output = mix(
3636
{ data: { controller: "foo" } },
37-
{ data!: { controller: "bar" } }
37+
{ data!: { controller: "bar" } },
3838
)
3939

4040
expect(output) == { data: { controller: "bar" } }

quickdraw/sgml/attributes.test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

3-
{div: "div"}.each do |method_name, tag|
3+
{ div: "div" }.each do |method_name, tag|
44
describe "<#{tag}> with class array attribute" do
55
example = Class.new(Phlex::HTML) do
66
define_method :view_template do
7-
send(method_name, class: ["class", nil, inactive: false, truthy: 1]) { "content" }
7+
__send__(method_name, class: ["class", nil, inactive: false, truthy: 1]) { "content" }
88
end
99
end
1010

@@ -16,7 +16,7 @@
1616
describe "<#{tag}> with class hash attribute" do
1717
example = Class.new(Phlex::HTML) do
1818
define_method :view_template do
19-
send(method_name, class: {class: true, inactive: false, truthy: 1}) { "content" }
19+
__send__(method_name, class: { class: true, inactive: false, truthy: 1 }) { "content" }
2020
end
2121
end
2222

@@ -28,7 +28,7 @@
2828
describe "<#{tag}> with style array attribute" do
2929
example = Class.new(Phlex::HTML) do
3030
define_method :view_template do
31-
send(method_name, style: ["color: red", nil, font_weight: "bold", opacity: 0]) { "content" }
31+
__send__(method_name, style: ["color: red", nil, font_weight: "bold", opacity: 0]) { "content" }
3232
end
3333
end
3434

@@ -40,7 +40,7 @@
4040
describe "<#{tag}> with style hash attribute" do
4141
example = Class.new(Phlex::HTML) do
4242
define_method :view_template do
43-
send(method_name, style: {color: "red", word_break: nil, font_weight: "bold"}) { "content" }
43+
__send__(method_name, style: { color: "red", word_break: nil, font_weight: "bold" }) { "content" }
4444
end
4545
end
4646

quickdraw/sgml/render_enumerable.test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# frozen_string_literal: true
22

33
class Card < Phlex::HTML
4-
def view_template(&block)
5-
article(&block)
4+
def view_template(&)
5+
article(&)
66
end
77
end
88

99
class WithoutBlock < Phlex::HTML
1010
def initialize
1111
@cards = [
1212
Card.new,
13-
Card.new
13+
Card.new,
1414
]
1515
end
1616

0 commit comments

Comments
 (0)