Skip to content

Commit

Permalink
Rubocop (#16)
Browse files Browse the repository at this point in the history
introducing rubocop linter
  • Loading branch information
kp-cat authored Feb 17, 2023
1 parent 41b2983 commit 8a8c0ac
Show file tree
Hide file tree
Showing 28 changed files with 282 additions and 149 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ruby-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-versions }}
bundler-cache: true

- name: Run tests
run: bundle exec rake

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
bundler-cache: true
- name: Run Rubocop
run: bundle exec rubocop

coverage:
needs: test
runs-on: ubuntu-latest
Expand Down
142 changes: 142 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstArgumentIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: false

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: always

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
#Style/StringLiterals:
# Enabled: true
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: false

# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: false
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source "https://rubygems.org"
gemspec
gemspec
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ desc "Run specs"
RSpec::Core::RakeTask.new do |t|
end

task :default => :spec
task :default => :spec
1 change: 1 addition & 0 deletions configcat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 12.3"
spec.add_development_dependency "codecov", "~> 0.5"
spec.add_development_dependency "webmock", "~> 3.0"
spec.add_development_dependency "rubocop"
end
6 changes: 2 additions & 4 deletions lib/configcat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require 'logger'

module ConfigCat

@logger = Logger.new(STDOUT, level: Logger::WARN)
class << self
attr_accessor :logger
Expand All @@ -17,7 +16,7 @@ class << self
# :param sdk_key [String] ConfigCat SDK Key to access your configuration.
# :param options [ConfigCatOptions] Configuration `ConfigCatOptions` for `ConfigCatClient`.
# :return [ConfigCatClient] the `ConfigCatClient` instance.
def ConfigCat.get(sdk_key, options=nil)
def ConfigCat.get(sdk_key, options = nil)
return ConfigCatClient.get(sdk_key, options)
end

Expand Down Expand Up @@ -185,5 +184,4 @@ def ConfigCat.create_client_with_manual_poll(sdk_key,
client.log.warn('create_client_with_manual_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
return client
end

end
end
27 changes: 13 additions & 14 deletions lib/configcat/configcatclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigCatClient
# :param sdk_key [String] ConfigCat SDK Key to access your configuration.
# :param options [ConfigCatOptions] Configuration for `ConfigCatClient`.
# :return [ConfigCatClient] the `ConfigCatClient` instance.
def self.get(sdk_key, options=nil)
def self.get(sdk_key, options = nil)
@@lock.synchronize do
client = @@instances[sdk_key]
if client
Expand Down Expand Up @@ -51,7 +51,7 @@ def self.close_all
end
end

private def initialize(sdk_key, options=ConfigCatOptions.new)
private def initialize(sdk_key, options = ConfigCatOptions.new)
@hooks = options.hooks || Hooks.new
@log = ConfigCatLogger.new(@hooks)

Expand Down Expand Up @@ -102,7 +102,7 @@ def self.close_all
# :param default_value in case of any failure, this value will be returned.
# :param user [User] the user object to identify the caller.
# :return the value.
def get_value(key, default_value, user=nil)
def get_value(key, default_value, user = nil)
settings, fetch_time = _get_settings()
if settings.nil?
message = "Evaluating get_value('%s') failed. Cache is empty. " \
Expand All @@ -121,7 +121,7 @@ def get_value(key, default_value, user=nil)
# :param default_value in case of any failure, this value will be returned.
# :param user [User] the user object to identify the caller.
# :return [EvaluationDetails] the evaluation details.
def get_value_details(key, default_value, user=nil)
def get_value_details(key, default_value, user = nil)
settings, fetch_time = _get_settings()
if settings.nil?
message = "Evaluating get_value_details('%s') failed. Cache is empty. " \
Expand Down Expand Up @@ -151,7 +151,7 @@ def get_all_keys
# :param default_variation_id in case of any failure, this value will be returned.
# :param user [User] the user object to identify the caller.
# :return the variation ID.
def get_variation_id(key, default_variation_id, user=nil)
def get_variation_id(key, default_variation_id, user = nil)
@log.warn("get_variation_id is deprecated and will be removed in a future major version. "\
"Please use [get_value_details] instead.")

Expand All @@ -173,7 +173,7 @@ def get_variation_id(key, default_variation_id, user=nil)
#
# :param user [User] the user object to identify the caller.
# :return list of variation IDs
def get_all_variation_ids(user=nil)
def get_all_variation_ids(user = nil)
@log.warn("get_all_variation_ids is deprecated and will be removed in a future major version. "\
"Please use [get_value_details] instead.")

Expand Down Expand Up @@ -226,7 +226,7 @@ def get_key_and_value(variation_id)
#
# :param user [User] the user object to identify the caller.
# :return dictionary of values
def get_all_values(user=nil)
def get_all_values(user = nil)
keys = get_all_keys()
all_values = {}
for key in keys
Expand All @@ -242,7 +242,7 @@ def get_all_values(user=nil)
#
# :param user [User] the user object to identify the caller.
# :return list of all evaluation details
def get_all_value_details(user=nil)
def get_all_value_details(user = nil)
settings, fetch_time = _get_settings()
if settings.nil?
@log.error("Evaluating get_all_value_details() failed. Cache is empty. Returning empty list.")
Expand Down Expand Up @@ -346,11 +346,11 @@ def _get_cache_key
def _evaluate(key, user, default_value, default_variation_id, settings, fetch_time)
user = user || @_default_user
value, variation_id, rule, percentage_rule, error = @_rollout_evaluator.evaluate(
key: key,
user: user,
default_value: default_value,
default_variation_id: default_variation_id,
settings: settings)
key: key,
user: user,
default_value: default_value,
default_variation_id: default_variation_id,
settings: settings)

details = EvaluationDetails.new(key: key,
value: value,
Expand All @@ -364,6 +364,5 @@ def _evaluate(key, user, default_value, default_variation_id, settings, fetch_ti
@hooks.invoke_on_flag_evaluated(details)
return details
end

end
end
2 changes: 0 additions & 2 deletions lib/configcat/configcatlogger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module ConfigCat

class ConfigCatLogger
def initialize(hooks)
@hooks = hooks
Expand All @@ -22,5 +21,4 @@ def error(message)
ConfigCat.logger.error(message)
end
end

end
2 changes: 0 additions & 2 deletions lib/configcat/configcatoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'configcat/pollingmode'

module ConfigCat

class Hooks
#
# Events fired by [ConfigCatClient].
Expand Down Expand Up @@ -151,5 +150,4 @@ def initialize(base_url: nil,
@offline = offline
end
end

end
Loading

0 comments on commit 8a8c0ac

Please sign in to comment.