RuboCop: Style/BarePercentLiterals

[skip-stages=Flakey]

auto-corrected

also enable Style/PercentQLiterals forcing uppercase with it, so that
both %q and %Q get changed to bare %

Change-Id: I91389c18d864b3ec638c6cd366c2c74f78c69a57
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/278673
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jacob Burroughs <jburroughs@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2021-11-17 15:29:40 -07:00
parent 4d43809cae
commit a0096a3375
14 changed files with 32 additions and 29 deletions

View File

@ -191,6 +191,8 @@ Specs/EnsureSpecExtension:
Style/Alias:
EnforcedStyle: prefer_alias_method # https://github.com/rubocop/ruby-style-guide/issues/821
Severity: error
Style/BarePercentLiterals:
Severity: error
Style/CaseLikeIf:
Severity: error
Style/ColonMethodCall:
@ -244,6 +246,9 @@ Style/ParenthesesAroundCondition:
Severity: error
Style/PercentLiteralDelimiters:
Severity: error
Style/PercentQLiterals:
EnforcedStyle: upper_case_q
Severity: error
Style/PerlBackrefs:
Enabled: false # Regexp.last_match(1) is far worse than $1
Style/PreferredHashMethods:
@ -365,8 +370,6 @@ Style/NumericLiterals: # TODO: autocorrect
Enabled: false
Style/ParallelAssignment: # TODO: autocorrect (with probable exceptions)
Enabled: false
Style/PercentQLiterals: # TODO: autocorrect
Enabled: false
Style/RedundantSelf: # TODO: autocorrect
Enabled: false
Style/RescueModifier: # TODO

View File

@ -409,7 +409,7 @@ describe CanvasKaltura::ClientV3 do
}]
expect(@kaltura).to receive(:bulkUploadCsv).with(
%Q(the_name,the_desc,the_tags,the_url,the_media_type,"","","","","","",the_partner_data\n)
%(the_name,the_desc,the_tags,the_url,the_media_type,"","","","","","",the_partner_data\n)
)
@kaltura.bulkUploadAdd(files)

View File

@ -41,7 +41,7 @@ describe Qti::AssessmentTestConverter do
def test_section(select)
Nokogiri::XML(<<~XML).at_css('testPart')
<testPart identifier="BaseTestPart">
#{select && %Q(<selection select="#{select}">)}
#{select && %(<selection select="#{select}">)}
</testPart>
XML
end

View File

@ -43,7 +43,7 @@ module InstFS
if !session[:shown_instfs_pixel] && user && enabled?
session[:shown_instfs_pixel] = true
pixel_url = login_pixel_url(token: session_jwt(user, oauth_host))
%Q(<img src="#{pixel_url}" alt="" role="presentation" />).html_safe
%(<img src="#{pixel_url}" alt="" role="presentation" />).html_safe
end
end

View File

@ -195,7 +195,7 @@ unless Rails.env.production? || ARGV.any? { |a| a.start_with?('gems') }
desc "check if spec server is running"
task :status do
if File.exist?(daemonized_server_pid)
$stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).delete("\n")})}
$stderr.puts %{spec_server is running (PID: #{File.read(daemonized_server_pid).delete("\n")})}
else
$stderr.puts "No server running."
end

View File

@ -426,7 +426,7 @@ describe UserContent, type: :request do
end
def confirm_url_stability(url)
link = %Q(<a href="#{url}">what</a>)
link = %(<a href="#{url}">what</a>)
html = tester.process_incoming_html_content(link)
doc = Nokogiri::HTML5.fragment(html)
expect(doc.at_css('a')['href']).to eq url
@ -450,7 +450,7 @@ describe UserContent, type: :request do
end
def confirm_url_stability(url)
link = %Q(<a href="#{url}">what</a>a>)
link = %(<a href="#{url}">what</a>a>)
html = tester.process_incoming_html_content(link)
doc = Nokogiri::HTML5.fragment(html)
expect(doc.at_css('a')['href']).to eq url

View File

@ -474,8 +474,8 @@ describe OAuth2ProviderController do
let(:redis) do
redis = double('Redis')
allow(redis).to receive(:get)
allow(redis).to receive(:get).with(valid_code_redis_key).and_return(%Q({"client_id": #{key.id}, "user": #{user.id}}))
allow(redis).to receive(:del).with(valid_code_redis_key).and_return(%Q({"client_id": #{key.id}, "user": #{user.id}}))
allow(redis).to receive(:get).with(valid_code_redis_key).and_return(%({"client_id": #{key.id}, "user": #{user.id}}))
allow(redis).to receive(:del).with(valid_code_redis_key).and_return(%({"client_id": #{key.id}, "user": #{user.id}}))
redis
end

View File

@ -186,7 +186,7 @@ describe QuizzesHelper do
context 'fill_in_multiple_blanks_question' do
before do
@question_text = %q(<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value={{question_1}}' />)
@question_text = %(<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value={{question_1}}' />)
@answer_list = []
@answers = []
@ -205,7 +205,7 @@ describe QuizzesHelper do
:answers => @answers
)
expect(html).to eq %q(<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value=red' readonly="readonly" aria-label='Fill in the blank, read surrounding text' />)
expect(html).to eq %(<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value=red' readonly="readonly" aria-label='Fill in the blank, read surrounding text' />)
end
it 'sanitizes user input' do
@ -220,7 +220,7 @@ describe QuizzesHelper do
:answers => @answers
)
expect(html).to eq %q|<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value=&gt;&lt;script&gt;alert()&lt;/script&gt;&lt;img' readonly="readonly" aria-label='Fill in the blank, read surrounding text' />|
expect(html).to eq %|<input name="question_1_1813d2a7223184cf43e19db6622df40b" 'value=&gt;&lt;script&gt;alert()&lt;/script&gt;&lt;img' readonly="readonly" aria-label='Fill in the blank, read surrounding text' />|
expect(html).to be_html_safe
end

View File

@ -154,7 +154,7 @@ module Canvas::Plugins::TicketingSystem
it "maps an env hash to a json string" do
report.http_env = { one: "two", three: "four" }
expect(delegate.pretty_http_env).to eq(%Q(one: "two"\nthree: "four"))
expect(delegate.pretty_http_env).to eq(%(one: "two"\nthree: "four"))
end
end
end

View File

@ -440,7 +440,7 @@ describe "Common Cartridge exporting" do
it "does not get confused by attachments with absolute paths" do
@att = Attachment.create!(:filename => 'first.png', :uploaded_data => StringIO.new('ohai'), :folder => Folder.unfiled_folder(@course), :context => @course)
@q1 = @course.quizzes.create(:title => 'quiz1', :description => %Q(<img src="https://example.com/files/#{@att.id}/download?download_frd=1">))
@q1 = @course.quizzes.create(:title => 'quiz1', :description => %(<img src="https://example.com/files/#{@att.id}/download?download_frd=1">))
@ce.export_type = ContentExport::COMMON_CARTRIDGE
run_export
doc = Nokogiri::XML.parse(@zip_file.read("#{mig_id(@q1)}/assessment_meta.xml"))
@ -593,7 +593,7 @@ describe "Common Cartridge exporting" do
it "exports CC 1.3 assignments" do
@file = Attachment.create!(:filename => 'test.txt', :uploaded_data => StringIO.new('ohai'), :folder => Folder.unfiled_folder(@course), :context => @course)
@course.assignments.create! name: 'test assignment', description: %Q(<a href="/courses/#{@course.id}/files/#{@file.id}/preview">what?</a>), points_possible: 11,
@course.assignments.create! name: 'test assignment', description: %(<a href="/courses/#{@course.id}/files/#{@file.id}/preview">what?</a>), points_possible: 11,
submission_types: 'online_text_entry,online_upload,online_url'
@ce.export_type = ContentExport::COMMON_CARTRIDGE
@ce.save!
@ -620,7 +620,7 @@ describe "Common Cartridge exporting" do
expect(extension_node.namespace.href).to eq 'http://canvas.instructure.com/xsd/cccv1p0'
# validate fallback html manifest resource
variant_tag = @manifest_doc.at_css(%Q(resource[identifier="#{assignment_id}_fallback"])).elements.first
variant_tag = @manifest_doc.at_css(%(resource[identifier="#{assignment_id}_fallback"])).elements.first
expect(variant_tag.name).to eq 'variant'
expect(variant_tag.attribute('identifierref').value).to eql assignment_id
expect(variant_tag.next_element.name).to eq 'file'

View File

@ -154,14 +154,14 @@ describe UserContent do
end
it "matches absolute paths with https" do
expect(regex.match(%Q(<a href="https://this-is-terrible.example.com/courses/#{rewriter.context.id}/pages/whatever?srsly=0">)).to_a).to eq([
"https://this-is-terrible.example.com/courses/#{rewriter.context.id}/pages/whatever?srsly=0",
"https://this-is-terrible.example.com",
"/courses/#{rewriter.context.id}",
"pages",
"whatever",
"?srsly=0"
])
expect(regex.match(%(<a href="https://this-is-terrible.example.com/courses/#{rewriter.context.id}/pages/whatever?srsly=0">)).to_a).to eq([
"https://this-is-terrible.example.com/courses/#{rewriter.context.id}/pages/whatever?srsly=0",
"https://this-is-terrible.example.com",
"/courses/#{rewriter.context.id}",
"pages",
"whatever",
"?srsly=0"
])
end
it "doesn't match invalid hostnames" do

View File

@ -152,11 +152,11 @@ describe ContentMigration do
it "preserves new-RCE mediahref iframes" do
att = @copy_from.attachments.create!(:filename => 'videro.mov', :uploaded_data => StringIO.new('...'), :folder => Folder.root_folders(@copy_from).first)
page = @copy_from.wiki_pages.create!(:title => "watch this y'all", :body =>
%Q(<iframe data-media-type="video" src="/media_objects_iframe?mediahref=/courses/#{@copy_from.id}/files/#{att.id}/download" data-media-id="#{att.id}"/>))
%(<iframe data-media-type="video" src="/media_objects_iframe?mediahref=/courses/#{@copy_from.id}/files/#{att.id}/download" data-media-id="#{att.id}"/>))
run_course_copy
att_to = @copy_to.attachments.where(migration_id: mig_id(att)).take
page_to = @copy_to.wiki_pages.where(migration_id: mig_id(page)).take
expect(page_to.body).to include %Q(src="/media_objects_iframe?mediahref=/courses/#{@copy_to.id}/files/#{att_to.id}/download")
expect(page_to.body).to include %(src="/media_objects_iframe?mediahref=/courses/#{@copy_to.id}/files/#{att_to.id}/download")
end
it "references existing usage rights on course copy" do

View File

@ -200,7 +200,7 @@ describe "speed grader submissions" do
end
expect(f('#submission_not_newest_notice')).to be_displayed
f(%Q(#students_selectmenu option[value="#{submission2.user.id}"])).click
f(%(#students_selectmenu option[value="#{submission2.user.id}"])).click
in_frame 'speedgrader_iframe', '.is-inside-submission-frame' do
wait_for_ajaximations

View File

@ -213,7 +213,7 @@ describe "shared/_select_content_dialog" do
view_context
render partial: 'shared/select_content_dialog'
page = Nokogiri(response.body)
expect(page.css(%Q(#quizs_select .module_item_select option[value="quiz_#{existing_quiz.id}"]))).not_to be_empty
expect(page.css(%(#quizs_select .module_item_select option[value="quiz_#{existing_quiz.id}"]))).not_to be_empty
expect(page.css('#quizs_select .module_item_select option[value="new"]')).to be_empty
expect(page.css('#assignments_select .module_item_select option[value="new"]')).to be_empty
end