Skip to content

Commit ef57573

Browse files
authored
Merge pull request #56 from ParentSquare/update-rubocop-and-gemspec
Update rubocop cleanup gemspec
2 parents 9043ccd + d74204f commit ef57573

26 files changed

+223
-183
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
redis: [4]
16-
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, jruby-9.2.10, truffleruby-20.2.0]
15+
ruby: ['2.5', '2.6', '2.7', '3.0', jruby-9.3.6.0, truffleruby-22.2.0]
16+
bundler: [default]
17+
redis: ['4']
1718
include:
18-
- redis: 3
19-
ruby: 2.7
19+
- ruby: '2.7'
20+
bundler: 'default'
21+
redis: '3'
22+
- ruby: '2.3'
23+
bundler: '1'
24+
redis: '4'
25+
- ruby: '2.4'
26+
bundler: '1'
27+
redis: '4'
2028
services:
2129
redis:
2230
image: redis
@@ -28,12 +36,13 @@ jobs:
2836
- 9200:9200
2937
options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=3s --health-timeout=5s --health-retries=20
3038
steps:
31-
- uses: actions/checkout@v2
39+
- uses: actions/checkout@v3
3240
- uses: ruby/setup-ruby@v1
3341
env:
3442
REDIS_VERSION: ${{ matrix.redis }}
3543
with:
3644
ruby-version: ${{ matrix.ruby }}
45+
bundler: ${{ matrix.bundler }}
3746
bundler-cache: true
3847
- run: bundle exec rubocop
3948
if: matrix.ruby == '2.7'

.rubocop.yml

Lines changed: 116 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,119 @@ require:
55
AllCops:
66
TargetRubyVersion: 2.3
77

8-
Layout/ArgumentAlignment:
9-
EnforcedStyle: with_fixed_indentation
10-
11-
Layout/CaseIndentation:
12-
EnforcedStyle: end
13-
14-
Layout/ParameterAlignment:
15-
EnforcedStyle: with_fixed_indentation
16-
17-
Layout/EndAlignment:
18-
EnforcedStyleAlignWith: start_of_line
19-
20-
Layout/FirstArgumentIndentation:
21-
EnforcedStyle: consistent
22-
23-
Layout/FirstArrayElementIndentation:
24-
EnforcedStyle: consistent
25-
26-
Layout/FirstHashElementIndentation:
27-
EnforcedStyle: consistent
28-
29-
Layout/LineLength:
30-
Max: 120
31-
32-
Layout/MultilineMethodCallIndentation:
33-
EnforcedStyle: indented
34-
35-
Layout/RescueEnsureAlignment:
36-
Enabled: false
37-
38-
Lint/RaiseException:
39-
Enabled: true
40-
41-
Lint/StructNewOverride:
42-
Enabled: true
43-
44-
RSpec/ExampleLength:
45-
Enabled: false
46-
47-
RSpec/FilePath:
48-
Enabled: false
49-
50-
RSpec/NamedSubject:
51-
Enabled: false
52-
53-
RSpec/MessageSpies:
54-
Enabled: false
55-
56-
RSpec/MultipleExpectations:
57-
Enabled: false
58-
59-
RSpec/SubjectStub:
60-
Enabled: false
61-
62-
Metrics/AbcSize:
63-
Max: 35
64-
65-
Metrics/BlockLength:
66-
Enabled: false
67-
68-
Metrics/MethodLength:
69-
Max: 30
70-
71-
Naming/MethodParameterName:
72-
MinNameLength: 1
73-
74-
Style/Documentation:
75-
Enabled: false
76-
77-
Style/EmptyMethod:
78-
EnforcedStyle: expanded
79-
80-
Style/FrozenStringLiteralComment:
81-
Enabled: true
82-
EnforcedStyle: always
83-
84-
Style/GuardClause:
85-
Enabled: false
86-
87-
Style/HashEachMethods:
88-
Enabled: true
89-
90-
Style/HashTransformKeys:
91-
Enabled: false
92-
93-
Style/HashTransformValues:
94-
Enabled: false
95-
96-
Style/IfUnlessModifier:
97-
Enabled: false
8+
Gemspec/DeprecatedAttributeAssignment: { Enabled: true }
9+
Gemspec/RequireMFA: { Enabled: true }
10+
11+
Layout/ArgumentAlignment: { EnforcedStyle: with_fixed_indentation }
12+
Layout/CaseIndentation: { EnforcedStyle: end }
13+
Layout/EndAlignment: { EnforcedStyleAlignWith: start_of_line }
14+
Layout/FirstArgumentIndentation: { EnforcedStyle: consistent }
15+
Layout/FirstArrayElementIndentation: { EnforcedStyle: consistent }
16+
Layout/FirstHashElementIndentation: { EnforcedStyle: consistent }
17+
Layout/LineContinuationLeadingSpace: { Enabled: true }
18+
Layout/LineContinuationSpacing: { Enabled: true }
19+
Layout/LineEndStringConcatenationIndentation: { Enabled: true }
20+
Layout/LineLength: { Max: 120 }
21+
Layout/MultilineMethodCallIndentation: { EnforcedStyle: indented }
22+
Layout/ParameterAlignment: { EnforcedStyle: with_fixed_indentation }
23+
Layout/RescueEnsureAlignment: { Enabled: false }
24+
Layout/SpaceBeforeBrackets: { Enabled: true }
25+
26+
Lint/AmbiguousAssignment: { Enabled: true }
27+
Lint/AmbiguousOperatorPrecedence: { Enabled: true }
28+
Lint/AmbiguousRange: { Enabled: true }
29+
Lint/ConstantOverwrittenInRescue: { Enabled: true }
30+
Lint/DeprecatedConstants: { Enabled: true }
31+
Lint/DuplicateBranch: { Enabled: true }
32+
Lint/DuplicateRegexpCharacterClassElement: { Enabled: true }
33+
Lint/EmptyBlock: { Enabled: true }
34+
Lint/EmptyClass: { Enabled: true }
35+
Lint/EmptyInPattern: { Enabled: true }
36+
Lint/IncompatibleIoSelectWithFiberScheduler: { Enabled: true }
37+
Lint/LambdaWithoutLiteralBlock: { Enabled: true }
38+
Lint/NoReturnInBeginEndBlocks: { Enabled: true }
39+
Lint/NonAtomicFileOperation: { Enabled: true }
40+
Lint/NumberedParameterAssignment: { Enabled: true }
41+
Lint/OrAssignmentToConstant: { Enabled: true }
42+
Lint/RaiseException: { Enabled: true }
43+
Lint/RedundantDirGlobSort: { Enabled: true }
44+
Lint/RefinementImportMethods: { Enabled: true }
45+
Lint/RequireRangeParentheses: { Enabled: true }
46+
Lint/RequireRelativeSelfPath: { Enabled: true }
47+
Lint/StructNewOverride: { Enabled: true }
48+
Lint/SymbolConversion: { Enabled: true }
49+
Lint/ToEnumArguments: { Enabled: true }
50+
Lint/TripleQuotes: { Enabled: true }
51+
Lint/UnexpectedBlockArity: { Enabled: true }
52+
Lint/UnmodifiedReduceAccumulator: { Enabled: true }
53+
Lint/UselessRuby2Keywords: { Enabled: true }
54+
55+
RSpec/BeEq: { Enabled: true }
56+
RSpec/BeNil: { Enabled: true }
57+
RSpec/Capybara/SpecificMatcher: { Enabled: true }
58+
RSpec/ChangeByZero: { Enabled: true }
59+
RSpec/ExampleLength: { Enabled: false }
60+
RSpec/ExcessiveDocstringSpacing: { Enabled: true }
61+
RSpec/FactoryBot/SyntaxMethods: { Enabled: true }
62+
RSpec/FilePath: { Enabled: false }
63+
RSpec/IdenticalEqualityAssertion: { Enabled: true }
64+
RSpec/MessageSpies: { Enabled: false }
65+
RSpec/MultipleExpectations: { Enabled: false }
66+
RSpec/MultipleMemoizedHelpers: { Enabled: false }
67+
RSpec/NamedSubject: { Enabled: false }
68+
RSpec/Rails/AvoidSetupHook: { Enabled: true }
69+
RSpec/Rails/HaveHttpStatus: { Enabled: true }
70+
RSpec/SubjectDeclaration: { Enabled: true }
71+
RSpec/SubjectStub: { Enabled: false }
72+
RSpec/VerifiedDoubleReference: { Enabled: true }
73+
74+
Metrics/AbcSize: { Max: 40 }
75+
Metrics/BlockLength: { Enabled: false }
76+
Metrics/CyclomaticComplexity: { Enabled: false }
77+
Metrics/MethodLength: { Max: 30 }
78+
Metrics/PerceivedComplexity: { Enabled: false }
79+
80+
Naming/BlockForwarding: { Enabled: true }
81+
Naming/MethodParameterName: { MinNameLength: 1 }
82+
83+
Security/CompoundHash: { Enabled: true }
84+
Security/IoMethods: { Enabled: true }
85+
86+
Style/ArgumentsForwarding: { Enabled: true }
87+
Style/CollectionCompact: { Enabled: true }
88+
Style/DocumentDynamicEvalDefinition: { Enabled: true }
89+
Style/Documentation: { Enabled: false }
90+
Style/EmptyHeredoc: { Enabled: true }
91+
Style/EmptyMethod: { EnforcedStyle: expanded }
92+
Style/EndlessMethod: { Enabled: true }
93+
Style/EnvHome: { Enabled: true }
94+
Style/FetchEnvVar: { Enabled: true }
95+
Style/FileRead: { Enabled: true }
96+
Style/FileWrite: { Enabled: true }
97+
Style/FrozenStringLiteralComment: { Enabled: true, EnforcedStyle: always }
98+
Style/GuardClause: { Enabled: false }
99+
Style/HashConversion: { Enabled: true }
100+
Style/HashEachMethods: { Enabled: true }
101+
Style/HashExcept: { Enabled: true }
102+
Style/HashTransformKeys: { Enabled: false }
103+
Style/HashTransformValues: { Enabled: false }
104+
Style/IfUnlessModifier: { Enabled: false }
105+
Style/IfWithBooleanLiteralBranches: { Enabled: true }
106+
Style/InPatternThen: { Enabled: true }
107+
Style/MapCompactWithConditionalBlock: { Enabled: true }
108+
Style/MapToHash: { Enabled: true }
109+
Style/MultilineInPatternThen: { Enabled: true }
110+
Style/NegatedIfElseCondition: { Enabled: true }
111+
Style/NestedFileDirname: { Enabled: true }
112+
Style/NilLambda: { Enabled: true }
113+
Style/NumberedParameters: { Enabled: true }
114+
Style/NumberedParametersLimit: { Enabled: true }
115+
Style/ObjectThen: { Enabled: true }
116+
Style/OpenStructUse: { Enabled: true }
117+
Style/QuotedSymbols: { Enabled: true }
118+
Style/RedundantArgument: { Enabled: true }
119+
Style/RedundantInitialize: { Enabled: true }
120+
Style/RedundantSelfAssignmentBranch: { Enabled: true }
121+
Style/SelectByRegexp: { Enabled: true }
122+
Style/StringChars: { Enabled: true }
123+
Style/SwapValues: { Enabled: true }

.yamllint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
rules:
3+
braces:
4+
min-spaces-inside: 1
5+
max-spaces-inside: 1
6+

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ gemspec
1111
not_jruby = %i[ruby mingw x64_mingw].freeze
1212

1313
gem 'activesupport', '>= 4.2'
14-
gem 'bundler', '>= 1.17', '< 3'
1514
gem 'byebug', platforms: not_jruby
1615
# Open source licensed elasticsearch
1716
gem 'elasticsearch', '> 7', '< 7.14'
@@ -27,6 +26,11 @@ gem 'simplecov', '>= 0.17.1'
2726
gem 'simplecov-lcov', '~> 0.7', '< 0.8'
2827
gem 'yard', '~> 0.9.25', platforms: not_jruby
2928

29+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
30+
gem 'rubocop', '~> 1.32.0'
31+
gem 'rubocop-rspec', '~> 2.12'
32+
end
33+
3034
if ENV['REDIS_VERSION']
3135
gem 'redis', "~> #{ENV['REDIS_VERSION']}"
3236
end

faulty.gemspec

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ Gem::Specification.new do |spec|
1010
spec.authors = ['Justin Howard']
1111
spec.email = ['[email protected]']
1212
spec.licenses = ['MIT']
13-
1413
spec.summary = 'Fault-tolerance tools for ruby based on circuit-breakers'
1514
spec.homepage = 'https://github.com/ParentSquare/faulty'
1615

17-
spec.files = `git ls-files -z`
18-
.split("\x0")
19-
.reject { |f| f.match(%r{^spec/}) }
16+
rubydoc = 'https://www.rubydoc.info/gems'
17+
spec.metadata['rubygems_mfa_required'] = 'true'
18+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
19+
spec.metadata['documentation_uri'] = "#{rubydoc}/#{spec.name}/#{spec.version}"
20+
21+
spec.files = Dir['lib/**/*.rb', '*.md', '*.txt', '.yardopts']
2022
spec.require_paths = ['lib']
2123

2224
spec.required_ruby_version = '>= 2.3'
@@ -29,8 +31,5 @@ Gem::Specification.new do |spec|
2931
spec.add_development_dependency 'json'
3032
spec.add_development_dependency 'redis', '>= 3.0'
3133
spec.add_development_dependency 'rspec', '~> 3.8'
32-
# 0.81 is the last rubocop version with Ruby 2.3 support
33-
spec.add_development_dependency 'rubocop', '0.81.0'
34-
spec.add_development_dependency 'rubocop-rspec', '1.38.1'
3534
spec.add_development_dependency 'timecop', '>= 0.9'
3635
end

lib/faulty/circuit.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,13 @@ def failure!(status, error)
462462
end
463463
options.notifier.notify(:circuit_failure, circuit: self, status: status, error: error)
464464

465-
opened = if status.half_open?
465+
if status.half_open?
466466
reopen!(error, status.opened_at)
467467
elsif status.fails_threshold?
468468
open!(error)
469469
else
470470
false
471471
end
472-
473-
opened
474472
end
475473

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

556554
# Get the next time to refresh the cache when writing to it

lib/faulty/deprecation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Faulty
55
module Deprecation
66
class << self
77
# Call to raise errors instead of logging warnings for Faulty deprecations
8-
def raise_errors!(enabled = true)
8+
def raise_errors!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter
99
@raise_errors = (enabled == true)
1010
end
1111

lib/faulty/patch/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ module Base
3131
#
3232
# @yield A block to run inside the circuit
3333
# @return The block return value
34-
def faulty_run
34+
def faulty_run(&block)
3535
faulty_running_key = "faulty_running_#{object_id}"
3636
return yield unless @faulty_circuit
3737
return yield if Thread.current[faulty_running_key]
3838

3939
Thread.current[faulty_running_key] = true
40-
@faulty_circuit.run { yield }
40+
@faulty_circuit.run(&block)
4141
ensure
4242
Thread.current[faulty_running_key] = nil
4343
end

lib/faulty/patch/redis.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ def io(&block)
8181
return super unless @faulty_circuit
8282

8383
reply = super
84-
if reply.is_a?(::Redis::CommandError)
85-
if reply.message.start_with?('BUSY')
86-
reply = BusyError.new(reply.message)
87-
end
84+
if reply.is_a?(::Redis::CommandError) && reply.message.start_with?('BUSY')
85+
reply = BusyError.new(reply.message)
8886
end
8987

9088
reply

lib/faulty/status.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class Faulty
3838
:sample_size,
3939
:options,
4040
:stub
41-
) do
41+
)
42+
43+
class Status
4244
include ImmutableOptions
4345

4446
# The allowed state values

0 commit comments

Comments
 (0)