Skip to content

Commit 7997911

Browse files
authored
Added rubocop for code style consistency (#115)
* Added rubocop (and rubocop-rspec, rubocop-rake) for code style consistency Auto-generated the `.rubocop.yml' file to follow existing styles with: rubocop --auto-gen-config --exclude-limit 0 Added running rubocop to github action script. * Manually disabled a few rubocop cops that depend on arbitrarily chosen lengths * Enabled some rubocop cops and fixed related warnings Chose cops that were very easy to update the code to adhere to and, in some cases, relate to preventing bugs. Mostly avoided cops that involve more person code style preferences (e.g. spacing, alignment, naming).
1 parent f06f85f commit 7997911

File tree

14 files changed

+279
-36
lines changed

14 files changed

+279
-36
lines changed

.github/workflows/ruby.yml

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ jobs:
3939
RAILS_VERSION: "${{ matrix.rails_version }}"
4040
- name: Install Graphviz
4141
run: sudo apt-get install graphviz
42+
- name: Run code lint
43+
run: bundle exec rubocop
44+
env:
45+
RAILS_VERSION: "${{ matrix.rails_version }}"
4246
- name: Run tests
4347
run: bundle exec rspec
4448
env:

.rubocop.yml

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
require:
2+
- rubocop-rake
3+
- rubocop-rspec
4+
5+
AllCops:
6+
NewCops: disable
7+
8+
Gemspec/OrderedDependencies:
9+
Enabled: false
10+
11+
Layout/ArgumentAlignment:
12+
Enabled: false
13+
14+
Layout/CaseIndentation:
15+
Enabled: false
16+
17+
Layout/EmptyLinesAroundBlockBody:
18+
Enabled: false
19+
20+
Layout/ExtraSpacing:
21+
Enabled: false
22+
23+
Layout/FirstHashElementIndentation:
24+
Enabled: false
25+
26+
Layout/HashAlignment:
27+
Enabled: false
28+
29+
Layout/SpaceAroundEqualsInParameterDefault:
30+
Enabled: false
31+
32+
Layout/SpaceAroundOperators:
33+
Enabled: false
34+
35+
Layout/SpaceBeforeBlockBraces:
36+
Enabled: false
37+
38+
Layout/SpaceInsideBlockBraces:
39+
Enabled: false
40+
41+
Layout/SpaceInsideHashLiteralBraces:
42+
Enabled: false
43+
44+
Lint/ConstantDefinitionInBlock:
45+
Exclude:
46+
- spec/**/*
47+
48+
Lint/RedundantSplatExpansion:
49+
Enabled: false
50+
51+
Lint/ToJSON:
52+
Enabled: false
53+
54+
Lint/UnusedBlockArgument:
55+
Enabled: false
56+
57+
Lint/UnusedMethodArgument:
58+
Enabled: false
59+
60+
Lint/UselessAssignment:
61+
Enabled: false
62+
63+
Metrics/AbcSize:
64+
Enabled: false
65+
66+
Metrics/BlockLength:
67+
Enabled: false
68+
69+
Metrics/ClassLength:
70+
Enabled: false
71+
72+
Metrics/CyclomaticComplexity:
73+
Enabled: false
74+
75+
Metrics/MethodLength:
76+
Enabled: false
77+
78+
Naming/MemoizedInstanceVariableName:
79+
Enabled: false
80+
81+
Naming/PredicateName:
82+
Enabled: false
83+
84+
Naming/RescuedExceptionsVariableName:
85+
Enabled: false
86+
87+
Style/BlockDelimiters:
88+
Enabled: false
89+
90+
Style/ClassVars:
91+
Enabled: false
92+
93+
Style/CombinableLoops:
94+
Enabled: false
95+
96+
Style/ConditionalAssignment:
97+
Enabled: false
98+
99+
Style/Documentation:
100+
Enabled: false
101+
102+
Style/EmptyCaseCondition:
103+
Enabled: false
104+
105+
Style/EmptyMethod:
106+
Enabled: false
107+
108+
Style/FrozenStringLiteralComment:
109+
Enabled: false
110+
111+
Style/GuardClause:
112+
Enabled: false
113+
114+
Style/HashSyntax:
115+
Enabled: false
116+
117+
Style/IfUnlessModifier:
118+
Enabled: false
119+
120+
Style/InverseMethods:
121+
Enabled: false
122+
123+
Style/MethodCallWithoutArgsParentheses:
124+
Enabled: false
125+
126+
Style/NumericLiteralPrefix:
127+
Enabled: false
128+
129+
Style/PercentLiteralDelimiters:
130+
Enabled: false
131+
132+
Style/RaiseArgs:
133+
Enabled: false
134+
135+
Style/SafeNavigation:
136+
Enabled: false
137+
138+
Style/SpecialGlobalVars:
139+
Enabled: false
140+
141+
Style/StringLiterals:
142+
Enabled: false
143+
144+
Style/SymbolProc:
145+
Enabled: false
146+
147+
Style/UnlessElse:
148+
Enabled: false
149+
150+
Style/WordArray:
151+
Enabled: false
152+
153+
Layout/LineLength:
154+
Enabled: false
155+
156+
RSpec/AnyInstance:
157+
Enabled: false
158+
159+
RSpec/BeEq:
160+
Enabled: false
161+
162+
RSpec/ContextWording:
163+
Enabled: false
164+
165+
RSpec/DescribedClass:
166+
Enabled: false
167+
168+
RSpec/EmptyExampleGroup:
169+
Enabled: false
170+
171+
RSpec/EmptyLineAfterExampleGroup:
172+
Enabled: false
173+
174+
RSpec/EmptyLineAfterSubject:
175+
Enabled: false
176+
177+
RSpec/ExampleLength:
178+
Enabled: false
179+
180+
RSpec/ExampleWording:
181+
Enabled: false
182+
183+
RSpec/ExpectChange:
184+
Enabled: false
185+
186+
RSpec/HookArgument:
187+
EnforcedStyle: each
188+
189+
RSpec/LeakyConstantDeclaration:
190+
Enabled: false
191+
192+
RSpec/LetSetup:
193+
Enabled: false
194+
195+
RSpec/MatchArray:
196+
Enabled: false
197+
198+
RSpec/MessageSpies:
199+
EnforcedStyle: receive
200+
201+
RSpec/MultipleExpectations:
202+
Enabled: false
203+
204+
RSpec/MultipleMemoizedHelpers:
205+
Enabled: false
206+
207+
RSpec/NamedSubject:
208+
Enabled: false
209+
210+
RSpec/NestedGroups:
211+
Enabled: false
212+
213+
RSpec/NotToNot:
214+
Enabled: false
215+
216+
RSpec/PredicateMatcher:
217+
Enabled: false
218+
219+
RSpec/ReceiveCounts:
220+
Enabled: false
221+
222+
RSpec/SpecFilePathFormat:
223+
Enabled: false
224+
225+
RSpec/StubbedMock:
226+
Enabled: false
227+
228+
RSpec/SubjectStub:
229+
Enabled: false
230+
231+
RSpec/VerifiedDoubles:
232+
Enabled: false

gush.gemspec

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
43

54
require_relative 'lib/gush/version'
@@ -33,6 +32,9 @@ Gem::Specification.new do |spec|
3332
spec.add_dependency "launchy", "~> 2.4"
3433
spec.add_development_dependency "bundler"
3534
spec.add_development_dependency "rake", "~> 12"
35+
spec.add_development_dependency "rubocop", '~> 1.65.0'
36+
spec.add_development_dependency "rubocop-rake", '~> 0.6.0'
37+
spec.add_development_dependency "rubocop-rspec", '~> 3.0.3'
3638
spec.add_development_dependency "rspec", '~> 3.0'
3739
spec.add_development_dependency "pry", '~> 0.10'
3840
end

lib/gush/cli.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def viz(class_or_id)
101101
begin
102102
workflow = class_or_id.constantize.new
103103
rescue NameError => e
104-
STDERR.puts Paint["'#{class_or_id}' is not a valid workflow class or id", :red]
104+
warn Paint["'#{class_or_id}' is not a valid workflow class or id", :red]
105105
exit 1
106106
end
107107
end

lib/gush/cli/overview.rb

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def jobs_list(jobs)
3434
end
3535

3636
private
37+
3738
def rows
3839
[].tap do |rows|
3940
columns.each_pair do |name, value|
@@ -91,6 +92,7 @@ def job_to_list_element(job)
9192

9293
def jobs_by_type(type)
9394
return sorted_jobs if type == :all
95+
9496
jobs.select{|j| j.public_send("#{type}?") }
9597
end
9698

lib/gush/client.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def find_workflow(id)
9595
keys = redis.scan_each(match: "gush.jobs.#{id}.*")
9696

9797
nodes = keys.each_with_object([]) do |key, array|
98-
array.concat redis.hvals(key).map { |json| Gush::JSON.decode(json, symbolize_keys: true) }
98+
array.concat(redis.hvals(key).map { |json| Gush::JSON.decode(json, symbolize_keys: true) })
9999
end
100100

101101
workflow_from_hash(hash, nodes)
@@ -142,13 +142,13 @@ def destroy_job(workflow_id, job)
142142
end
143143

144144
def expire_workflow(workflow, ttl=nil)
145-
ttl = ttl || configuration.ttl
145+
ttl ||= configuration.ttl
146146
redis.expire("gush.workflows.#{workflow.id}", ttl)
147147
workflow.jobs.each {|job| expire_job(workflow.id, job, ttl) }
148148
end
149149

150150
def expire_job(workflow_id, job, ttl=nil)
151-
ttl = ttl || configuration.ttl
151+
ttl ||= configuration.ttl
152152
redis.expire("gush.jobs.#{workflow_id}.#{job.klass}", ttl)
153153
end
154154

lib/gush/graph.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module Gush
66
class Graph
7-
attr_reader :workflow, :filename, :path, :start_node, :end_node
7+
attr_reader :workflow, :filename, :start_node, :end_node
88

99
def initialize(workflow, options = {})
1010
@workflow = workflow
@@ -32,7 +32,7 @@ def viz
3232
file_format = path.split('.')[-1]
3333
format = file_format if file_format.length == 3
3434

35-
Graphviz::output(@graph, path: path, format: format)
35+
Graphviz.output(@graph, path: path, format: format)
3636
end
3737

3838
def path

lib/gush/job.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Job
33
attr_accessor :workflow_id, :incoming, :outgoing, :params,
44
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads,
55
:klass, :queue, :wait
6-
attr_reader :id, :klass, :output_payload, :params
6+
attr_reader :id, :output_payload
77

88
def initialize(opts = {})
99
options = opts.dup

lib/gush/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Gush
2-
VERSION = '3.0.0'
2+
VERSION = '3.0.0'.freeze
33
end

lib/gush/worker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def perform(workflow_id, job_id)
3030

3131
private
3232

33-
attr_reader :client, :workflow_id, :job, :configuration
33+
attr_reader :workflow_id, :job
3434

3535
def client
3636
@client ||= Gush::Client.new(Gush.configuration)

lib/gush/workflow.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
module Gush
44
class Workflow
5-
attr_accessor :id, :jobs, :dependencies, :stopped, :persisted, :arguments, :kwargs, :globals
5+
attr_accessor :jobs, :dependencies, :stopped, :persisted, :arguments, :kwargs, :globals
6+
attr_writer :id
67

78
def initialize(*args, globals: nil, internal_state: {}, **kwargs)
89
@arguments = args
@@ -56,7 +57,7 @@ def persist!
5657
client.persist_workflow(self)
5758
end
5859

59-
def expire! (ttl=nil)
60+
def expire!(ttl=nil)
6061
client.expire_workflow(self, ttl)
6162
end
6263

spec/features/integration_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def perform
136136

137137
class SummaryJob < Gush::Job
138138
def perform
139-
output payloads.map { |payload| payload[:output] }
139+
output(payloads.map { |payload| payload[:output] })
140140
end
141141
end
142142

0 commit comments

Comments
 (0)