Skip to content

Commit a20a7f4

Browse files
committed
Refactor the code in accordance with adjusted Rubocop rules
1 parent 303004f commit a20a7f4

36 files changed

+137
-276
lines changed

.rubocop_todo.yml

+1-164
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,23 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-07-28 17:33:15 +0200 using RuboCop version 0.49.1.
3+
# on 2017-07-31 15:28:00 +0200 using RuboCop version 0.49.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 1
10-
# Cop supports --auto-correct.
11-
Layout/EmptyLinesAroundExceptionHandlingKeywords:
12-
Exclude:
13-
- 'app/controllers/services_controller.rb'
14-
15-
# Offense count: 19
16-
# Cop supports --auto-correct.
17-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
18-
# SupportedStyles: space, no_space
19-
# SupportedStylesForEmptyBraces: space, no_space
20-
Layout/SpaceInsideBlockBraces:
21-
Exclude:
22-
- 'bin/spring'
23-
- 'config/spring.rb'
24-
- 'lib/rmt/downloader.rb'
25-
- 'lib/rmt/rpm/base_parser.rb'
26-
- 'lib/tasks/potato.rake'
27-
- 'spec/factories/products.rb'
28-
- 'spec/factories/repositories.rb'
29-
- 'spec/factories/systems.rb'
30-
- 'spec/rails_helper.rb'
31-
- 'spec/requests/services_controller_spec.rb'
32-
33-
# Offense count: 3
34-
RSpec/EmptyLineAfterFinalLet:
35-
Exclude:
36-
- 'spec/lib/rmt/rpm/deltainfo_xml_parser_spec.rb'
37-
- 'spec/lib/rmt/rpm/repomd_xml_parser_spec.rb'
38-
- 'spec/models/activation_spec.rb'
39-
40-
# Offense count: 16
41-
RSpec/EmptyLineAfterSubject:
42-
Exclude:
43-
- 'spec/models/siebel/activity_spec.rb'
44-
- 'spec/models/repository_spec.rb'
45-
- 'spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb'
46-
- 'spec/requests/api/connect/v3/systems/products_controller_spec.rb'
47-
- 'spec/requests/api/connect/v3/systems/systems_controller_spec.rb'
48-
- 'spec/requests/api/connect/v4/systems/products_controller_spec.rb'
49-
- 'spec/support/shared_examples/product_checks.rb'
50-
51-
# Offense count: 2
5210
# Configuration parameters: Max.
5311
RSpec/ExampleLength:
5412
Exclude:
5513
- 'spec/features/**/*'
56-
- 'spec/lib/rmt/rpm/primary_xml_parser_spec.rb'
5714
- 'spec/lib/rmt/rpm/repomd_xml_parser_spec.rb'
5815

59-
# Offense count: 29
60-
# Configuration parameters: EnforcedStyle, SupportedStyles.
61-
# SupportedStyles: is_expected, should
62-
RSpec/ImplicitExpect:
63-
Exclude:
64-
- 'spec/models/activation_spec.rb'
65-
- 'spec/models/product_spec.rb'
66-
- 'spec/models/repository_spec.rb'
67-
- 'spec/models/service_spec.rb'
68-
- 'spec/models/system_spec.rb'
69-
7016
# Offense count: 1
7117
RSpec/IteratedExpectation:
7218
Exclude:
7319
- 'spec/requests/api/connect/v3/systems/activations_controller_spec.rb'
7420

75-
# Offense count: 11
76-
RSpec/LeadingSubject:
77-
Exclude:
78-
- 'spec/models/activation_spec.rb'
79-
- 'spec/models/product_spec.rb'
80-
- 'spec/models/service_spec.rb'
81-
- 'spec/models/system_spec.rb'
82-
- 'spec/requests/api/connect/v3/systems/products_controller_spec.rb'
83-
- 'spec/requests/api/connect/v4/systems/products_controller_spec.rb'
84-
- 'spec/requests/services_controller_spec.rb'
85-
- 'spec/support/shared_examples/product_checks.rb'
86-
87-
# Offense count: 1
88-
RSpec/NamedSubject:
89-
Exclude:
90-
- 'spec/lib/rmt/downloader_spec.rb'
91-
9221
# Offense count: 19
9322
# Configuration parameters: Max.
9423
RSpec/NestedGroups:
@@ -100,95 +29,3 @@ RSpec/NestedGroups:
10029
- 'spec/requests/api/connect/v3/systems/systems_controller_spec.rb'
10130
- 'spec/requests/api/connect/v4/systems/products_controller_spec.rb'
10231
- 'spec/requests/services_controller_spec.rb'
103-
104-
# Offense count: 1
105-
# Configuration parameters: EnforcedStyle, SupportedStyles.
106-
# SupportedStyles: not_to, to_not
107-
RSpec/NotToNot:
108-
Exclude:
109-
- 'spec/models/service_spec.rb'
110-
111-
# Offense count: 4
112-
RSpec/ScatteredLet:
113-
Exclude:
114-
- 'spec/models/service_spec.rb'
115-
- 'spec/models/system_spec.rb'
116-
117-
# Offense count: 1
118-
# Cop supports --auto-correct.
119-
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
120-
Rails/Blank:
121-
Exclude:
122-
- 'spec/factories/systems.rb'
123-
124-
# Offense count: 1
125-
# Cop supports --auto-correct.
126-
# Configuration parameters: Whitelist.
127-
# Whitelist: find_by_sql
128-
Rails/DynamicFindBy:
129-
Exclude:
130-
- 'app/models/system.rb'
131-
132-
# Offense count: 2
133-
Rails/FilePath:
134-
Exclude:
135-
- 'config/environments/development.rb'
136-
- 'spec/rails_helper.rb'
137-
138-
# Offense count: 1
139-
# Cop supports --auto-correct.
140-
# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank.
141-
Rails/Present:
142-
Exclude:
143-
- 'app/controllers/api/connect/v3/systems/products_controller.rb'
144-
145-
# Offense count: 7
146-
# Cop supports --auto-correct.
147-
# Configuration parameters: EnforcedStyle, SupportedStyles.
148-
# SupportedStyles: always, conditionals
149-
Style/AndOr:
150-
Exclude:
151-
- 'bin/rmt-mirror'
152-
- 'lib/rmt/downloader.rb'
153-
- 'lib/rmt/rpm/deltainfo_xml_parser.rb'
154-
- 'lib/rmt/rpm/primary_xml_parser.rb'
155-
- 'lib/suse/connect/api.rb'
156-
157-
# Offense count: 3
158-
# Cop supports --auto-correct.
159-
# Configuration parameters: InverseMethods, InverseBlocks.
160-
Style/InverseMethods:
161-
Exclude:
162-
- 'lib/tasks/potato.rake'
163-
164-
# Offense count: 2
165-
# Cop supports --auto-correct.
166-
Style/MultilineIfModifier:
167-
Exclude:
168-
- 'lib/rmt/rpm/deltainfo_xml_parser.rb'
169-
- 'lib/rmt/rpm/primary_xml_parser.rb'
170-
171-
# Offense count: 8
172-
# Cop supports --auto-correct.
173-
# Configuration parameters: PreferredDelimiters.
174-
Style/PercentLiteralDelimiters:
175-
Exclude:
176-
- 'config/initializers/fast_gettext.rb'
177-
- 'config/spring.rb'
178-
- 'lib/rmt/downloader.rb'
179-
- 'lib/rmt/rpm/primary_xml_parser.rb'
180-
- 'lib/suse/connect/api.rb'
181-
- 'spec/lib/rmt/downloader_spec.rb'
182-
- 'spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb'
183-
184-
# Offense count: 9
185-
# Cop supports --auto-correct.
186-
# Configuration parameters: EnforcedStyle, MinSize, SupportedStyles.
187-
# SupportedStyles: percent, brackets
188-
Style/SymbolArray:
189-
Exclude:
190-
- 'Gemfile'
191-
- 'app/controllers/api/connect/v3/systems/products_controller.rb'
192-
- 'db/migrate/20170619104044_create_products_and_repositories.rb'
193-
- 'lib/tasks/potato.rake'
194-
- 'spec/factories/activations.rb'

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ gem 'rails', '~> 5.1'
3434

3535
group :development, :test do
3636
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
37-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
37+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
3838
gem 'rspec-rails', '~> 3.5'
3939
gem 'scc-codestyle'
4040
gem 'factory_girl_rails'
@@ -58,7 +58,7 @@ end
5858
gem 'simplecov', require: false, group: :test
5959

6060
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
61-
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
61+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
6262

6363
gem 'versionist'
6464
gem 'responders'

app/controllers/api/connect/v3/systems/products_controller.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class Api::Connect::V3::Systems::ProductsController < Api::Connect::BaseController
22

33
before_action :authenticate_system
4-
before_action :require_product, only: [:show, :activate, :destroy]
5-
before_action :check_base_product_dependencies, only: [:activate, :upgrade, :show]
4+
before_action :require_product, only: %i[show activate destroy]
5+
before_action :check_base_product_dependencies, only: %i[activate upgrade show]
66

77
def activate
88
create_product_activation
@@ -24,7 +24,7 @@ def show
2424
protected
2525

2626
def require_product
27-
require_params([:identifier, :version, :arch])
27+
require_params(%i[identifier version arch])
2828

2929
@product = Product.where(identifier: params[:identifier], version: params[:version], arch: params[:arch]).first
3030

@@ -49,7 +49,7 @@ def check_base_product_dependencies
4949
# TODO: For APIv5 and future. We skip this check for second level extensions. E.g. HA-GEO
5050
# To fix bnc#951189 specifically the rollback part of it.
5151
return if @product.bases.any?(&:extension?)
52-
return if @product.base? || !(@system.products & @product.bases).blank?
52+
return if @product.base? || (@system.products & @product.bases).present?
5353

5454
logger.info("Tried to activate/upgrade to '#{@product.friendly_name}' with unmet base product dependency")
5555
raise ActionController::TranslatedError.new(

app/controllers/services_controller.rb

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def show
1111
@base_url = request.base_url
1212

1313
render :xml, template: 'services/show.xml.builder'
14-
1514
rescue ActiveRecord::RecordNotFound
1615
untranslated = N_('Requested service not found')
1716
render(xml: { error: untranslated, localized_error: _(untranslated) }, status: 404) and return

app/models/system.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def init
1717
def self.generate_secure_login
1818
generated_login = nil
1919
# Generate a new login as long as it is not in use.
20-
while !generated_login || System.find_by_login(generated_login)
20+
while !generated_login || System.find_by(login: generated_login)
2121
# The login credentials has to have the prefix "SCC_" in order to recognize SCC authentication
2222
generated_login = "SCC_#{build_secure_token}"
2323
end

bin/rmt-mirror

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require 'rmt/config'
1010
repository_url = ARGV[0]
1111
local_path = ARGV[1]
1212

13-
unless (repository_url and local_path)
13+
unless (repository_url && local_path)
1414
STDERR.puts 'Usage: rmt-mirror [repository_url] [local_path]'
1515
exit 1
1616
end

bin/spring

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ unless defined?(Spring)
88
require 'bundler'
99

1010
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11-
spring = lockfile.specs.detect {|spec| spec.name == 'spring' }
11+
spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
1212
if spring
1313
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
1414
gem 'spring', spring.version

config/environments/development.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
config.consider_all_requests_local = true
1414

1515
# Enable/disable caching. By default caching is disabled.
16-
if Rails.root.join('tmp/caching-dev.txt').exist?
16+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
1717
config.action_controller.perform_caching = true
1818

1919
config.cache_store = :memory_store

config/initializers/fast_gettext.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Configure fast_gettext for i18n.
22
FastGettext.add_text_domain('glue', path: 'locale', type: :po, ignore_fuzzy: true, report_warning: false)
33
FastGettext.default_locale = I18n.default_locale
4-
FastGettext.default_available_locales = %w(en de fr ja es pt_BR zh_CN)
4+
FastGettext.default_available_locales = %w[en de fr ja es pt_BR zh_CN]
55
FastGettext.default_text_domain = 'glue'

config/spring.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
%w(
1+
%w[
22
.ruby-version
33
.rbenv-vars
44
tmp/restart.txt
55
tmp/caching-dev.txt
6-
).each {|path| Spring.watch(path) }
6+
].each { |path| Spring.watch(path) }

db/migrate/20170619104044_create_products_and_repositories.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def change # rubocop:disable Metrics/MethodLength
6363
t.integer :extension_id, null: false
6464
end
6565

66-
add_index :repositories, [:name, :distro_target], unique: true
67-
add_index :repositories_services, [:service_id, :repository_id], unique: true
66+
add_index :repositories, %i[name distro_target], unique: true
67+
add_index :repositories_services, %i[service_id repository_id], unique: true
6868
add_index :services, :product_id, unique: true
6969

7070
add_foreign_key :activations, :systems, on_delete: :cascade

lib/rmt/downloader.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RMT::Downloader
99
class Exception < RuntimeError
1010
end
1111

12-
KNOWN_HASH_FUNCTIONS = %i(MD5 SHA1 SHA256 SHA384 SHA512).freeze
12+
KNOWN_HASH_FUNCTIONS = %i[MD5 SHA1 SHA256 SHA384 SHA512].freeze
1313

1414
attr_accessor :repository_url, :local_path, :concurrency, :logger
1515

@@ -84,7 +84,7 @@ def make_request(remote_file, local_file, request_fiber, checksum_type = nil, ch
8484
downloaded_file = Tempfile.new('rmt')
8585

8686
request = RMT::HttpRequest.new(uri.to_s, followlocation: true)
87-
request.on_headers {|response| request_fiber.resume(response) }
87+
request.on_headers { |response| request_fiber.resume(response) }
8888
request.on_body do |chunk|
8989
next :abort if downloaded_file.closed?
9090
downloaded_file.write(chunk)
@@ -96,18 +96,18 @@ def make_request(remote_file, local_file, request_fiber, checksum_type = nil, ch
9696
response = Fiber.yield(request) # yields headers
9797

9898
begin
99-
if (URI(uri).scheme != 'file' and response.code != 200)
99+
if (URI(uri).scheme != 'file' && response.code != 200)
100100
raise RMT::Downloader::Exception.new("#{remote_file} - HTTP request failed with code #{response.code}")
101101
end
102102

103103
response = Fiber.yield # yields when the request is complete
104-
if (response.return_code and response.return_code != :ok)
104+
if (response.return_code && response.return_code != :ok)
105105
raise RMT::Downloader::Exception.new("#{remote_file} - return code #{response.return_code}")
106106
end
107107

108108
downloaded_file.close
109109

110-
verify_checksum(downloaded_file.path, checksum_type, checksum_value) if (checksum_type and checksum_value)
110+
verify_checksum(downloaded_file.path, checksum_type, checksum_value) if (checksum_type && checksum_value)
111111
rescue StandardError => e
112112
downloaded_file.unlink
113113
raise e

lib/rmt/rpm/base_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def parse
2424
protected
2525

2626
def get_attribute(attributes, name)
27-
attributes.select {|e| e[0] == name }.first[1]
27+
attributes.select { |e| e[0] == name }.first[1]
2828
end
2929

3030
end

lib/rmt/rpm/deltainfo_xml_parser.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ def characters(string)
3131

3232
def end_element(name)
3333
if (name == 'delta')
34-
@referenced_files << RMT::Rpm::FileEntry.new(
35-
@delta[:location],
36-
@delta[:checksum_type],
37-
@delta[:checksum],
38-
:drpm
39-
) unless (@package[:arch] == 'src' and !@mirror_src)
34+
unless (@package[:arch] == 'src' && !@mirror_src)
35+
@referenced_files << RMT::Rpm::FileEntry.new(
36+
@delta[:location],
37+
@delta[:checksum_type],
38+
@delta[:checksum],
39+
:drpm
40+
)
41+
end
4042
end
4143
end
4244

0 commit comments

Comments
 (0)