Skip to content

Commit

Permalink
RuboCop linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny committed Mar 10, 2024
1 parent 099053e commit f4a3a03
Show file tree
Hide file tree
Showing 37 changed files with 244 additions and 488 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
bundler-cache: true

- name: RuboCop
run: bin/rubocop-gradual --check
run: NO_GRADUAL=1 bin/rubocop --format github
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Gemspec/RequiredRubyVersion:

# Layout

Layout/ArgumentAlignment:
EnforcedStyle: with_first_argument

# Errors out on Ruby 3.1.3
Layout/BlockAlignment:
Enabled: false
Expand Down Expand Up @@ -98,18 +101,37 @@ Style/Documentation:
Style/ExponentialNotation:
Enabled: true

Layout/IndentationConsistency:
Exclude:
- README.md

Style/MethodCallWithArgsParentheses:
Enabled: false

# Allow using the second parameter as a boolean.
Style/OptionalBooleanParameter:
Enabled: false

Style/SingleLineMethods:
AllowIfMethodIsEmpty: true

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
Exclude:
- README.md

Style/DoubleNegation:
Enabled: false

Style/StabbyLambdaParentheses:
EnforcedStyle: require_no_parentheses

# ThreadSafety

ThreadSafety/InstanceVariableInClassMethod:
Enabled: false
307 changes: 0 additions & 307 deletions .rubocop_gradual.lock

This file was deleted.

19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ PATH
remote: .
specs:
service_actor (3.7.0)
zeitwerk
zeitwerk (>= 1.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
code-scanning-rubocop (0.6.1)
rubocop (~> 1.0)
coderay (1.1.3)
diff-lcs (1.5.1)
diffy (3.4.2)
Expand Down Expand Up @@ -118,16 +120,17 @@ PLATFORMS
ruby

DEPENDENCIES
interactor
pry
rake
rspec
code-scanning-rubocop
interactor (>= 3.0)
pry (>= 0.12)
rake (>= 13.0)
rspec (>= 3.0)
rspec-block_is_expected (>= 1.0)
rubocop-gradual (>= 0.3)
rubocop-lts (~> 18.2)
rubocop-performance
rubocop-rake
rubocop-rspec
rubocop-performance (>= 1.0)
rubocop-rake (>= 0.1)
rubocop-rspec (>= 2.0)
service_actor!

BUNDLED WITH
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class BuildGreeting < Actor
input :adjective, default: "wonderful"
input :length_of_time, default: -> { ["day", "week", "month"].sample }
input :article,
default: -> context { context.adjective =~ /^aeiou/ ? 'an' : 'a' }
default: -> context { context.adjective.match?(/^aeiou/) ? "an" : "a" }

output :greeting

Expand Down Expand Up @@ -475,7 +475,7 @@ end
is: [TrueClass, FalseClass],
message: (lambda do |input_key:, expected_type:, given_type:, **|
"Wrong type \"#{given_type}\" for \"#{input_key}\". " \
"Expected: \"#{expected_type}\""
"Expected: \"#{expected_type}\""
end)
}
end
Expand Down
18 changes: 9 additions & 9 deletions lib/service_actor/attributable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
# output :name
# end
module ServiceActor::Attributable
def self.included(base)
base.extend(ClassMethods)
class << self
def included(base)
base.extend(ClassMethods)
end
end

module ClassMethods
Expand All @@ -26,10 +28,8 @@ def input(name, **arguments)
result[name]
end

# For avoid method redefined warning messages.
alias_method name, name if method_defined?(name)

protected name
# To avoid method redefined warning messages.
protected alias_method(name, name) if method_defined?(name)
end

def inputs
Expand All @@ -42,12 +42,12 @@ def output(name, **arguments)
define_method(name) do
result[name]
end
protected name

define_method("#{name}=") do |value|
define_method(:"#{name}=") do |value|
result[name] = value
end

protected name, "#{name}="
protected :"#{name}="
end

def outputs
Expand Down
22 changes: 12 additions & 10 deletions lib/service_actor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
require "service_actor/support/loader"

module ServiceActor::Base
def self.included(base)
# Essential mechanics
base.include(ServiceActor::Core)
base.include(ServiceActor::Configurable)
base.include(ServiceActor::Attributable)
base.include(ServiceActor::Playable)
class << self
def included(base)
# Essential mechanics
base.include(ServiceActor::Core)
base.include(ServiceActor::Configurable)
base.include(ServiceActor::Attributable)
base.include(ServiceActor::Playable)

# Extra concerns
base.include(ServiceActor::Checkable)
base.include(ServiceActor::Defaultable)
base.include(ServiceActor::Failable)
# Extra concerns
base.include(ServiceActor::Checkable)
base.include(ServiceActor::Defaultable)
base.include(ServiceActor::Failable)
end
end
end
10 changes: 6 additions & 4 deletions lib/service_actor/checkable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module ServiceActor::Checkable
def self.included(base)
base.prepend(PrependedMethods)
class << self
def included(base)
base.prepend(PrependedMethods)
end
end

module PrependedMethods
Expand All @@ -11,7 +13,7 @@ module PrependedMethods
ServiceActor::Checks::MustCheck,
ServiceActor::Checks::InclusionCheck,
ServiceActor::Checks::NilCheck,
ServiceActor::Checks::DefaultCheck
ServiceActor::Checks::DefaultCheck,
].freeze
private_constant :CHECK_CLASSES

Expand All @@ -30,7 +32,7 @@ def _call
# rubocop:disable Metrics/MethodLength
def service_actor_checks_for(origin)
check_classes = CHECK_CLASSES.select { _1.applicable_to_origin?(origin) }
self.class.public_send("#{origin}s").each do |input_key, input_options|
self.class.public_send(:"#{origin}s").each do |input_key, input_options|
input_options.each do |check_name, check_conditions|
check_classes.each do |check_class|
argument_errors = check_class.check(
Expand Down
6 changes: 4 additions & 2 deletions lib/service_actor/checks/base.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

class ServiceActor::Checks::Base
def self.applicable_to_origin?(_origin)
true
class << self
def applicable_to_origin?(_origin)
true
end
end

def initialize
Expand Down
22 changes: 12 additions & 10 deletions lib/service_actor/checks/default_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
# }
# end
class ServiceActor::Checks::DefaultCheck < ServiceActor::Checks::Base
def self.applicable_to_origin?(origin)
origin == :input
end
class << self
def applicable_to_origin?(origin)
origin == :input
end

def self.check(result:, input_key:, input_options:, actor:, **)
new(
result: result,
input_key: input_key,
input_options: input_options,
actor: actor,
).check
def check(result:, input_key:, input_options:, actor:, **)
new(
result: result,
input_key: input_key,
input_options: input_options,
actor: actor,
).check
end
end

def initialize(result:, input_key:, input_options:, actor:)
Expand Down
22 changes: 12 additions & 10 deletions lib/service_actor/checks/inclusion_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ class ServiceActor::Checks::InclusionCheck < ServiceActor::Checks::Base
DEFAULT_MESSAGE = lambda do |input_key:, actor:, inclusion_in:, value:|
"The \"#{input_key}\" input must be included " \
"in #{inclusion_in.inspect} on \"#{actor}\" " \
"instead of #{value.inspect}"
"instead of #{value.inspect}"
end

private_constant :DEFAULT_MESSAGE

def self.check(check_name:, input_key:, actor:, conditions:, result:, **) # rubocop:disable Metrics/ParameterLists
# DEPRECATED: `in` is deprecated in favor of `inclusion`.
return unless %i[inclusion in].include?(check_name)
class << self
def check(check_name:, input_key:, actor:, conditions:, result:, **)
# DEPRECATED: `in` is deprecated in favor of `inclusion`.
return unless %i[inclusion in].include?(check_name)

new(
input_key: input_key,
actor: actor,
inclusion: conditions,
value: result[input_key],
).check
new(
input_key: input_key,
actor: actor,
inclusion: conditions,
value: result[input_key],
).check
end
end

def initialize(input_key:, actor:, inclusion:, value:)
Expand Down
18 changes: 10 additions & 8 deletions lib/service_actor/checks/must_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ class ServiceActor::Checks::MustCheck < ServiceActor::Checks::Base

private_constant :DEFAULT_MESSAGE

def self.check(check_name:, input_key:, actor:, conditions:, result:, **) # rubocop:disable Metrics/ParameterLists
return unless check_name == :must
class << self
def check(check_name:, input_key:, actor:, conditions:, result:, **)
return unless check_name == :must

new(
input_key: input_key,
actor: actor,
nested_checks: conditions,
value: result[input_key],
).check
new(
input_key: input_key,
actor: actor,
nested_checks: conditions,
value: result[input_key],
).check
end
end

def initialize(input_key:, actor:, nested_checks:, value:)
Expand Down
36 changes: 19 additions & 17 deletions lib/service_actor/checks/nil_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ class ServiceActor::Checks::NilCheck < ServiceActor::Checks::Base

private_constant :DEFAULT_MESSAGE

def self.check( # rubocop:disable Metrics/ParameterLists
origin:,
input_key:,
input_options:,
actor:,
conditions:,
result:,
**
) # do
new(
origin: origin,
input_key: input_key,
input_options: input_options,
actor: actor,
allow_nil: conditions,
value: result[input_key],
).check
class << self
def check(
origin:,
input_key:,
input_options:,
actor:,
conditions:,
result:,
**
) # do
new(
origin: origin,
input_key: input_key,
input_options: input_options,
actor: actor,
allow_nil: conditions,
value: result[input_key],
).check
end
end

def initialize( # rubocop:disable Metrics/ParameterLists
Expand Down
Loading

0 comments on commit f4a3a03

Please sign in to comment.