Skip to content

Commit f61d5c7

Browse files
authored
Rubocop cleanup (#7)
* Clean up rubocop and fixes a few error, from 200 offenses to 100 * Remove dup line lenght, set lenght to 150, and one clean up * contains not contaians
1 parent 177c92e commit f61d5c7

File tree

13 files changed

+83
-94
lines changed

13 files changed

+83
-94
lines changed

.rubocop.yml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Rails/Delegate:
9494
Description: 'Prefer delegate method for delegations.'
9595
Enabled: false
9696

97-
Style/DeprecatedHashMethods:
97+
Style/PreferredHashMethods:
9898
Description: 'Checks for use of deprecated Hash methods.'
9999
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
100100
Enabled: false
@@ -103,11 +103,6 @@ Style/Documentation:
103103
Description: 'Document classes and non-namespace modules.'
104104
Enabled: false
105105

106-
Style/DotPosition:
107-
Description: 'Checks the position of the dot in multi-line method calls.'
108-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
109-
EnforcedStyle: trailing
110-
111106
Style/DoubleNegation:
112107
Description: 'Checks for uses of double negation (!!).'
113108
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang'
@@ -133,10 +128,6 @@ Style/EvenOdd:
133128
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
134129
Enabled: false
135130

136-
Style/ExtraSpacing:
137-
Description: 'Do not use unnecessary spacing.'
138-
Enabled: true
139-
140131
Style/FileName:
141132
Description: 'Use snake_case for source file names.'
142133
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
@@ -196,9 +187,9 @@ Style/LineEndConcatenation:
196187
Enabled: false
197188

198189
Metrics/LineLength:
199-
Description: 'Limit lines to 100 characters.'
190+
Description: 'Limit lines to 150 characters.'
200191
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
201-
Max: 100
192+
Max: 150
202193

203194
Metrics/MethodLength:
204195
Description: 'Avoid methods longer than 10 lines of code.'
@@ -210,13 +201,6 @@ Style/ModuleFunction:
210201
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function'
211202
Enabled: false
212203

213-
Style/MultilineOperationIndentation:
214-
Description: >-
215-
Checks indentation of binary operations that span more than
216-
one line.
217-
Enabled: true
218-
EnforcedStyle: indented
219-
220204
Style/NegatedIf:
221205
Description: >-
222206
Favor unless over if for negative conditions
@@ -334,13 +318,14 @@ Style/StringLiterals:
334318
EnforcedStyle: double_quotes
335319
Enabled: true
336320

337-
Style/TrailingComma:
338-
Description: 'Checks for trailing comma in parameter lists and literals.'
339-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
340-
EnforcedStyleForMultiline: comma
341-
SupportedStyles:
342-
- comma
343-
- no_comma
321+
Style/TrailingCommaInArguments:
322+
Description: 'Checks for trailing comma in argument lists.'
323+
StyleGuide: '#no-trailing-params-comma'
324+
Enabled: true
325+
326+
Style/TrailingCommaInLiteral:
327+
Description: 'Checks for trailing comma in array and hash literals.'
328+
StyleGuide: '#no-trailing-array-commas'
344329
Enabled: true
345330

346331
Style/TrivialAccessors:
@@ -372,6 +357,29 @@ Style/WordArray:
372357
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
373358
Enabled: false
374359

360+
# Layout
361+
Layout/DotPosition:
362+
Description: 'Checks the position of the dot in multi-line method calls.'
363+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
364+
EnforcedStyle: trailing
365+
366+
Layout/ExtraSpacing:
367+
Description: 'Do not use unnecessary spacing.'
368+
Enabled: true
369+
370+
Layout/MultilineOperationIndentation:
371+
Description: >-
372+
Checks indentation of binary operations that span more than
373+
one line.
374+
Enabled: true
375+
EnforcedStyle: indented
376+
377+
Layout/InitialIndentation:
378+
Description: >-
379+
Checks the indentation of the first non-blank non-comment line in a file.
380+
Enabled: false
381+
382+
375383
# Lint
376384

377385
Lint/AmbiguousOperator:
@@ -434,11 +442,6 @@ Lint/InvalidCharacterLiteral:
434442
whitespace character.
435443
Enabled: false
436444

437-
Style/InitialIndentation:
438-
Description: >-
439-
Checks the indentation of the first non-blank non-comment line in a file.
440-
Enabled: false
441-
442445
Lint/LiteralInCondition:
443446
Description: 'Checks of literals used in conditions.'
444447
Enabled: false
@@ -560,10 +563,6 @@ Rails/Date:
560563
such as Date.today, Date.current etc.
561564
Enabled: false
562565

563-
Rails/DefaultScope:
564-
Description: 'Checks if the argument passed to default_scope is a block.'
565-
Enabled: false
566-
567566
Rails/FindBy:
568567
Description: 'Prefer find_by over where.first.'
569568
Enabled: false

ext/mkrf_conf.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require 'rubygems'
1+
require "rubygems"
22

33

44
# From http://stackoverflow.com/questions/5830835/how-to-add-openssl-dependency-to-gemspec
55
# the whole reason this file exists: to return an error if openssl
66
# isn't installed.
7-
require 'openssl'
7+
require "openssl"
88

99
f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
1010
f.write("task :default\n")
11-
f.close
11+
f.close

ldclient-rb.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# coding: utf-8
2+
23
lib = File.expand_path("../lib", __FILE__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45
require "ldclient-rb/version"
56

7+
# rubocop:disable Metrics/BlockLength
68
Gem::Specification.new do |spec|
79
spec.name = "ldclient-rb"
810
spec.version = LaunchDarkly::VERSION
@@ -34,7 +36,7 @@ Gem::Specification.new do |spec|
3436
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.10.0"
3537
spec.add_runtime_dependency "celluloid", "~> 0.18.0.pre" # transitive dep; specified here for more control
3638

37-
if RUBY_VERSION >= '2.2.2'
39+
if RUBY_VERSION >= "2.2.2"
3840
spec.add_runtime_dependency "nio4r", "< 3" # for maximum ruby version compatibility.
3941
else
4042
spec.add_runtime_dependency "nio4r", "~> 1.1" # for maximum ruby version compatibility.

lib/ldclient-rb/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Config
4242
# @option opts [Boolean] :stream (true) Whether or not the streaming API should be used to receive flag updates.
4343
#
4444
# @return [type] [description]
45+
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
4546
def initialize(opts = {})
4647
@base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
4748
@stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
@@ -144,7 +145,6 @@ def offline?
144145
#
145146
attr_reader :feature_store
146147

147-
148148
# The proxy configuration string
149149
#
150150
attr_reader :proxy

lib/ldclient-rb/evaluation.rb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
require "date"
22

33
module LaunchDarkly
4-
54
module Evaluation
65
BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name, :anonymous]
76

87
OPERATORS = {
9-
in:
8+
in:
109
lambda do |a, b|
1110
a == b
1211
end,
13-
endsWith:
12+
endsWith:
1413
lambda do |a, b|
1514
(a.is_a? String) && (a.end_with? b)
1615
end,
17-
startsWith:
16+
startsWith:
1817
lambda do |a, b|
1918
(a.is_a? String) && (a.start_with? b)
2019
end,
@@ -50,7 +49,7 @@ module Evaluation
5049
end
5150
if b.is_a? String
5251
b = DateTime.rfc3339(b).strftime('%Q').to_i
53-
end
52+
end
5453
(a.is_a? Numeric) ? a < b : false
5554
rescue => e
5655
false
@@ -60,11 +59,11 @@ module Evaluation
6059
lambda do |a, b|
6160
begin
6261
if a.is_a? String
63-
a = DateTime.rfc3339(a).strftime('%Q').to_i
62+
a = DateTime.rfc3339(a).strftime("%Q").to_i
6463
end
6564
if b.is_a? String
66-
b = DateTime.rfc3339(b).strftime('%Q').to_i
67-
end
65+
b = DateTime.rfc3339(b).strftime("%Q").to_i
66+
end
6867
(a.is_a? Numeric) ? a > b : false
6968
rescue => e
7069
false
@@ -93,23 +92,22 @@ def evaluate(flag, user, store)
9392
if flag[:on]
9493
res = eval_internal(flag, user, store, events)
9594

96-
return {value: res, events: events} if !res.nil?
95+
return { value: res, events: events } if !res.nil?
9796
end
9897

9998
if !flag[:offVariation].nil? && flag[:offVariation] < flag[:variations].length
10099
value = flag[:variations][flag[:offVariation]]
101-
return {value: value, events: events}
100+
return { value: value, events: events }
102101
end
103102

104-
{value: nil, events: events}
103+
{ value: nil, events: events }
105104
end
106105

107106
def eval_internal(flag, user, store, events)
108107
failed_prereq = false
109108
# Evaluate prerequisites, if any
110109
if !flag[:prerequisites].nil?
111110
flag[:prerequisites].each do |prerequisite|
112-
113111
prereq_flag = store.get(prerequisite[:key])
114112

115113
if prereq_flag.nil? || !prereq_flag[:on]
@@ -119,7 +117,7 @@ def eval_internal(flag, user, store, events)
119117
prereq_res = eval_internal(prereq_flag, user, store, events)
120118
variation = get_variation(prereq_flag, prerequisite[:variation])
121119
events.push(kind: "feature", key: prereq_flag[:key], value: prereq_res, version: prereq_flag[:version], prereqOf: flag[:key])
122-
if prereq_res.nil? || prereq_res!= variation
120+
if prereq_res.nil? || prereq_res != variation
123121
failed_prereq = true
124122
end
125123
rescue => exn
@@ -149,7 +147,7 @@ def eval_rules(flag, user)
149147
end
150148
end
151149
end
152-
end
150+
end
153151

154152
# Check custom rules
155153
if !flag[:rules].nil?
@@ -202,7 +200,7 @@ def clause_match_user(clause, user)
202200
end
203201

204202
maybe_negate(clause, match_any(op, val, clause[:values]))
205-
end
203+
end
206204

207205
def variation_for_user(rule, user, flag)
208206
if !rule[:variation].nil? # fixed variation
@@ -234,7 +232,7 @@ def bucket_user(user, key, bucket_by, salt)
234232
hash_key = "%s.%s.%s" % [key, salt, id_hash]
235233

236234
hash_val = (Digest::SHA1.hexdigest(hash_key))[0..14]
237-
hash_val.to_i(16) / Float(0xFFFFFFFFFFFFFFF)
235+
hash_val.to_i(16) / Float(0xFFFFFFFFFFFFFFF)
238236
end
239237

240238
def user_value(user, attribute)
@@ -260,6 +258,4 @@ def match_any(op, value, values)
260258
return false
261259
end
262260
end
263-
264261
end
265-

lib/ldclient-rb/events.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require "faraday"
33

44
module LaunchDarkly
5-
65
class EventProcessor
76
def initialize(sdk_key, config)
87
@queue = Queue.new
@@ -67,9 +66,8 @@ def add_event(event)
6766
else
6867
@config.logger.warn("[LDClient] Exceeded event queue capacity. Increase capacity to avoid dropping events.")
6968
end
70-
end
69+
end
7170

7271
private :create_worker, :post_flushed_events
73-
7472
end
75-
end
73+
end

lib/ldclient-rb/feature_store.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require "concurrent/atomics"
22

33
module LaunchDarkly
4-
54
class InMemoryFeatureStore
65
def initialize
76
@features = Hash.new
@@ -57,4 +56,4 @@ def initialized?
5756
@initialized.value
5857
end
5958
end
60-
end
59+
end

0 commit comments

Comments
 (0)