Skip to content

Commit 17fe755

Browse files
authored
Merge pull request #752 from tamird/update-rubocop
Update RuboCop to 0.50.x
2 parents e84b6ce + d89f241 commit 17fe755

36 files changed

+402
-348
lines changed

.rubocop.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4+
TargetRubyVersion: 1.9
5+
46
DisplayCopNames: true
57
Exclude:
68
- 'pkg/**/*'
79
- 'tmp/**/*'
810
- 'vendor/**/*'
911

12+
Layout/CaseIndentation:
13+
EnforcedStyle: end
14+
15+
Layout/IndentHash:
16+
EnforcedStyle: consistent
17+
18+
Layout/IndentHeredoc:
19+
EnforcedStyle: powerpack
20+
1021
Lint/EndAlignment:
11-
AlignWith: variable
22+
EnforcedStyleAlignWith: variable
1223

13-
Style/CaseIndentation:
14-
IndentWhenRelativeTo: end
24+
Style/Encoding:
25+
AutoCorrectEncodingComment: '# encoding: UTF-8'
26+
EnforcedStyle: always
1527

16-
Style/IndentHash:
17-
EnforcedStyle: consistent
28+
Style/TrailingCommaInArguments:
29+
EnforcedStyleForMultiline: consistent_comma
1830

19-
Style/TrailingComma:
31+
Style/TrailingCommaInLiteral:
2032
EnforcedStyleForMultiline: consistent_comma
2133

2234
Style/TrivialAccessors:
2335
AllowPredicates: true
24-
25-
# TODO: remove when we end support for < 1.9.3
26-
27-
Style/HashSyntax:
28-
EnforcedStyle: hash_rockets
29-
30-
Style/Lambda:
31-
Enabled: false

.rubocop_todo.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,86 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2015-09-06 13:16:09 -0400 using RuboCop version 0.34.0.
3+
# on 2017-11-25 19:54:28 -0500 using RuboCop version 0.50.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 2
1010
Metrics/AbcSize:
11-
Max: 93
11+
Max: 90
12+
13+
# Offense count: 31
14+
# Configuration parameters: CountComments, ExcludedMethods.
15+
Metrics/BlockLength:
16+
Max: 825
1217

1318
# Offense count: 1
19+
# Configuration parameters: CountBlocks.
1420
Metrics/BlockNesting:
1521
Max: 5
1622

1723
# Offense count: 1
24+
# Configuration parameters: CountComments.
1825
Metrics/ClassLength:
1926
Max: 125
2027

21-
# Offense count: 2
28+
# Offense count: 3
2229
Metrics/CyclomaticComplexity:
2330
Max: 30
2431

25-
# Offense count: 290
26-
# Configuration parameters: AllowURI, URISchemes.
32+
# Offense count: 313
33+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
34+
# URISchemes: http, https
2735
Metrics/LineLength:
2836
Max: 232
2937

30-
# Offense count: 5
38+
# Offense count: 6
3139
# Configuration parameters: CountComments.
3240
Metrics/MethodLength:
33-
Max: 60
41+
Max: 57
3442

35-
# Offense count: 1
43+
# Offense count: 2
3644
Metrics/PerceivedComplexity:
3745
Max: 27
3846

39-
# Offense count: 40
40-
# Cop supports --auto-correct.
41-
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
42-
Style/BlockDelimiters:
43-
Enabled: false
47+
# Offense count: 3
48+
# Configuration parameters: Blacklist.
49+
# Blacklist: END, (?-mix:EO[A-Z]{1})
50+
Naming/HeredocDelimiterNaming:
51+
Exclude:
52+
- 'tasks/compile.rake'
4453

45-
# Offense count: 12
54+
# Offense count: 10
4655
Style/Documentation:
4756
Exclude:
57+
- 'spec/**/*'
58+
- 'test/**/*'
4859
- 'benchmark/active_record.rb'
4960
- 'benchmark/allocations.rb'
5061
- 'benchmark/query_with_mysql_casting.rb'
5162
- 'lib/mysql2.rb'
5263
- 'lib/mysql2/client.rb'
5364
- 'lib/mysql2/em.rb'
5465
- 'lib/mysql2/error.rb'
55-
- 'lib/mysql2/field.rb'
5666
- 'lib/mysql2/result.rb'
5767
- 'lib/mysql2/statement.rb'
58-
- 'lib/mysql2/version.rb'
5968

60-
# Offense count: 9
69+
# Offense count: 14
6170
# Configuration parameters: AllowedVariables.
6271
Style/GlobalVars:
6372
Exclude:
6473
- 'ext/mysql2/extconf.rb'
6574

66-
# Offense count: 14
75+
# Offense count: 17
6776
# Cop supports --auto-correct.
77+
# Configuration parameters: Strict.
6878
Style/NumericLiterals:
6979
MinDigits: 20
7080

71-
# Offense count: 680
81+
# Offense count: 726
7282
# Cop supports --auto-correct.
73-
# Configuration parameters: EnforcedStyle, SupportedStyles.
83+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
84+
# SupportedStyles: single_quotes, double_quotes
7485
Style/StringLiterals:
7586
Enabled: false

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: UTF-8
2+
13
source 'https://rubygems.org'
24

35
gemspec
@@ -8,7 +10,9 @@ gem 'rake-compiler', '~> 1.0'
810
group :test do
911
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
1012
gem 'rspec', '~> 3.2'
11-
gem 'rubocop', '~> 0.34.0'
13+
# https://github.com/bbatsov/rubocop/pull/3328
14+
# https://github.com/bbatsov/rubocop/pull/4789
15+
gem 'rubocop', '~> 0.50.0' unless RUBY_VERSION =~ /1.9/
1216
end
1317

1418
group :benchmarks do

Rakefile

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
require 'rake'
34

45
# Load custom tasks (careful attention to define tasks before prerequisites)
@@ -8,17 +9,11 @@ load 'tasks/compile.rake'
89
load 'tasks/generate.rake'
910
load 'tasks/benchmarks.rake'
1011

11-
# TODO: remove engine check when rubinius stops crashing on RuboCop
12-
has_rubocop = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
13-
begin
14-
require 'rubocop/rake_task'
15-
RuboCop::RakeTask.new
16-
task :default => [:spec, :rubocop]
17-
rescue LoadError # rubocop:disable Lint/HandleExceptions
18-
end
19-
end
20-
21-
unless has_rubocop
12+
begin
13+
require 'rubocop/rake_task'
14+
RuboCop::RakeTask.new
15+
task default: [:spec, :rubocop]
16+
rescue LoadError
2217
warn 'RuboCop is not available'
23-
task :default => :spec
18+
task default: :spec
2419
end

benchmark/active_record.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
@@ -8,7 +9,7 @@
89
ActiveRecord::Base.default_timezone = :local
910
ActiveRecord::Base.time_zone_aware_attributes = true
1011

11-
opts = { :database => 'test' }
12+
opts = { database: 'test' }
1213

1314
class TestModel < ActiveRecord::Base
1415
self.table_name = 'mysql2_test'
@@ -17,12 +18,12 @@ class TestModel < ActiveRecord::Base
1718
batch_size = 1000
1819

1920
Benchmark.ips do |x|
20-
%w(mysql mysql2).each do |adapter|
21-
TestModel.establish_connection(opts.merge(:adapter => adapter))
21+
%w[mysql mysql2].each do |adapter|
22+
TestModel.establish_connection(opts.merge(adapter: adapter))
2223

2324
x.report(adapter) do
2425
TestModel.limit(batch_size).to_a.each do |r|
25-
r.attributes.keys.each do |k|
26+
r.attributes.each_key do |k|
2627
r.send(k.to_sym)
2728
end
2829
end

benchmark/active_record_threaded.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
56
require 'benchmark/ips'
67
require 'active_record'
78

89
number_of_threads = 25
9-
opts = { :database => 'test', :pool => number_of_threads }
10+
opts = { database: 'test', pool: number_of_threads }
1011

1112
Benchmark.ips do |x|
12-
%w(mysql mysql2).each do |adapter|
13-
ActiveRecord::Base.establish_connection(opts.merge(:adapter => adapter))
13+
%w[mysql mysql2].each do |adapter|
14+
ActiveRecord::Base.establish_connection(opts.merge(adapter: adapter))
1415

1516
x.report(adapter) do
16-
number_of_threads.times.map do
17+
Array.new(number_of_threads) do
1718
Thread.new { ActiveRecord::Base.connection.execute('SELECT SLEEP(1)') }
1819
end.each(&:join)
1920
end

benchmark/allocations.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
@@ -13,7 +14,7 @@ class TestModel < ActiveRecord::Base
1314

1415
def bench_allocations(feature, iterations = 10, batch_size = 1000)
1516
puts "GC overhead for #{feature}"
16-
TestModel.establish_connection(:adapter => 'mysql2', :database => 'test')
17+
TestModel.establish_connection(adapter: 'mysql2', database: 'test')
1718
GC::Profiler.clear
1819
GC::Profiler.enable
1920
iterations.times { yield batch_size }
@@ -23,7 +24,7 @@ def bench_allocations(feature, iterations = 10, batch_size = 1000)
2324

2425
bench_allocations('coercion') do |batch_size|
2526
TestModel.limit(batch_size).to_a.each do |r|
26-
r.attributes.keys.each do |k|
27+
r.attributes.each_key do |k|
2728
r.send(k.to_sym)
2829
end
2930
end

benchmark/escape.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
@@ -15,7 +16,7 @@ def run_escape_benchmarks(str)
1516
mysql.quote str
1617
end
1718

18-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
19+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
1920
x.report "Mysql2 #{str.inspect}" do
2021
mysql2.escape str
2122
end

benchmark/query_with_mysql_casting.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
@@ -41,10 +42,10 @@ def mysql_cast(type, value)
4142
debug = ENV['DEBUG']
4243

4344
Benchmark.ips do |x|
44-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
45+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
4546
mysql2.query "USE #{database}"
4647
x.report "Mysql2" do
47-
mysql2_result = mysql2.query sql, :symbolize_keys => true
48+
mysql2_result = mysql2.query sql, symbolize_keys: true
4849
mysql2_result.each { |res| puts res.inspect if debug }
4950
end
5051

benchmark/query_without_mysql_casting.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
34

45
require 'rubygems'
@@ -13,15 +14,15 @@
1314
debug = ENV['DEBUG']
1415

1516
Benchmark.ips do |x|
16-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
17+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
1718
mysql2.query "USE #{database}"
1819
x.report "Mysql2 (cast: true)" do
19-
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
20+
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: true
2021
mysql2_result.each { |res| puts res.inspect if debug }
2122
end
2223

2324
x.report "Mysql2 (cast: false)" do
24-
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
25+
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: false
2526
mysql2_result.each { |res| puts res.inspect if debug }
2627
end
2728

0 commit comments

Comments
 (0)