Skip to content

Commit

Permalink
Added rubocop for code style consistency (#115)
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
noahfpf authored Aug 12, 2024
1 parent f06f85f commit 7997911
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
RAILS_VERSION: "${{ matrix.rails_version }}"
- name: Install Graphviz
run: sudo apt-get install graphviz
- name: Run code lint
run: bundle exec rubocop
env:
RAILS_VERSION: "${{ matrix.rails_version }}"
- name: Run tests
run: bundle exec rspec
env:
Expand Down
232 changes: 232 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: disable

Gemspec/OrderedDependencies:
Enabled: false

Layout/ArgumentAlignment:
Enabled: false

Layout/CaseIndentation:
Enabled: false

Layout/EmptyLinesAroundBlockBody:
Enabled: false

Layout/ExtraSpacing:
Enabled: false

Layout/FirstHashElementIndentation:
Enabled: false

Layout/HashAlignment:
Enabled: false

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: false

Layout/SpaceAroundOperators:
Enabled: false

Layout/SpaceBeforeBlockBraces:
Enabled: false

Layout/SpaceInsideBlockBraces:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
Enabled: false

Lint/ConstantDefinitionInBlock:
Exclude:
- spec/**/*

Lint/RedundantSplatExpansion:
Enabled: false

Lint/ToJSON:
Enabled: false

Lint/UnusedBlockArgument:
Enabled: false

Lint/UnusedMethodArgument:
Enabled: false

Lint/UselessAssignment:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/MethodLength:
Enabled: false

Naming/MemoizedInstanceVariableName:
Enabled: false

Naming/PredicateName:
Enabled: false

Naming/RescuedExceptionsVariableName:
Enabled: false

Style/BlockDelimiters:
Enabled: false

Style/ClassVars:
Enabled: false

Style/CombinableLoops:
Enabled: false

Style/ConditionalAssignment:
Enabled: false

Style/Documentation:
Enabled: false

Style/EmptyCaseCondition:
Enabled: false

Style/EmptyMethod:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/GuardClause:
Enabled: false

Style/HashSyntax:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/InverseMethods:
Enabled: false

Style/MethodCallWithoutArgsParentheses:
Enabled: false

Style/NumericLiteralPrefix:
Enabled: false

Style/PercentLiteralDelimiters:
Enabled: false

Style/RaiseArgs:
Enabled: false

Style/SafeNavigation:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SymbolProc:
Enabled: false

Style/UnlessElse:
Enabled: false

Style/WordArray:
Enabled: false

Layout/LineLength:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/BeEq:
Enabled: false

RSpec/ContextWording:
Enabled: false

RSpec/DescribedClass:
Enabled: false

RSpec/EmptyExampleGroup:
Enabled: false

RSpec/EmptyLineAfterExampleGroup:
Enabled: false

RSpec/EmptyLineAfterSubject:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/ExampleWording:
Enabled: false

RSpec/ExpectChange:
Enabled: false

RSpec/HookArgument:
EnforcedStyle: each

RSpec/LeakyConstantDeclaration:
Enabled: false

RSpec/LetSetup:
Enabled: false

RSpec/MatchArray:
Enabled: false

RSpec/MessageSpies:
EnforcedStyle: receive

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NamedSubject:
Enabled: false

RSpec/NestedGroups:
Enabled: false

RSpec/NotToNot:
Enabled: false

RSpec/PredicateMatcher:
Enabled: false

RSpec/ReceiveCounts:
Enabled: false

RSpec/SpecFilePathFormat:
Enabled: false

RSpec/StubbedMock:
Enabled: false

RSpec/SubjectStub:
Enabled: false

RSpec/VerifiedDoubles:
Enabled: false
6 changes: 4 additions & 2 deletions gush.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require_relative 'lib/gush/version'
Expand Down Expand Up @@ -33,6 +32,9 @@ Gem::Specification.new do |spec|
spec.add_dependency "launchy", "~> 2.4"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 12"
spec.add_development_dependency "rubocop", '~> 1.65.0'
spec.add_development_dependency "rubocop-rake", '~> 0.6.0'
spec.add_development_dependency "rubocop-rspec", '~> 3.0.3'
spec.add_development_dependency "rspec", '~> 3.0'
spec.add_development_dependency "pry", '~> 0.10'
end
2 changes: 1 addition & 1 deletion lib/gush/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def viz(class_or_id)
begin
workflow = class_or_id.constantize.new
rescue NameError => e
STDERR.puts Paint["'#{class_or_id}' is not a valid workflow class or id", :red]
warn Paint["'#{class_or_id}' is not a valid workflow class or id", :red]
exit 1
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/gush/cli/overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def jobs_list(jobs)
end

private

def rows
[].tap do |rows|
columns.each_pair do |name, value|
Expand Down Expand Up @@ -91,6 +92,7 @@ def job_to_list_element(job)

def jobs_by_type(type)
return sorted_jobs if type == :all

jobs.select{|j| j.public_send("#{type}?") }
end

Expand Down
6 changes: 3 additions & 3 deletions lib/gush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def find_workflow(id)
keys = redis.scan_each(match: "gush.jobs.#{id}.*")

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

workflow_from_hash(hash, nodes)
Expand Down Expand Up @@ -142,13 +142,13 @@ def destroy_job(workflow_id, job)
end

def expire_workflow(workflow, ttl=nil)
ttl = ttl || configuration.ttl
ttl ||= configuration.ttl
redis.expire("gush.workflows.#{workflow.id}", ttl)
workflow.jobs.each {|job| expire_job(workflow.id, job, ttl) }
end

def expire_job(workflow_id, job, ttl=nil)
ttl = ttl || configuration.ttl
ttl ||= configuration.ttl
redis.expire("gush.jobs.#{workflow_id}.#{job.klass}", ttl)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/gush/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Gush
class Graph
attr_reader :workflow, :filename, :path, :start_node, :end_node
attr_reader :workflow, :filename, :start_node, :end_node

def initialize(workflow, options = {})
@workflow = workflow
Expand Down Expand Up @@ -32,7 +32,7 @@ def viz
file_format = path.split('.')[-1]
format = file_format if file_format.length == 3

Graphviz::output(@graph, path: path, format: format)
Graphviz.output(@graph, path: path, format: format)
end

def path
Expand Down
2 changes: 1 addition & 1 deletion lib/gush/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Job
attr_accessor :workflow_id, :incoming, :outgoing, :params,
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads,
:klass, :queue, :wait
attr_reader :id, :klass, :output_payload, :params
attr_reader :id, :output_payload

def initialize(opts = {})
options = opts.dup
Expand Down
2 changes: 1 addition & 1 deletion lib/gush/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gush
VERSION = '3.0.0'
VERSION = '3.0.0'.freeze
end
2 changes: 1 addition & 1 deletion lib/gush/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def perform(workflow_id, job_id)

private

attr_reader :client, :workflow_id, :job, :configuration
attr_reader :workflow_id, :job

def client
@client ||= Gush::Client.new(Gush.configuration)
Expand Down
5 changes: 3 additions & 2 deletions lib/gush/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module Gush
class Workflow
attr_accessor :id, :jobs, :dependencies, :stopped, :persisted, :arguments, :kwargs, :globals
attr_accessor :jobs, :dependencies, :stopped, :persisted, :arguments, :kwargs, :globals
attr_writer :id

def initialize(*args, globals: nil, internal_state: {}, **kwargs)
@arguments = args
Expand Down Expand Up @@ -56,7 +57,7 @@ def persist!
client.persist_workflow(self)
end

def expire! (ttl=nil)
def expire!(ttl=nil)
client.expire_workflow(self, ttl)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def perform

class SummaryJob < Gush::Job
def perform
output payloads.map { |payload| payload[:output] }
output(payloads.map { |payload| payload[:output] })
end
end

Expand Down
Loading

0 comments on commit 7997911

Please sign in to comment.