Skip to content

Commit

Permalink
Merge pull request #320 from SUSE/cleanup_rubocop
Browse files Browse the repository at this point in the history
Cleanup rubocop config
  • Loading branch information
thutterer committed Dec 13, 2017
2 parents c77d6be + a064565 commit b261ee7
Show file tree
Hide file tree
Showing 44 changed files with 213 additions and 308 deletions.
47 changes: 1 addition & 46 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,10 @@ AllCops:
- vendor/**
- package/**

ClassLength:
Max: 128

HashSyntax:
Enabled: false

MethodLength:
Max: 15

LineLength:
Max: 160

SpaceBeforeBlockBraces:
Enabled: true
EnforcedStyle: space

SpaceInsideBlockBraces:
EnforcedStyle: space
SpaceBeforeBlockParameters: false

EmptyLinesAroundMethodBody:
Enabled: false

EmptyLinesAroundClassBody:
Enabled: false

EmptyLinesAroundModuleBody:
Enabled: false

SignalException:
Enabled: false

DoubleNegation:
Enabled: false

PercentLiteralDelimiters:
PreferredDelimiters:
'%w': '{}'

SpaceBeforeFirstArg:
Rails:
Enabled: false

FileName:
Exclude:
- SUSEConnect
- suse-connect.gemspec

ClassAndModuleChildren:
Enabled: false

GlobalVars:
AllowedVariables: []
43 changes: 0 additions & 43 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ Layout/ExtraSpacing:
- 'spec/connect/client_spec.rb'
- 'spec/connect/connection_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/LeadingCommentSpace:
Exclude:
- 'Gemfile'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down Expand Up @@ -381,43 +375,6 @@ RSpec/VerifiedDoubles:
- 'spec/support/credentials_mocks.rb'
- 'spec/toolkit/system_calls_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
Rails/Blank:
Exclude:
- 'lib/suse/connect/credentials.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'suse-connect.gemspec'

# Offense count: 16
# Configuration parameters: Include.
# Include: app/**/*.rb, config/**/*.rb, lib/**/*.rb
Rails/Exit:
Exclude:
- 'lib/**/*.rake'
- 'lib/suse/connect/cli.rb'

# Offense count: 4
# Configuration parameters: Include.
# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
Rails/Output:
Exclude:
- 'lib/suse/connect/cli.rb'
- 'lib/suse/connect/status.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'lib/suse/connect/status.rb'

# Offense count: 1
# Cop supports --auto-correct.
Security/YAMLLoad:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ group :development do
gem 'redcarpet'
gem 'ronn'
gem 'rake'
#gem 'gem2rpm', '~> 0.10.1' # TODO: let's link this to the repo that contains the --config fix from the suse package
# gem 'gem2rpm', '~> 0.10.1' # TODO: let's link this to the repo that contains the --config fix from the suse package
gem 'bump'
end

group :test do
gem 'coveralls', :require => false
gem 'coveralls', require: false
gem 'rspec', '~> 3.3.0'
gem 'rspec-its'
gem 'webmock', '~> 1.21.0'
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module MonkeypatchRakeLastComment
end
Rake::Application.send :include, MonkeypatchRakeLastComment unless Rake::Application.method_defined? :last_comment

task :default => [:spec, :rubocop]
task default: [:spec, :rubocop]

desc 'Run RSpec'
RSpec::Core::RakeTask.new(:spec)
Expand Down
2 changes: 1 addition & 1 deletion features/step_definition/library_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
When(/^there's a file "(.+)" with a line "(.+)"$/) do |filename, line|
File.open(filename, 'w') {|f| f.puts(line) }
File.open(filename, 'w') { |f| f.puts(line) }
end

When(/^I should receive '(.*)' as a migration target$/) do |target_name|
Expand Down
4 changes: 2 additions & 2 deletions lib/suse/connect/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def to_yaml
end

def select_serializable_attributes
to_hash_with_string_keys.select {|key, _| self.class.serializable.include?(key.to_sym) }
to_hash_with_string_keys.select { |key, _| self.class.serializable.include?(key.to_sym) }
end

# allows to merge hash from other source into config to maintain precedence
Expand All @@ -60,7 +60,7 @@ def url_default?
def to_hash_with_string_keys
# OK, this code maybe look quite magic, but in fact it takes hash from
# to_h and create new one with keys that is converted with to_s
Hash[to_h.map {|k, v| [k.to_s, v] }]
Hash[to_h.map { |k, v| [k.to_s, v] }]
end

def read
Expand Down
8 changes: 4 additions & 4 deletions lib/suse/connect/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Connection
include Logger

VERB_TO_CLASS = {
:get => Net::HTTP::Get,
:post => Net::HTTP::Post,
:put => Net::HTTP::Put,
:delete => Net::HTTP::Delete
get: Net::HTTP::Get,
post: Net::HTTP::Post,
put: Net::HTTP::Put,
delete: Net::HTTP::Delete
}

attr_accessor :debug, :http, :auth, :language
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/connect/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def write
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
log.debug("Writing credentials to #{filename}")
log.debug("Credentials to write: #{self}")
File.write(filename, serialize, :perm => 0600)
File.write(filename, serialize, perm: 0600)
end

# security - override to_s to avoid writing the password to log
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/connect/hwinfo/s390.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def uuid
private

def output
@output ||= Hash[execute('read_values -s', false).split("\n").map {|line| line.split(':') }]
@output ||= Hash[execute('read_values -s', false).split("\n").map { |line| line.split(':') }]
end
end
end
6 changes: 3 additions & 3 deletions lib/suse/connect/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def rollback(client_params = {})
status = Status.new(config)

# FIXME: Sort products and ensure the base product is the first one in the list
status.installed_products.sort_by {|p| p.isbase ? 0 : 1 }.each do |product|
status.installed_products.sort_by { |p| p.isbase ? 0 : 1 }.each do |product|
service = client.downgrade_product(product)
# INFO: Remove old and new service because this could be called after filesystem rollback or
# from inside a failed migration
Expand Down Expand Up @@ -59,7 +59,7 @@ def disable_repository(name)
def repositories
# INFO: use block instead of .map(&:to_openstruct) see https://bugs.ruby-lang.org/issues/9786
# rubocop:disable SymbolProc
SUSE::Connect::Zypper.repositories.map {|r| r.to_openstruct }
SUSE::Connect::Zypper.repositories.map { |r| r.to_openstruct }
end

# Forwards the service which should be added with zypper
Expand All @@ -81,7 +81,7 @@ def remove_service(service_name)
def find_products(identifier)
# INFO: use block instead of .map(&:to_openstruct) see https://bugs.ruby-lang.org/issues/9786
# rubocop:disable SymbolProc
SUSE::Connect::Zypper.find_products(identifier).map {|p| p.to_openstruct }
SUSE::Connect::Zypper.find_products(identifier).map { |p| p.to_openstruct }
end

# Installs the product release package
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/connect/remote/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SUSE::Connect::Remote::Product < SUSE::Connect::Remote::ServerDrivenModel
def initialize(product_hash)
super
# TODO: ensure we have array here
self.extensions = extensions.map {|ext| self.class.new(ext) } if extensions
self.extensions = extensions.map { |ext| self.class.new(ext) } if extensions
end

def to_params
Expand Down
14 changes: 7 additions & 7 deletions lib/suse/connect/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def print_product_statuses(format = :text)

def system_products
products = installed_products + activated_products
products.map {|product| Product.transform(product) }.uniq
products.map { |product| Product.transform(product) }.uniq
end

private
Expand All @@ -69,16 +69,16 @@ def extract_extensions(product)
activation_code: build_product_activation_code(extension),
name: extension.friendly_name,
free: extension.free,
installed: installed_products.any? {|p| p == extension },
activated: activated_products.any? {|p| p == extension },
installed: installed_products.any? { |p| p == extension },
activated: activated_products.any? { |p| p == extension },
extensions: extract_extensions(extension)
}
end if product.extensions
extensions
end

def grouped_extensions
@grouped_extensions ||= available_system_extensions.group_by {|ext| ext[:free] }
@grouped_extensions ||= available_system_extensions.group_by { |ext| ext[:free] }
end

def build_product_activation_code(product)
Expand Down Expand Up @@ -117,19 +117,19 @@ def json_product_status
end

def activations_from_server
system_activations.map {|s| Remote::Activation.new(s) }
system_activations.map { |s| Remote::Activation.new(s) }
end

def products_from_activations
system_activations.map {|p| Remote::Product.new(p['service']['product']) }
system_activations.map { |p| Remote::Product.new(p['service']['product']) }
end

def products_from_zypper
Zypper.installed_products
end

def product_statuses
installed_products.map {|p| Zypper::ProductStatus.new(p, self) }
installed_products.map { |p| Zypper::ProductStatus.new(p, self) }
end

def system_activations
Expand Down
4 changes: 2 additions & 2 deletions lib/suse/connect/yast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def activated_products(client_params = {})
# where an upgrade path is an array of Remote::Product object.
def system_migrations(products, client_params = {})
config = SUSE::Connect::Config.new.merge!(client_params)
Client.new(config).system_migrations(products).map {|a| a.map(&:to_openstruct) }
Client.new(config).system_migrations(products).map { |a| a.map(&:to_openstruct) }
end

# List available Installer-Updates repositories for the given product
Expand All @@ -166,7 +166,7 @@ def system_migrations(products, client_params = {})
# @return [Array <OpenStruct>] list of Installer-Updates repositories
def list_installer_updates(product, client_params = {})
config = SUSE::Connect::Config.new.merge!(client_params)
Client.new(config).list_installer_updates(product).map {|repo| OpenStruct.new repo }
Client.new(config).list_installer_updates(product).map { |repo| OpenStruct.new repo }
end

# Writes the config file with the given parameters, overwriting any existing contents
Expand Down
4 changes: 2 additions & 2 deletions lib/suse/connect/zypper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def installed_products
zypper_out = call('--no-remote --no-refresh --xmlout --non-interactive products -i', false)
xml_doc = REXML::Document.new(zypper_out, compress_whitespace: [])
ary_of_products_hashes = xml_doc.root.elements['product-list'].elements.map(&:to_hash)
ary_of_products_hashes.map {|hash| Product.new(hash) }
ary_of_products_hashes.map { |hash| Product.new(hash) }
end

def base_product
Expand Down Expand Up @@ -81,7 +81,7 @@ def repositories
# Don't fail when zypper exits with 6 (no repositories)
zypper_out = call('--xmlout --non-interactive repos -d', false, [Zypper::ExitCode::OK, Zypper::ExitCode::Error::NO_REPOS])
xml_doc = REXML::Document.new(zypper_out, compress_whitespace: [])
xml_doc.elements.to_a('stream/repo-list/repo').map {|r| r.to_hash.merge!(url: r.elements['url'].text) }
xml_doc.elements.to_a('stream/repo-list/repo').map { |r| r.to_hash.merge!(url: r.elements['url'].text) }
end

# @param service_url [String] url to appropriate repomd.xml to be fed to zypper
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/connect/zypper/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(product_hash)
@identifier = product_hash[:name]
@version = product_hash[:version]
@arch = product_hash[:arch]
@isbase = %w{1 true yes}.include?(product_hash[:isbase])
@isbase = %w[1 true yes].include?(product_hash[:isbase])
@release_type = determine_release_type product_hash
@summary = product_hash[:summary]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/suse/toolkit/cast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module Cast
def to_openstruct
attributes = self.attributes
attributes.each do |key, value|
attributes[key] = value.map {|v| v.to_openstruct } if value.is_a?(Array) && value.any? {|v| v.is_a?(Hash) }
attributes[key] = value.map { |v| v.to_openstruct } if value.is_a?(Array) && value.any? { |v| v.is_a?(Hash) }
end
OpenStruct.new(attributes)
end

def attributes
attributes = to_h
attributes.each do |key, value|
attributes[key] = value.map(&:to_h) if value.is_a?(Array) && value.any? {|v| v.is_a?(OpenStruct) }
attributes[key] = value.map(&:to_h) if value.is_a?(Array) && value.any? { |v| v.is_a?(OpenStruct) }
end
attributes
end
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/toolkit/curlrc_dotfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def password

def line_with_credentials
return nil unless exist?
@line_with_credentials ||= File.readlines(@file_location).find {|l| l =~ /--proxy-user ".*:.*"/ }
@line_with_credentials ||= File.readlines(@file_location).find { |l| l =~ /--proxy-user ".*:.*"/ }
end
end
2 changes: 1 addition & 1 deletion lib/suse/toolkit/system_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module SystemCalls

def execute(cmd, quiet = true, valid_exit_codes = [0]) # rubocop:disable CyclomaticComplexity
log.debug("Executing: '#{cmd}' Quiet: #{quiet}")
output, error, status = Open3.capture3({ 'LC_ALL' => 'C' }, cmd) {|_stdin, stdout, _stderr, _wait_thr| stdout.read }
output, error, status = Open3.capture3({ 'LC_ALL' => 'C' }, cmd) { |_stdin, stdout, _stderr, _wait_thr| stdout.read }
log.debug("Output: '#{output.strip}'") unless output.empty?
log.debug("Error: '#{error.strip}'") unless error.empty?

Expand Down
Loading

0 comments on commit b261ee7

Please sign in to comment.