Skip to content

Commit 74de040

Browse files
authored
Merge pull request #2074 from yahonda/enable_style_redundant_regexp_escape_cop
Enable `Style/RedundantRegexpEscape` cop
2 parents 79fd5cd + cea3db0 commit 74de040

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ Style/RedundantReturn:
204204
Enabled: true
205205
AllowMultipleReturnValues: true
206206

207+
Style/RedundantRegexpEscape:
208+
Enabled: true
209+
207210
Style/Semicolon:
208211
Enabled: true
209212
AllowAsExpressionSeparator: true

lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def new_connection(config)
113113
if database && (using_tns_alias || host == "connection-string")
114114
url = "jdbc:oracle:thin:@#{database}"
115115
else
116-
unless database.match?(/^(\:|\/)/)
116+
unless database.match?(/^(:|\/)/)
117117
# assume database is a SID if no colon or slash are supplied (backward-compatibility)
118118
database = "/#{database}"
119119
end

lib/active_record/connection_adapters/oracle_enhanced/quoting.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def quote_column_name(name) #:nodoc:
1212
name = name.to_s
1313
self.class.quoted_column_names[name] ||= begin
1414
# if only valid lowercase column characters in name
15-
if /\A[a-z][a-z_0-9\$#]*\Z/.match?(name)
15+
if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
1616
"\"#{name.upcase}\""
1717
else
1818
# remove double quotes which cannot be used inside quoted identifier
@@ -27,9 +27,9 @@ def quote_column_name_or_expression(name) #:nodoc:
2727
name = name.to_s
2828
case name
2929
# if only valid lowercase column characters in name
30-
when /^[a-z][a-z_0-9\$#]*$/
30+
when /^[a-z][a-z_0-9$#]*$/
3131
"\"#{name.upcase}\""
32-
when /^[a-z][a-z_0-9\$#\-]*$/i
32+
when /^[a-z][a-z_0-9$#\-]*$/i
3333
"\"#{name}\""
3434
# if other characters present then assume that it is expression
3535
# which should not be quoted

spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def verify_logged_statements
326326
it "should dump definition of single column index" do
327327
@conn.add_context_index :posts, :title
328328
output = dump_table_schema "posts"
329-
expect(output).to match(/add_context_index "posts", \["title"\], name: \"index_posts_on_title\"$/)
329+
expect(output).to match(/add_context_index "posts", \["title"\], name: "index_posts_on_title"$/)
330330
@conn.remove_context_index :posts, :title
331331
end
332332

spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def drop_test_posts_table
7171

7272
it "should be able to dump default values using special characters" do
7373
output = dump_table_schema "test_defaults"
74-
expect(output).to match(/t.string \"special_c\", default: "\\n"/)
74+
expect(output).to match(/t.string "special_c", default: "\\n"/)
7575
end
7676
end
7777

@@ -104,7 +104,7 @@ def drop_test_posts_table
104104

105105
it "should be able to dump ntext columns" do
106106
output = dump_table_schema "test_ntexts"
107-
expect(output).to match(/t.ntext \"ntext_column\"/)
107+
expect(output).to match(/t.ntext "ntext_column"/)
108108
end
109109
end
110110

@@ -370,7 +370,7 @@ class ::TestName < ActiveRecord::Base
370370
expect(output).to match(/t\.virtual "full_name",(\s*)type: :string,(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""/)
371371
expect(output).to match(/t\.virtual "short_name",(\s*)type: :string,(\s*)limit: 300,(\s*)as:(.*)/)
372372
expect(output).to match(/t\.virtual "full_name_length",(\s*)type: :integer,(\s*)precision: 38,(\s*)as:(.*)/)
373-
expect(output).to match(/t\.virtual "name_ratio",(\s*)as:(.*)\"$/) # no :type
373+
expect(output).to match(/t\.virtual "name_ratio",(\s*)as:(.*)"$/) # no :type
374374
expect(output).to match(/t\.virtual "abbrev_name",(\s*)type: :string,(\s*)limit: 100,(\s*)as:(.*)/)
375375
expect(output).to match(/t\.virtual "field_with_leading_space",(\s*)type: :string,(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"/)
376376
end

spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ::TestPost < ActiveRecord::Base
6868
SQL
6969
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
7070
expect(dump.split('\n').length).to eq(1)
71-
expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOO\"? FOREIGN KEY \(\"?FOO_ID\"?\) REFERENCES \"?FOOS\"?\(\"?ID\"?\)/i)
71+
expect(dump).to match(/ALTER TABLE "?TEST_POSTS"? ADD CONSTRAINT "?FK_TEST_POST_FOO"? FOREIGN KEY \("?FOO_ID"?\) REFERENCES "?FOOS"?\("?ID"?\)/i)
7272
end
7373

7474
it "should dump foreign keys when reference column name is not 'id'" do
@@ -88,7 +88,7 @@ class ::TestPost < ActiveRecord::Base
8888

8989
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
9090
expect(dump.split('\n').length).to eq(1)
91-
expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\)/i)
91+
expect(dump).to match(/ALTER TABLE "?TEST_POSTS"? ADD CONSTRAINT "?FK_TEST_POST_BAZ"? FOREIGN KEY \("?BAZ_ID"?\) REFERENCES "?FOOS"?\("?BAZ_ID"?\)/i)
9292
end
9393

9494
it "should not error when no foreign keys are present" do
@@ -136,7 +136,7 @@ class ::TestPost < ActiveRecord::Base
136136
)
137137
SQL
138138
dump = ActiveRecord::Base.connection.structure_dump
139-
expect(dump).to match(/\"?ID_PLUS\"? NUMBER GENERATED ALWAYS AS \(ID\+2\) VIRTUAL/)
139+
expect(dump).to match(/"?ID_PLUS"? NUMBER GENERATED ALWAYS AS \(ID\+2\) VIRTUAL/)
140140
end
141141

142142
it "should dump RAW virtual columns" do
@@ -149,7 +149,7 @@ class ::TestPost < ActiveRecord::Base
149149
)
150150
SQL
151151
dump = ActiveRecord::Base.connection.structure_dump
152-
expect(dump).to match(/CREATE TABLE \"BARS\" \(\n \"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\) GENERATED ALWAYS AS \(HEXTORAW\(TO_CHAR\(ID\)\)\) VIRTUAL/)
152+
expect(dump).to match(/CREATE TABLE "BARS" \(\n "ID" NUMBER\(38,0\) NOT NULL,\n "SUPER" RAW\(255\) GENERATED ALWAYS AS \(HEXTORAW\(TO_CHAR\(ID\)\)\) VIRTUAL/)
153153
end
154154

155155
it "should dump NCLOB columns" do
@@ -161,7 +161,7 @@ class ::TestPost < ActiveRecord::Base
161161
)
162162
SQL
163163
dump = ActiveRecord::Base.connection.structure_dump
164-
expect(dump).to match(/CREATE TABLE \"BARS\" \(\n \"ID\" NUMBER\(38,0\) NOT NULL,\n \"NCLOB_TEXT\" NCLOB/)
164+
expect(dump).to match(/CREATE TABLE "BARS" \(\n "ID" NUMBER\(38,0\) NOT NULL,\n "NCLOB_TEXT" NCLOB/)
165165
end
166166

167167
it "should dump unique keys" do
@@ -187,7 +187,7 @@ class ::TestPost < ActiveRecord::Base
187187

188188
dump = ActiveRecord::Base.connection.structure_dump
189189
expect(dump).to match(/CREATE UNIQUE INDEX "?IX_TEST_POSTS_FOO_ID"? ON "?TEST_POSTS"? \("?FOO_ID"?\)/i)
190-
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FOO\"? ON "?TEST_POSTS"? \("?FOO"?\)/i)
190+
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FOO"? ON "?TEST_POSTS"? \("?FOO"?\)/i)
191191
expect(dump).not_to match(/CREATE UNIQUE INDEX "?UK_TEST_POSTS_/i)
192192
end
193193

@@ -199,8 +199,8 @@ class ::TestPost < ActiveRecord::Base
199199
SQL
200200

201201
dump = ActiveRecord::Base.connection.structure_dump
202-
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FOO_FOO_ID\"? ON "?TEST_POSTS"? \("?FOO"?, "?FOO_ID"?\)/i)
203-
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FUNCTION\"? ON "?TEST_POSTS"? \(TO_CHAR\(LENGTH\("?FOO"?\)\)\|\|"?FOO"?\)/i)
202+
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FOO_FOO_ID"? ON "?TEST_POSTS"? \("?FOO"?, "?FOO_ID"?\)/i)
203+
expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FUNCTION"? ON "?TEST_POSTS"? \(TO_CHAR\(LENGTH\("?FOO"?\)\)\|\|"?FOO"?\)/i)
204204
end
205205

206206
it "should dump RAW columns" do
@@ -212,7 +212,7 @@ class ::TestPost < ActiveRecord::Base
212212
)
213213
SQL
214214
dump = ActiveRecord::Base.connection.structure_dump
215-
expect(dump).to match(/CREATE TABLE \"BARS\" \(\n \"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\)/)
215+
expect(dump).to match(/CREATE TABLE "BARS" \(\n "ID" NUMBER\(38,0\) NOT NULL,\n "SUPER" RAW\(255\)/)
216216
end
217217

218218
it "should dump table comments" do
@@ -269,7 +269,7 @@ class ::TestPost < ActiveRecord::Base
269269
end
270270
context "default sequence" do
271271
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\"" }
272-
it { is_expected.to_not match(%r{CREATE SEQUENCE \"#{sequence_name}" MAXVALUE \d+ MINVALUE \d+ NOORDER NOCYCLE}) }
272+
it { is_expected.to_not match(%r{CREATE SEQUENCE "#{sequence_name}" MAXVALUE \d+ MINVALUE \d+ NOORDER NOCYCLE}) }
273273
end
274274
context "noorder" do
275275
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\" NOORDER" }

spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class ::TestEmployee2 < ActiveRecord::Base
9999

100100
it "should get sequence value at next time" do
101101
TestEmployee.create!
102-
expect(@logger.logged(:debug).first).not_to match(/SELECT \"TEST_EMPLOYEES_SEQ\".NEXTVAL FROM dual/im)
102+
expect(@logger.logged(:debug).first).not_to match(/SELECT "TEST_EMPLOYEES_SEQ".NEXTVAL FROM dual/im)
103103
@logger.clear(:debug)
104104
TestEmployee.create!
105-
expect(@logger.logged(:debug).first).to match(/SELECT \"TEST_EMPLOYEES_SEQ\".NEXTVAL FROM dual/im)
105+
expect(@logger.logged(:debug).first).to match(/SELECT "TEST_EMPLOYEES_SEQ".NEXTVAL FROM dual/im)
106106
end
107107
end
108108
end

0 commit comments

Comments
 (0)