Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade RuboCop to v1.30 #1268

Merged
merged 7 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
BUNDLE_WITHOUT: development
steps:
- uses: actions/checkout@v3
- name: Set up Ruby 2.4
- name: Set up Ruby 2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.4
ruby-version: 2.6
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run RuboCop
run: bundle exec rubocop
14 changes: 11 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.0
SuggestExtensions: false
NewCops: disable

DisplayCopNames: true
Exclude:
Expand All @@ -12,16 +14,22 @@ AllCops:
Layout/CaseIndentation:
EnforcedStyle: end

Layout/IndentHash:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Lint/EndAlignment:
Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Layout/HashAlignment:
EnforcedHashRocketStyle: table

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrivialAccessors:
Expand Down
145 changes: 113 additions & 32 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,176 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-11-25 19:54:28 -0500 using RuboCop version 0.50.0.
# on 2022-05-30 13:48:55 UTC using RuboCop version 1.30.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: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
# This cop supports safe autocorrection (--autocorrect).
Layout/HeredocIndentation:
Exclude:
- 'support/ruby_enc_to_mysql.rb'
- 'tasks/compile.rake'

# Offense count: 2
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/mysql2/client_spec.rb'
- 'tasks/rspec.rake'

# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'lib/mysql2/em.rb'

# Offense count: 2
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 91
Max: 94

# Offense count: 31
# Configuration parameters: CountComments, ExcludedMethods.
# Offense count: 34
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 860
Max: 592

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

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 135

# Offense count: 3
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 32

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

# Offense count: 6
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 57

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 29
Max: 32

# Offense count: 3
# Configuration parameters: Blacklist.
# Blacklist: END, (?-mix:EO[A-Z]{1})
# Offense count: 2
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'tasks/compile.rake'

# Offense count: 10
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CaseLikeIf:
Exclude:
- 'ext/mysql2/extconf.rb'

# Offense count: 8
# Configuration parameters: AllowedConstants.
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/result.rb'
- 'lib/mysql2/statement.rb'

# Offense count: 14
# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
Style/ExpandPathArguments:
Exclude:
- 'ext/mysql2/extconf.rb'
- 'mysql2.gemspec'
- 'spec/mysql2/client_spec.rb'
- 'support/mysql_enc_to_ruby.rb'
- 'tasks/compile.rake'

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

# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: Strict.
# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/mysql2.rb'
- 'lib/mysql2/client.rb'
- 'spec/mysql2/client_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMethodComparison.
Style/MultipleComparison:
Exclude:
- 'lib/mysql2/client.rb'

# Offense count: 18
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Strict, AllowedNumbers.
Style/NumericLiterals:
MinDigits: 20

# Offense count: 726
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'benchmark/setup_db.rb'
- 'ext/mysql2/extconf.rb'
- 'lib/mysql2/em.rb'

# Offense count: 14
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'benchmark/active_record.rb'
- 'benchmark/active_record_threaded.rb'
- 'benchmark/allocations.rb'
- 'benchmark/escape.rb'
- 'benchmark/query_with_mysql_casting.rb'
- 'benchmark/query_without_mysql_casting.rb'
- 'benchmark/sequel.rb'
- 'benchmark/setup_db.rb'
- 'ext/mysql2/extconf.rb'
- 'lib/mysql2/client.rb'
- 'tasks/compile.rake'

# Offense count: 782
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: percent
MinSize: 4

# Offense count: 32
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 232
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ source 'https://rubygems.org'

gemspec

gem 'rake', if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
'~> 13.0.1'
else
'< 13'
end
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the next release could drop Ruby < 2.2

Copy link
Contributor Author

@mishina2228 mishina2228 Jun 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to omit if-else condition, but rake 13.x supports only Ruby 2.2+.
So can we drop Ruby 2.1 from the CI matrix?

ruby:
- '3.1'
- '3.0'
- '2.7'
- '2.6'
- '2.5'
- '2.4'
- '2.3'
- '2.2'
- '2.1'

and also CentOS 7 with Ruby 2.0.0?

# CentOS 7 system Ruby is the fixed version 2.0.0.
- {distro: centos, image: 'centos:7', name_extra: 'ruby 2.0.0'}

gem 'rake', '~> 13.0.1'
else
gem 'rake', '< 13'
end
gem 'rake-compiler', '~> 1.1.0'

# For local debugging, irb is Gemified since Ruby 2.6
Expand All @@ -19,7 +19,7 @@ group :test do
# Downgrade psych because old RuboCop can't use new Psych
gem 'psych', '< 4.0.0'
mishina2228 marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/bbatsov/rubocop/pull/4789
gem 'rubocop', '~> 0.50.0'
gem 'rubocop', '~> 1.30' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
end

group :benchmarks, optional: true do
Expand Down
2 changes: 1 addition & 1 deletion benchmark/allocations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def bench_allocations(feature, iterations = 10, batch_size = 1000)
GC::Profiler.clear
GC::Profiler.enable
iterations.times { yield batch_size }
GC::Profiler.report(STDOUT)
GC::Profiler.report($stdout)
GC::Profiler.disable
end

Expand Down
2 changes: 1 addition & 1 deletion ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def add_ssl_defines(header)
end
end

unless disabled_sanitizers.empty?
unless disabled_sanitizers.empty? # rubocop:disable Style/IfUnlessModifier
abort "-----\nCould not enable requested sanitizers: #{disabled_sanitizers.join(',')}\n-----"
end

Expand Down
1 change: 1 addition & 0 deletions lib/mysql2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module Util
#
def self.key_hash_as_symbols(hash)
return nil unless hash

Hash[hash.map { |k, v| [k.to_sym, v] }]
end

Expand Down
4 changes: 4 additions & 0 deletions lib/mysql2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def self.default_query_options

def initialize(opts = {})
raise Mysql2::Error, "Options parameter must be a Hash" unless opts.is_a? Hash

opts = Mysql2::Util.key_hash_as_symbols(opts)
@read_timeout = nil
@query_options = self.class.default_query_options.dup
Expand All @@ -33,6 +34,7 @@ def initialize(opts = {})
# TODO: stricter validation rather than silent massaging
%i[reconnect connect_timeout local_infile read_timeout write_timeout default_file default_group secure_auth init_command automatic_close enable_cleartext_plugin default_auth].each do |key|
next unless opts.key?(key)

case key
when :reconnect, :local_infile, :secure_auth, :automatic_close, :enable_cleartext_plugin
send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation
Expand Down Expand Up @@ -136,6 +138,7 @@ def find_default_ca_path
# and performance_schema.session_account_connect_attrs
def parse_connect_attrs(conn_attrs)
return {} if Mysql2::Client::CONNECT_ATTRS.zero?

conn_attrs ||= {}
conn_attrs[:program_name] ||= $PROGRAM_NAME
conn_attrs.each_with_object({}) do |(key, value), hash|
Expand All @@ -152,6 +155,7 @@ def query(sql, options = {})
def query_info
info = query_info_string
return {} unless info

info_hash = {}
info.split.each_slice(2) { |s| info_hash[s[0].downcase.delete(':').to_sym] = s[1].to_i }
info_hash
Expand Down
2 changes: 2 additions & 0 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

Klient = Class.new(Mysql2::Client) do
attr_reader :connect_args

def connect(*args)
@connect_args ||= []
@connect_args << args
Expand Down Expand Up @@ -212,6 +213,7 @@ def run_gc
10.times do
closed = @client.query("SHOW PROCESSLIST").none? { |row| row['Id'] == connection_id }
break if closed

sleep(0.1)
end
expect(closed).to eq(true)
Expand Down
18 changes: 9 additions & 9 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,17 @@
end

{
'char_test' => 'CHAR',
'varchar_test' => 'VARCHAR',
'varbinary_test' => 'VARBINARY',
'tiny_blob_test' => 'TINYBLOB',
'tiny_text_test' => 'TINYTEXT',
'blob_test' => 'BLOB',
'text_test' => 'TEXT',
'char_test' => 'CHAR',
'varchar_test' => 'VARCHAR',
'varbinary_test' => 'VARBINARY',
'tiny_blob_test' => 'TINYBLOB',
'tiny_text_test' => 'TINYTEXT',
'blob_test' => 'BLOB',
'text_test' => 'TEXT',
'medium_blob_test' => 'MEDIUMBLOB',
'medium_text_test' => 'MEDIUMTEXT',
'long_blob_test' => 'LONGBLOB',
'long_text_test' => 'LONGTEXT',
'long_blob_test' => 'LONGBLOB',
'long_text_test' => 'LONGTEXT',
}.each do |field, type|
it "should return a String for #{type}" do
expect(test_result[field]).to be_an_instance_of(String)
Expand Down
Loading