Skip to content

Commit

Permalink
Merge pull request #56 from ParentSquare/update-rubocop-and-gemspec
Browse files Browse the repository at this point in the history
Update rubocop cleanup gemspec
  • Loading branch information
justinhoward authored Jul 29, 2022
2 parents 9043ccd + d74204f commit ef57573
Show file tree
Hide file tree
Showing 26 changed files with 223 additions and 183 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ jobs:
strategy:
fail-fast: false
matrix:
redis: [4]
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, jruby-9.2.10, truffleruby-20.2.0]
ruby: ['2.5', '2.6', '2.7', '3.0', jruby-9.3.6.0, truffleruby-22.2.0]
bundler: [default]
redis: ['4']
include:
- redis: 3
ruby: 2.7
- ruby: '2.7'
bundler: 'default'
redis: '3'
- ruby: '2.3'
bundler: '1'
redis: '4'
- ruby: '2.4'
bundler: '1'
redis: '4'
services:
redis:
image: redis
Expand All @@ -28,12 +36,13 @@ jobs:
- 9200:9200
options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=3s --health-timeout=5s --health-retries=20
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
env:
REDIS_VERSION: ${{ matrix.redis }}
with:
ruby-version: ${{ matrix.ruby }}
bundler: ${{ matrix.bundler }}
bundler-cache: true
- run: bundle exec rubocop
if: matrix.ruby == '2.7'
Expand Down
206 changes: 116 additions & 90 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,119 @@ require:
AllCops:
TargetRubyVersion: 2.3

Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation

Layout/CaseIndentation:
EnforcedStyle: end

Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/LineLength:
Max: 120

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/RescueEnsureAlignment:
Enabled: false

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

RSpec/ExampleLength:
Enabled: false

RSpec/FilePath:
Enabled: false

RSpec/NamedSubject:
Enabled: false

RSpec/MessageSpies:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/SubjectStub:
Enabled: false

Metrics/AbcSize:
Max: 35

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Max: 30

Naming/MethodParameterName:
MinNameLength: 1

Style/Documentation:
Enabled: false

Style/EmptyMethod:
EnforcedStyle: expanded

Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always

Style/GuardClause:
Enabled: false

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false

Style/IfUnlessModifier:
Enabled: false
Gemspec/DeprecatedAttributeAssignment: { Enabled: true }
Gemspec/RequireMFA: { Enabled: true }

Layout/ArgumentAlignment: { EnforcedStyle: with_fixed_indentation }
Layout/CaseIndentation: { EnforcedStyle: end }
Layout/EndAlignment: { EnforcedStyleAlignWith: start_of_line }
Layout/FirstArgumentIndentation: { EnforcedStyle: consistent }
Layout/FirstArrayElementIndentation: { EnforcedStyle: consistent }
Layout/FirstHashElementIndentation: { EnforcedStyle: consistent }
Layout/LineContinuationLeadingSpace: { Enabled: true }
Layout/LineContinuationSpacing: { Enabled: true }
Layout/LineEndStringConcatenationIndentation: { Enabled: true }
Layout/LineLength: { Max: 120 }
Layout/MultilineMethodCallIndentation: { EnforcedStyle: indented }
Layout/ParameterAlignment: { EnforcedStyle: with_fixed_indentation }
Layout/RescueEnsureAlignment: { Enabled: false }
Layout/SpaceBeforeBrackets: { Enabled: true }

Lint/AmbiguousAssignment: { Enabled: true }
Lint/AmbiguousOperatorPrecedence: { Enabled: true }
Lint/AmbiguousRange: { Enabled: true }
Lint/ConstantOverwrittenInRescue: { Enabled: true }
Lint/DeprecatedConstants: { Enabled: true }
Lint/DuplicateBranch: { Enabled: true }
Lint/DuplicateRegexpCharacterClassElement: { Enabled: true }
Lint/EmptyBlock: { Enabled: true }
Lint/EmptyClass: { Enabled: true }
Lint/EmptyInPattern: { Enabled: true }
Lint/IncompatibleIoSelectWithFiberScheduler: { Enabled: true }
Lint/LambdaWithoutLiteralBlock: { Enabled: true }
Lint/NoReturnInBeginEndBlocks: { Enabled: true }
Lint/NonAtomicFileOperation: { Enabled: true }
Lint/NumberedParameterAssignment: { Enabled: true }
Lint/OrAssignmentToConstant: { Enabled: true }
Lint/RaiseException: { Enabled: true }
Lint/RedundantDirGlobSort: { Enabled: true }
Lint/RefinementImportMethods: { Enabled: true }
Lint/RequireRangeParentheses: { Enabled: true }
Lint/RequireRelativeSelfPath: { Enabled: true }
Lint/StructNewOverride: { Enabled: true }
Lint/SymbolConversion: { Enabled: true }
Lint/ToEnumArguments: { Enabled: true }
Lint/TripleQuotes: { Enabled: true }
Lint/UnexpectedBlockArity: { Enabled: true }
Lint/UnmodifiedReduceAccumulator: { Enabled: true }
Lint/UselessRuby2Keywords: { Enabled: true }

RSpec/BeEq: { Enabled: true }
RSpec/BeNil: { Enabled: true }
RSpec/Capybara/SpecificMatcher: { Enabled: true }
RSpec/ChangeByZero: { Enabled: true }
RSpec/ExampleLength: { Enabled: false }
RSpec/ExcessiveDocstringSpacing: { Enabled: true }
RSpec/FactoryBot/SyntaxMethods: { Enabled: true }
RSpec/FilePath: { Enabled: false }
RSpec/IdenticalEqualityAssertion: { Enabled: true }
RSpec/MessageSpies: { Enabled: false }
RSpec/MultipleExpectations: { Enabled: false }
RSpec/MultipleMemoizedHelpers: { Enabled: false }
RSpec/NamedSubject: { Enabled: false }
RSpec/Rails/AvoidSetupHook: { Enabled: true }
RSpec/Rails/HaveHttpStatus: { Enabled: true }
RSpec/SubjectDeclaration: { Enabled: true }
RSpec/SubjectStub: { Enabled: false }
RSpec/VerifiedDoubleReference: { Enabled: true }

Metrics/AbcSize: { Max: 40 }
Metrics/BlockLength: { Enabled: false }
Metrics/CyclomaticComplexity: { Enabled: false }
Metrics/MethodLength: { Max: 30 }
Metrics/PerceivedComplexity: { Enabled: false }

Naming/BlockForwarding: { Enabled: true }
Naming/MethodParameterName: { MinNameLength: 1 }

Security/CompoundHash: { Enabled: true }
Security/IoMethods: { Enabled: true }

Style/ArgumentsForwarding: { Enabled: true }
Style/CollectionCompact: { Enabled: true }
Style/DocumentDynamicEvalDefinition: { Enabled: true }
Style/Documentation: { Enabled: false }
Style/EmptyHeredoc: { Enabled: true }
Style/EmptyMethod: { EnforcedStyle: expanded }
Style/EndlessMethod: { Enabled: true }
Style/EnvHome: { Enabled: true }
Style/FetchEnvVar: { Enabled: true }
Style/FileRead: { Enabled: true }
Style/FileWrite: { Enabled: true }
Style/FrozenStringLiteralComment: { Enabled: true, EnforcedStyle: always }
Style/GuardClause: { Enabled: false }
Style/HashConversion: { Enabled: true }
Style/HashEachMethods: { Enabled: true }
Style/HashExcept: { Enabled: true }
Style/HashTransformKeys: { Enabled: false }
Style/HashTransformValues: { Enabled: false }
Style/IfUnlessModifier: { Enabled: false }
Style/IfWithBooleanLiteralBranches: { Enabled: true }
Style/InPatternThen: { Enabled: true }
Style/MapCompactWithConditionalBlock: { Enabled: true }
Style/MapToHash: { Enabled: true }
Style/MultilineInPatternThen: { Enabled: true }
Style/NegatedIfElseCondition: { Enabled: true }
Style/NestedFileDirname: { Enabled: true }
Style/NilLambda: { Enabled: true }
Style/NumberedParameters: { Enabled: true }
Style/NumberedParametersLimit: { Enabled: true }
Style/ObjectThen: { Enabled: true }
Style/OpenStructUse: { Enabled: true }
Style/QuotedSymbols: { Enabled: true }
Style/RedundantArgument: { Enabled: true }
Style/RedundantInitialize: { Enabled: true }
Style/RedundantSelfAssignmentBranch: { Enabled: true }
Style/SelectByRegexp: { Enabled: true }
Style/StringChars: { Enabled: true }
Style/SwapValues: { Enabled: true }
6 changes: 6 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
rules:
braces:
min-spaces-inside: 1
max-spaces-inside: 1

6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ gemspec
not_jruby = %i[ruby mingw x64_mingw].freeze

gem 'activesupport', '>= 4.2'
gem 'bundler', '>= 1.17', '< 3'
gem 'byebug', platforms: not_jruby
# Open source licensed elasticsearch
gem 'elasticsearch', '> 7', '< 7.14'
Expand All @@ -27,6 +26,11 @@ gem 'simplecov', '>= 0.17.1'
gem 'simplecov-lcov', '~> 0.7', '< 0.8'
gem 'yard', '~> 0.9.25', platforms: not_jruby

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
gem 'rubocop', '~> 1.32.0'
gem 'rubocop-rspec', '~> 2.12'
end

if ENV['REDIS_VERSION']
gem 'redis', "~> #{ENV['REDIS_VERSION']}"
end
13 changes: 6 additions & 7 deletions faulty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ Gem::Specification.new do |spec|
spec.authors = ['Justin Howard']
spec.email = ['[email protected]']
spec.licenses = ['MIT']

spec.summary = 'Fault-tolerance tools for ruby based on circuit-breakers'
spec.homepage = 'https://github.com/ParentSquare/faulty'

spec.files = `git ls-files -z`
.split("\x0")
.reject { |f| f.match(%r{^spec/}) }
rubydoc = 'https://www.rubydoc.info/gems'
spec.metadata['rubygems_mfa_required'] = 'true'
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
spec.metadata['documentation_uri'] = "#{rubydoc}/#{spec.name}/#{spec.version}"

spec.files = Dir['lib/**/*.rb', '*.md', '*.txt', '.yardopts']
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.3'
Expand All @@ -29,8 +31,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'json'
spec.add_development_dependency 'redis', '>= 3.0'
spec.add_development_dependency 'rspec', '~> 3.8'
# 0.81 is the last rubocop version with Ruby 2.3 support
spec.add_development_dependency 'rubocop', '0.81.0'
spec.add_development_dependency 'rubocop-rspec', '1.38.1'
spec.add_development_dependency 'timecop', '>= 0.9'
end
6 changes: 2 additions & 4 deletions lib/faulty/circuit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,13 @@ def failure!(status, error)
end
options.notifier.notify(:circuit_failure, circuit: self, status: status, error: error)

opened = if status.half_open?
if status.half_open?
reopen!(error, status.opened_at)
elsif status.fails_threshold?
open!(error)
else
false
end

opened
end

def deprecated_entry?
Expand Down Expand Up @@ -550,7 +548,7 @@ def cache_write(key, value)
# @return [Boolean] true if the cache should be refreshed
def cache_should_refresh?(key)
time = options.cache.read(cache_refresh_key(key.to_s)).to_i
time + (rand * 2 - 1) * options.cache_refresh_jitter < Faulty.current_time
time + (((rand * 2) - 1) * options.cache_refresh_jitter) < Faulty.current_time
end

# Get the next time to refresh the cache when writing to it
Expand Down
2 changes: 1 addition & 1 deletion lib/faulty/deprecation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Faulty
module Deprecation
class << self
# Call to raise errors instead of logging warnings for Faulty deprecations
def raise_errors!(enabled = true)
def raise_errors!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter
@raise_errors = (enabled == true)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/faulty/patch/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ module Base
#
# @yield A block to run inside the circuit
# @return The block return value
def faulty_run
def faulty_run(&block)
faulty_running_key = "faulty_running_#{object_id}"
return yield unless @faulty_circuit
return yield if Thread.current[faulty_running_key]

Thread.current[faulty_running_key] = true
@faulty_circuit.run { yield }
@faulty_circuit.run(&block)
ensure
Thread.current[faulty_running_key] = nil
end
Expand Down
6 changes: 2 additions & 4 deletions lib/faulty/patch/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ def io(&block)
return super unless @faulty_circuit

reply = super
if reply.is_a?(::Redis::CommandError)
if reply.message.start_with?('BUSY')
reply = BusyError.new(reply.message)
end
if reply.is_a?(::Redis::CommandError) && reply.message.start_with?('BUSY')
reply = BusyError.new(reply.message)
end

reply
Expand Down
4 changes: 3 additions & 1 deletion lib/faulty/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class Faulty
:sample_size,
:options,
:stub
) do
)

class Status
include ImmutableOptions

# The allowed state values
Expand Down
Loading

0 comments on commit ef57573

Please sign in to comment.