Skip to content

Commit

Permalink
Merge pull request #10057 from saraycp/rubocop_autocorrect_IX_various
Browse files Browse the repository at this point in the history
Correct Rubocop Style/RegexpLiteral in various files
  • Loading branch information
hennevogel committed Aug 24, 2020
2 parents b8a12f2 + a60ab62 commit ff674b0
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 31 deletions.
16 changes: 0 additions & 16 deletions src/api/.rubocop_todo.yml
Expand Up @@ -1380,22 +1380,6 @@ Style/OptionalBooleanParameter:
- 'app/policies/package_policy.rb'
- 'lib/xpath_engine.rb'

# Offense count: 87
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'app/helpers/webui/webui_helper.rb'
- 'app/mixins/build_log_support.rb'
- 'app/services/package_service/file_verifier.rb'
- 'app/services/trigger_controller_service/token_extractor.rb'
- 'config/routes/webui_routes.rb'
- 'lib/api_error.rb'
- 'lib/tasks/coverage.rake'
- 'lib/tasks/extract.rake'
- 'lib/tasks/test_webui.rake'

# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/helpers/webui/webui_helper.rb
Expand Up @@ -167,7 +167,7 @@ def force_utf8_and_transform_nonprintables(text)
text.force_encoding('UTF-8')
text = 'The file you look at is not valid UTF-8 text. Please convert the file.' unless text.valid_encoding?
# Ged rid of stuff that shouldn't be part of PCDATA:
text.gsub(/([^a-zA-Z0-9&;<>\/\n \t()])/) do
text.gsub(%r{([^a-zA-Z0-9&;<>/\n \t()])}) do
if Regexp.last_match(1)[0].getbyte(0) < 32
''
else
Expand Down Expand Up @@ -266,7 +266,7 @@ def creator_intentions(role = nil)

def replace_jquery_meta_characters(input)
# The stated characters are c&p from https://api.jquery.com/category/selectors/
input.gsub(/[!"#$%&'()*+,.\/:\\;<=>?@\[\]^`{|}~]/, '_')
input.gsub(%r{[!"#$%&'()*+,./:\\;<=>?@\[\]^`{|}~]}, '_')
end

def word_break(string, length = 80)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/mixins/build_log_support.rb
Expand Up @@ -7,7 +7,7 @@ def raw_log_chunk(project, package, repo, arch, start, theend)
def get_log_chunk(project, package, repo, arch, start, theend)
log = raw_log_chunk(project, package, repo, arch, start, theend)
log.encode!(invalid: :replace, undef: :replace, cr_newline: true)
log.gsub(/([^a-zA-Z0-9&;<>\/\n\r \t()])/) do |c|
log.gsub(%r{([^a-zA-Z0-9&;<>/\n\r \t()])}) do |c|
if c.ord < 32
''
else
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/services/package_service/file_verifier.rb
Expand Up @@ -27,7 +27,7 @@ def content_readable(content)
end

def file_name_invalid?
@file_name.blank? || @file_name !~ /^[^.\/][^\/]+$/
@file_name.blank? || @file_name !~ %r{^[^./][^/]+$}
end

def service?
Expand Down
Expand Up @@ -19,7 +19,7 @@ def extract_auth_token
end

def valid?
@auth_token.present? && @auth_token[0..4] == 'Token' && @auth_token[6..-1].match?(/^[A-Za-z0-9+\/]+$/)
@auth_token.present? && @auth_token[0..4] == 'Token' && @auth_token[6..-1].match?(%r{^[A-Za-z0-9+/]+$})
end

# it will return a Token subclass or raise ActiveRecord::RecordNotFound
Expand Down
6 changes: 3 additions & 3 deletions src/api/config/routes/webui_routes.rb
Expand Up @@ -337,18 +337,18 @@
resource :session, only: [:new, :create, :destroy], controller: 'webui/session'

controller 'webui/groups/bs_requests' do
get 'groups/(:title)/requests' => :index, constraints: { title: /[^\/]*/ }, as: 'group_requests'
get 'groups/(:title)/requests' => :index, constraints: { title: %r{[^/]*} }, as: 'group_requests'
end

controller 'webui/groups' do
get 'groups' => :index
get 'group/show/:title' => :show, constraints: { title: /[^\/]*/ }, as: 'group_show'
get 'group/show/:title' => :show, constraints: { title: %r{[^/]*} }, as: 'group_show'
get 'group/new' => :new
post 'group/create' => :create
get 'group/autocomplete' => :autocomplete, as: 'autocomplete_groups'
end

resources :groups, only: [], param: :title, constraints: { title: /[^\/]*/ } do
resources :groups, only: [], param: :title, constraints: { title: %r{[^/]*} } do
resources :user, only: [:create, :destroy, :update], constraints: cons, param: :user_login, controller: 'webui/groups/users'
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/api_error.rb
Expand Up @@ -26,7 +26,7 @@ def errorcode

err = self.class.name.demodulize.underscore
# if the class name stops with Error, strip that
err.gsub(%r{_error$}, '')
err.gsub(/_error$/, '')
end

def status
Expand Down
6 changes: 3 additions & 3 deletions src/api/lib/tasks/coverage.rake
Expand Up @@ -29,11 +29,11 @@ namespace :ci do
SimpleCov.merge_timeout 100_000

SimpleCov.configure do
add_group('WebUI') { |file| file.filename =~ %r{webui} }
add_group('WebUI') { |file| file.filename =~ /webui/ }
add_group('Jobs') { |file| file.filename =~ %r{jobs/} }
add_group('Models') { |file| file.filename =~ %r{models/} }
add_group('Helpers') { |file| file.filename =~ %r{helpers/} && file.filename !~ %r{webui} }
add_group('API Controllers') { |file| file.filename =~ %r{controllers/} && file.filename !~ %r{webui} }
add_group('Helpers') { |file| file.filename =~ %r{helpers/} && file.filename !~ /webui/ }
add_group('API Controllers') { |file| file.filename =~ %r{controllers/} && file.filename !~ /webui/ }
end

# upload the result for all
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/tasks/extract.rake
Expand Up @@ -7,7 +7,7 @@ def local_to_yaml(hash, file)
keys.each_with_index do |k, index| # <-- here's my addition (the 'sort')
v = hash[k]
k = "record_#{index}" if k.is_a?(Integer)
file.write({ k => v }.to_yaml(SortKeys: true, ExplicitTypes: true).gsub(%r{^---\s*}, ''))
file.write({ k => v }.to_yaml(SortKeys: true, ExplicitTypes: true).gsub(/^---\s*/, ''))
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/lib/tasks/test_webui.rake
Expand Up @@ -5,7 +5,7 @@ Rake::TestTask.new do |t|
t.libs << 'test'
test_files = FileList['test/unit/*_test.rb']
test_files += FileList['test/models/*_test.rb']
test_files += FileList['test/**/*_test.rb'].exclude(%r{webui}).exclude(%r{test/models}).exclude(%r{test/unit})
test_files += FileList['test/**/*_test.rb'].exclude(/webui/).exclude(%r{test/models}).exclude(%r{test/unit})
t.test_files = test_files
t.name = 'test:api'
t.warning = false
Expand Down Expand Up @@ -46,7 +46,7 @@ end

Rake::TestTask.new do |t|
t.libs << 'test'
files = FileList['test/functional/**/*_test.rb'].exclude(%r{spider_test})
files = FileList['test/functional/**/*_test.rb'].exclude(/spider_test/)
SAFE_TESTS.each do |file|
files.exclude(file)
end
Expand Down

0 comments on commit ff674b0

Please sign in to comment.