Skip to content

Commit 3f4105a

Browse files
authored
Merge pull request #678 from splitrb/fix-hash-syntax-offenses
Fix Style/HashSyntax offenses
2 parents a663a33 + accf157 commit 3f4105a

21 files changed

+166
-182
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,6 @@ Style/DefWithParentheses:
186186
Exclude:
187187
- 'lib/split/helper.rb'
188188

189-
# Offense count: 23
190-
# Cop supports --auto-correct.
191-
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
192-
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
193-
Style/HashSyntax:
194-
Exclude:
195-
- 'Rakefile'
196-
- 'lib/split/experiment.rb'
197-
- 'lib/split/experiment_catalog.rb'
198-
- 'lib/split/helper.rb'
199-
- 'lib/split/metric.rb'
200-
- 'lib/split/persistence.rb'
201-
- 'lib/split/persistence/redis_adapter.rb'
202-
203189
# Offense count: 1
204190
# Cop supports --auto-correct.
205191
# Configuration parameters: EnforcedStyle.

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ require 'rspec/core/rake_task'
66

77
RSpec::Core::RakeTask.new('spec')
88

9-
task :default => :spec
9+
task default: :spec

lib/split/algorithms.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def beta_distribution_rng(a, b)
1717
end
1818
end
1919
end
20-
end
20+
end

lib/split/cache.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
module Split
44
class Cache
5-
65
def self.clear
76
@cache = nil
87
end

lib/split/experiment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Experiment
1111
attr_reader :resettable
1212

1313
DEFAULT_OPTIONS = {
14-
:resettable => true
14+
resettable: true
1515
}
1616

1717
def self.find(name)

lib/split/experiment_catalog.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
module Split
34
class ExperimentCatalog
45
# Return all experiments
@@ -26,7 +27,7 @@ def self.find_or_initialize(metric_descriptor, control = nil, *alternatives)
2627
experiment_name_with_version, goals = normalize_experiment(metric_descriptor)
2728
experiment_name = experiment_name_with_version.to_s.split(':')[0]
2829
Split::Experiment.new(experiment_name,
29-
:alternatives => [control].compact + alternatives, :goals => goals)
30+
alternatives: [control].compact + alternatives, goals: goals)
3031
end
3132

3233
def self.find_or_create(metric_descriptor, control = nil, *alternatives)

lib/split/helper.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def ab_test(metric_descriptor, control = nil, *alternatives)
1212
alternative = if Split.configuration.enabled && !exclude_visitor?
1313
experiment.save
1414
raise(Split::InvalidExperimentsFormatError) unless (Split.configuration.experiments || {}).fetch(experiment.name.to_sym, {})[:combined_experiments].nil?
15-
trial = Trial.new(:user => ab_user, :experiment => experiment,
16-
:override => override_alternative(experiment.name), :exclude => exclude_visitor?,
17-
:disabled => split_generically_disabled?)
15+
trial = Trial.new(user: ab_user, experiment: experiment,
16+
override: override_alternative(experiment.name), exclude: exclude_visitor?,
17+
disabled: split_generically_disabled?)
1818
alt = trial.choose!(self)
1919
alt ? alt.name : nil
2020
else
@@ -44,7 +44,7 @@ def reset!(experiment)
4444
ab_user.delete(experiment.key)
4545
end
4646

47-
def finish_experiment(experiment, options = {:reset => true})
47+
def finish_experiment(experiment, options = {reset: true})
4848
return false if active_experiments[experiment.name].nil?
4949
return true if experiment.has_winner?
5050
should_reset = experiment.resettable? && options[:reset]
@@ -53,10 +53,10 @@ def finish_experiment(experiment, options = {:reset => true})
5353
else
5454
alternative_name = ab_user[experiment.key]
5555
trial = Trial.new(
56-
:user => ab_user,
57-
:experiment => experiment,
58-
:alternative => alternative_name,
59-
:goals => options[:goals],
56+
user: ab_user,
57+
experiment: experiment,
58+
alternative: alternative_name,
59+
goals: options[:goals],
6060
)
6161

6262
trial.complete!(self)
@@ -69,15 +69,15 @@ def finish_experiment(experiment, options = {:reset => true})
6969
end
7070
end
7171

72-
def ab_finished(metric_descriptor, options = {:reset => true})
72+
def ab_finished(metric_descriptor, options = {reset: true})
7373
return if exclude_visitor? || Split.configuration.disabled?
7474
metric_descriptor, goals = normalize_metric(metric_descriptor)
7575
experiments = Metric.possible_experiments(metric_descriptor)
7676

7777
if experiments.any?
7878
experiments.each do |experiment|
7979
next if override_present?(experiment.key)
80-
finish_experiment(experiment, options.merge(:goals => goals))
80+
finish_experiment(experiment, options.merge(goals: goals))
8181
end
8282
end
8383
rescue => e

lib/split/metric.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.load_from_redis(name)
2222
Split::ExperimentCatalog.find(experiment_name)
2323
end
2424

25-
Split::Metric.new(:name => name, :experiments => experiments)
25+
Split::Metric.new(name: name, experiments: experiments)
2626
else
2727
nil
2828
end
@@ -31,7 +31,7 @@ def self.load_from_redis(name)
3131
def self.load_from_configuration(name)
3232
metrics = Split.configuration.metrics
3333
if metrics && metrics[name]
34-
Split::Metric.new(:experiments => metrics[name], :name => name)
34+
Split::Metric.new(experiments: metrics[name], name: name)
3535
else
3636
nil
3737
end

lib/split/persistence/redis_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Split
44
module Persistence
55
class RedisAdapter
6-
DEFAULT_CONFIG = {:namespace => 'persistence'}.freeze
6+
DEFAULT_CONFIG = {namespace: 'persistence'}.freeze
77

88
attr_reader :redis_key
99

spec/alternative_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
describe 'weights' do
3131
it "should set the weights" do
32-
experiment = Split::Experiment.new('basket_text', :alternatives => [{'Basket' => 0.6}, {"Cart" => 0.4}])
32+
experiment = Split::Experiment.new('basket_text', alternatives: [{'Basket' => 0.6}, {"Cart" => 0.4}])
3333
first = experiment.alternatives[0]
3434
expect(first.name).to eq('Basket')
3535
expect(first.weight).to eq(0.6)
@@ -41,11 +41,11 @@
4141

4242
it "accepts probability on alternatives" do
4343
Split.configuration.experiments = {
44-
:my_experiment => {
45-
:alternatives => [
46-
{ :name => "control_opt", :percent => 67 },
47-
{ :name => "second_opt", :percent => 10 },
48-
{ :name => "third_opt", :percent => 23 },
44+
my_experiment: {
45+
alternatives: [
46+
{ name: "control_opt", percent: 67 },
47+
{ name: "second_opt", percent: 10 },
48+
{ name: "third_opt", percent: 23 },
4949
]
5050
}
5151
}
@@ -61,11 +61,11 @@
6161

6262
it "accepts probability on some alternatives" do
6363
Split.configuration.experiments = {
64-
:my_experiment => {
65-
:alternatives => [
66-
{ :name => "control_opt", :percent => 34 },
64+
my_experiment: {
65+
alternatives: [
66+
{ name: "control_opt", percent: 34 },
6767
"second_opt",
68-
{ :name => "third_opt", :percent => 23 },
68+
{ name: "third_opt", percent: 23 },
6969
"fourth_opt",
7070
],
7171
}
@@ -87,11 +87,11 @@
8787
#
8888
it "allows name param without probability" do
8989
Split.configuration.experiments = {
90-
:my_experiment => {
91-
:alternatives => [
92-
{ :name => "control_opt" },
90+
my_experiment: {
91+
alternatives: [
92+
{ name: "control_opt" },
9393
"second_opt",
94-
{ :name => "third_opt", :percent => 64 },
94+
{ name: "third_opt", percent: 64 },
9595
],
9696
}
9797
}

0 commit comments

Comments
 (0)