Skip to content

Commit

Permalink
Perform auto correct for Performance/RegexpMatch cop
Browse files Browse the repository at this point in the history
* Use RuboCop Performance 1.4.1
* Refer rubocop/rubocop-performance#61 and/or rubocop/rubocop-performance#73

```ruby
$ bundle exec rubocop -a
Inspecting 66 files
..........C..C..C......C.................C........................

Offenses:

lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb:68:21: C: [Corrected] Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
          return if sql =~ /FROM all_/
                    ^^^^^^^^^^^^^^^^^^
lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb:241:26: C: [Corrected] Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
            raise unless e.message =~ /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:321:35: C: [Corrected] Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
            host = "[#{host}]" if host =~ /^[^\[].*:/  # IPv6
                                  ^^^^^^^^^^^^^^^^^^^
lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:323:46: C: [Corrected] Performance/RegexpMatch: Use match? instead of match when MatchData is not used.
            database = "/#{database}" unless database.match(/^\//)
                                             ^^^^^^^^^^^^^^^^^^^^^
lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb:650:46: C: [Corrected] Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
              field["data_default"] = nil if field["data_default"] =~ /^(null|empty_[bc]lob\(\))$/i
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb:183:58: C: [Corrected] Performance/RegexpMatch: Use match? instead of match when MatchData is not used.
      params[:database] = "/#{params[:database]}" unless params[:database].match(/^\//)
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

66 files inspected, 6 offenses detected, 6 offenses corrected
$
```
  • Loading branch information
yahonda committed Sep 9, 2019
1 parent e3f0088 commit 0ed7d70
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Expand Up @@ -65,7 +65,7 @@ def supports_explain?

def explain(arel, binds = [])
sql = "EXPLAIN PLAN FOR #{to_sql(arel, binds)}"
return if sql =~ /FROM all_/
return if /FROM all_/.match?(sql)
if ORACLE_ENHANCED_CONNECTION == :jdbc
exec_query(sql, "EXPLAIN", binds)
else
Expand Down
Expand Up @@ -238,7 +238,7 @@ def with_retry(&block)
begin
yield if block_given?
rescue Java::JavaSql::SQLException => e
raise unless e.message =~ /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
raise unless /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/.match?(e.message)
@active = false
raise unless should_retry
should_retry = false
Expand Down
Expand Up @@ -318,9 +318,9 @@ def self.new_connection(config)
# connection using host, port and database name
elsif host || port
host ||= "localhost"
host = "[#{host}]" if host =~ /^[^\[].*:/ # IPv6
host = "[#{host}]" if /^[^\[].*:/.match?(host) # IPv6
port ||= 1521
database = "/#{database}" unless database.match(/^\//)
database = "/#{database}" unless database.match?(/^\//)
"//#{host}:#{port}#{database}"
# if no host is specified then assume that
# database parameter is TNS alias or TNS connection string
Expand Down
Expand Up @@ -647,7 +647,7 @@ def new_column_from_field(table_name, field)
# If a default contains a newline these cleanup regexes need to
# match newlines.
field["data_default"].sub!(/^'(.*)'$/m, '\1')
field["data_default"] = nil if field["data_default"] =~ /^(null|empty_[bc]lob\(\))$/i
field["data_default"] = nil if /^(null|empty_[bc]lob\(\))$/i.match?(field["data_default"])
# TODO: Needs better fix to fallback "N" to false
field["data_default"] = false if field["data_default"] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings
end
Expand Down
Expand Up @@ -180,7 +180,7 @@
describe "with slash-prefixed database name (service name)" do
before(:all) do
params = CONNECTION_PARAMS.dup
params[:database] = "/#{params[:database]}" unless params[:database].match(/^\//)
params[:database] = "/#{params[:database]}" unless params[:database].match?(/^\//)
@conn = ActiveRecord::ConnectionAdapters::OracleEnhanced::Connection.create(params)
end

Expand Down

0 comments on commit 0ed7d70

Please sign in to comment.