Skip to content

Commit

Permalink
Merge pull request #752 from tamird/update-rubocop
Browse files Browse the repository at this point in the history
Update RuboCop to 0.50.x
  • Loading branch information
sodabrew authored Nov 27, 2017
2 parents e84b6ce + d89f241 commit 17fe755
Show file tree
Hide file tree
Showing 36 changed files with 402 additions and 348 deletions.
32 changes: 18 additions & 14 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 1.9

DisplayCopNames: true
Exclude:
- 'pkg/**/*'
- 'tmp/**/*'
- 'vendor/**/*'

Layout/CaseIndentation:
EnforcedStyle: end

Layout/IndentHash:
EnforcedStyle: consistent

Layout/IndentHeredoc:
EnforcedStyle: powerpack

Lint/EndAlignment:
AlignWith: variable
EnforcedStyleAlignWith: variable

Style/CaseIndentation:
IndentWhenRelativeTo: end
Style/Encoding:
AutoCorrectEncodingComment: '# encoding: UTF-8'
EnforcedStyle: always

Style/IndentHash:
EnforcedStyle: consistent
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingComma:
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrivialAccessors:
AllowPredicates: true

# TODO: remove when we end support for < 1.9.3

Style/HashSyntax:
EnforcedStyle: hash_rockets

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

# Offense count: 2
Metrics/AbcSize:
Max: 93
Max: 90

# Offense count: 31
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 825

# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 5

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 125

# Offense count: 2
# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 30

# Offense count: 290
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 313
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 232

# Offense count: 5
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 60
Max: 57

# Offense count: 1
# Offense count: 2
Metrics/PerceivedComplexity:
Max: 27

# Offense count: 40
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters:
Enabled: false
# Offense count: 3
# Configuration parameters: Blacklist.
# Blacklist: END, (?-mix:EO[A-Z]{1})
Naming/HeredocDelimiterNaming:
Exclude:
- 'tasks/compile.rake'

# Offense count: 12
# Offense count: 10
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'benchmark/active_record.rb'
- 'benchmark/allocations.rb'
- 'benchmark/query_with_mysql_casting.rb'
- 'lib/mysql2.rb'
- 'lib/mysql2/client.rb'
- 'lib/mysql2/em.rb'
- 'lib/mysql2/error.rb'
- 'lib/mysql2/field.rb'
- 'lib/mysql2/result.rb'
- 'lib/mysql2/statement.rb'
- 'lib/mysql2/version.rb'

# Offense count: 9
# Offense count: 14
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Exclude:
- 'ext/mysql2/extconf.rb'

# Offense count: 14
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: Strict.
Style/NumericLiterals:
MinDigits: 20

# Offense count: 680
# Offense count: 726
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: UTF-8

source 'https://rubygems.org'

gemspec
Expand All @@ -8,7 +10,9 @@ gem 'rake-compiler', '~> 1.0'
group :test do
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
gem 'rspec', '~> 3.2'
gem 'rubocop', '~> 0.34.0'
# https://github.com/bbatsov/rubocop/pull/3328
# https://github.com/bbatsov/rubocop/pull/4789
gem 'rubocop', '~> 0.50.0' unless RUBY_VERSION =~ /1.9/
end

group :benchmarks do
Expand Down
19 changes: 7 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

require 'rake'

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

# TODO: remove engine check when rubinius stops crashing on RuboCop
has_rubocop = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task :default => [:spec, :rubocop]
rescue LoadError # rubocop:disable Lint/HandleExceptions
end
end

unless has_rubocop
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task default: [:spec, :rubocop]
rescue LoadError
warn 'RuboCop is not available'
task :default => :spec
task default: :spec
end
9 changes: 5 additions & 4 deletions benchmark/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand All @@ -8,7 +9,7 @@
ActiveRecord::Base.default_timezone = :local
ActiveRecord::Base.time_zone_aware_attributes = true

opts = { :database => 'test' }
opts = { database: 'test' }

class TestModel < ActiveRecord::Base
self.table_name = 'mysql2_test'
Expand All @@ -17,12 +18,12 @@ class TestModel < ActiveRecord::Base
batch_size = 1000

Benchmark.ips do |x|
%w(mysql mysql2).each do |adapter|
TestModel.establish_connection(opts.merge(:adapter => adapter))
%w[mysql mysql2].each do |adapter|
TestModel.establish_connection(opts.merge(adapter: adapter))

x.report(adapter) do
TestModel.limit(batch_size).to_a.each do |r|
r.attributes.keys.each do |k|
r.attributes.each_key do |k|
r.send(k.to_sym)
end
end
Expand Down
9 changes: 5 additions & 4 deletions benchmark/active_record_threaded.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark/ips'
require 'active_record'

number_of_threads = 25
opts = { :database => 'test', :pool => number_of_threads }
opts = { database: 'test', pool: number_of_threads }

Benchmark.ips do |x|
%w(mysql mysql2).each do |adapter|
ActiveRecord::Base.establish_connection(opts.merge(:adapter => adapter))
%w[mysql mysql2].each do |adapter|
ActiveRecord::Base.establish_connection(opts.merge(adapter: adapter))

x.report(adapter) do
number_of_threads.times.map do
Array.new(number_of_threads) do
Thread.new { ActiveRecord::Base.connection.execute('SELECT SLEEP(1)') }
end.each(&:join)
end
Expand Down
5 changes: 3 additions & 2 deletions benchmark/allocations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

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

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

bench_allocations('coercion') do |batch_size|
TestModel.limit(batch_size).to_a.each do |r|
r.attributes.keys.each do |k|
r.attributes.each_key do |k|
r.send(k.to_sym)
end
end
Expand Down
3 changes: 2 additions & 1 deletion benchmark/escape.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand All @@ -15,7 +16,7 @@ def run_escape_benchmarks(str)
mysql.quote str
end

mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
x.report "Mysql2 #{str.inspect}" do
mysql2.escape str
end
Expand Down
5 changes: 3 additions & 2 deletions benchmark/query_with_mysql_casting.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down Expand Up @@ -41,10 +42,10 @@ def mysql_cast(type, value)
debug = ENV['DEBUG']

Benchmark.ips do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
mysql2.query "USE #{database}"
x.report "Mysql2" do
mysql2_result = mysql2.query sql, :symbolize_keys => true
mysql2_result = mysql2.query sql, symbolize_keys: true
mysql2_result.each { |res| puts res.inspect if debug }
end

Expand Down
7 changes: 4 additions & 3 deletions benchmark/query_without_mysql_casting.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand All @@ -13,15 +14,15 @@
debug = ENV['DEBUG']

Benchmark.ips do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
mysql2.query "USE #{database}"
x.report "Mysql2 (cast: true)" do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: true
mysql2_result.each { |res| puts res.inspect if debug }
end

x.report "Mysql2 (cast: false)" do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: false
mysql2_result.each { |res| puts res.inspect if debug }
end

Expand Down
1 change: 1 addition & 0 deletions benchmark/sequel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
Loading

0 comments on commit 17fe755

Please sign in to comment.