Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rubocop (0.41.2 → 1.24.1) #603

Merged
merged 16 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# use the shared Yast defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop_yast_style.yml
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7

Style/FrozenStringLiteralComment:
Enabled: false
Expand All @@ -24,7 +24,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 25

Metrics/LineLength:
Layout/LineLength:
Max: 100

# TODO: this need some non-trivial refactoring...
Expand All @@ -42,7 +42,7 @@ Lint/ShadowedException:
- 'src/lib/registration/connect_helpers.rb'

# Offense count: 5
Style/AccessorMethodName:
Naming/AccessorMethodName:
Enabled: false

# Offense count: 29
Expand All @@ -51,9 +51,30 @@ Style/Documentation:

# Offense count: 1
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
Style/PredicateName:
Naming/PredicateName:
Enabled: false

Naming/MethodParameterName:
Enabled: false

# Let lslezak decide what to do with it. In general jreidinger does not see it as such big violence of style
Style/StructInheritance:
Enabled: false

# Allow global mixins in tests
Style/MixinUsage:
Exclude:
- 'test/**/*.rb'

# this cop will change API, so disable it
Style/OptionalBooleanParameter:
Enabled: false

# it sometimes make code harder to read
Style/GuardClause:
Enabled: false

# disable missing ending range as it is not supported in ruby 2.7
# TODO: is it bug in rubocop that with target ruby version 2.7 it stil do it?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting question.
The current source for the cop thinks endless ranges should work even since Ruby 2.6:
https://github.com/rubocop/rubocop/blob/751898494b694f0520d1739b877e1add94c71366/lib/rubocop/cop/style/slicing_with_range.rb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it is my fault. ruby in SLE15 is 2.5 and not 2.7.

jreidinger@jreidinger:~/prace/yast/registration> ruby --version
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux-gnu]

Style/SlicingWithRange:
Enabled: false
6 changes: 3 additions & 3 deletions src/bin/install_ssl_certificates
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require "registration/ssl_certificate"

dir = Registration::SslCertificate::INSTSYS_CERT_DIR
if Dir.empty?(dir)
$stderr.puts "ERROR: Empty #{dir} directory, put your SSL certificate there."
warn "ERROR: Empty #{dir} directory, put your SSL certificate there."
exit 1
end

Expand All @@ -38,7 +38,7 @@ if ENV["YAST_IS_RUNNING"] != "instsys"
if $CHILD_STATUS.success?
puts "Done"
else
$stderr.puts "Failed!"
warn "Failed!"
end

exit $CHILD_STATUS.exitstatus
Expand All @@ -49,6 +49,6 @@ puts "Updating the inst-sys SSL certificates..."
if Registration::SslCertificate.update_instsys_ca
puts "Done"
else
$stderr.puts "Failed!"
warn "Failed!"
exit 1
end
56 changes: 29 additions & 27 deletions src/clients/discover_registration_services.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@

require "yast/suse_connect"

require "registration/helpers"
require "registration/url_helpers"
require "registration/ui/regservice_selection_dialog"

module Yast
class DiscoverRegistrationServicesClient < Client
include Yast::Logger

# @return [Array<SlpServiceClass::Service>] list of candidate services
attr_reader :services
unless defined?(DiscoverRegistrationServicesClient)
class DiscoverRegistrationServicesClient < Client
include Yast::Logger

def initialize
@services = []
end
# @return [Array<SlpServiceClass::Service>] list of candidate services
attr_reader :services

def main
textdomain "registration"
@services = ::Registration::UrlHelpers.slp_discovery_feedback
services.empty? ? nil : select_registration_service
end
def initialize
super
@services = []
end

private
def main
textdomain "registration"
@services = ::Registration::UrlHelpers.slp_discovery_feedback
services.empty? ? nil : select_registration_service
end

def select_registration_service
service = ::Registration::UI::RegserviceSelectionDialog.run(services: services)
case service
when :scc
nil
when :cancel
:cancel
else
url = ::Registration::UrlHelpers.service_url(service.slp_url)
log.info "Selected service URL: #{url}"
url
private

def select_registration_service
service = ::Registration::UI::RegserviceSelectionDialog.run(services: services)
case service
when :scc
nil
when :cancel
:cancel
else
url = ::Registration::UrlHelpers.service_url(service.slp_url)
log.info "Selected service URL: #{url}"
url
end
end
end
end unless defined?(DiscoverRegistrationServicesClient)
end
DiscoverRegistrationServicesClient.new.main
end
119 changes: 60 additions & 59 deletions src/clients/scc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2013 Novell, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -30,70 +28,73 @@
require "cgi/util"

module Yast
class SccClient < Client
include Yast::Logger

Yast.import "CommandLine"
Yast.import "Pkg"
Yast.import "Report"
Yast.import "Wizard"

def main
textdomain "registration"

if WFM.Args.include?("help")
print_help
else
Wizard.CreateDialog

begin
::Registration::SwMgmt.init

return WFM.call("inst_scc", WFM.Args)
rescue Registration::SourceRestoreError => e
retry if fix_repositories(e.message)
rescue Registration::PkgAborted => e
# Libzypp init has failed because another application
# has already locked the zypp stack. The user has already
# decided to exit the module. So nothing more has to be
# done here.
log.info "User abort..."
ensure
Wizard.CloseDialog
unless defined?(SccClient)
class SccClient < Client
include Yast::Logger

Yast.import "CommandLine"
Yast.import "Pkg"
Yast.import "Report"
Yast.import "Wizard"

def main
textdomain "registration"

if WFM.Args.include?("help")
print_help
else
Wizard.CreateDialog

begin
::Registration::SwMgmt.init

WFM.call("inst_scc", WFM.Args)
rescue Registration::SourceRestoreError => e
retry if fix_repositories(e.message)
rescue Registration::PkgAborted => e
# Libzypp init has failed because another application
# has already locked the zypp stack. The user has already
# decided to exit the module. So nothing more has to be
# done here.
log.info "User abort..."
ensure
Wizard.CloseDialog
end
end
end
end

private
private

# Print help in command line mode
def print_help
cmdline_description = {
"id" => "scc",
# Command line help text for the repository module, %1 is "SUSEconnect"
"help" => _("Use '%s' instead of this YaST module.") % "SUSEconnect"
}
# Print help in command line mode
def print_help
cmdline_description = {
"id" => "scc",
# Command line help text for the repository module, %1 is "SUSEconnect"
"help" => _("Use '%s' instead of this YaST module.") % "SUSEconnect"
}

CommandLine.Run(cmdline_description)
end
CommandLine.Run(cmdline_description)
end

# Let the user manually fix the broken repositories
# @return [Boolean] true if the repository manager was successfuly closed,
# false after pressing [Cancel]
def fix_repositories(details)
# TRANSLATORS: Error message in RichText format, %s contains the details from libzypp
Report.LongError(_("<p>The repository initialization failed. " \
"Disable (or remove) the offending service or repository " \
"in the repository manager.</p><p>Details:</p><p>%s</p>") % CGI.escapeHTML(details))

ret = WFM.call("repositories", WFM.Args)
log.info "repository manager result: #{ret}"

# drop all loaded repos, force complete reloading
Pkg.SourceFinishAll
ret == :next
# Let the user manually fix the broken repositories
# @return [Boolean] true if the repository manager was successfuly closed,
# false after pressing [Cancel]
def fix_repositories(details)
# TRANSLATORS: Error message in RichText format, %s contains the details from libzypp
Report.LongError(_("<p>The repository initialization failed. " \
"Disable (or remove) the offending service or repository " \
"in the repository manager.</p><p>Details:</p><p>%s</p>") %
CGI.escapeHTML(details))

ret = WFM.call("repositories", WFM.Args)
log.info "repository manager result: #{ret}"

# drop all loaded repos, force complete reloading
Pkg.SourceFinishAll
ret == :next
end
end
end unless defined?(SccClient)
end
end

Yast::SccClient.new.main
2 changes: 0 additions & 2 deletions src/clients/scc_auto.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ***************************************************************************
#
# Copyright (c) 2014 SUSE LLC
Expand Down
9 changes: 5 additions & 4 deletions src/lib/registration/addon.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2014 SUSE LLC
#
Expand Down Expand Up @@ -58,6 +56,7 @@ def find_all(registration)
# @return [Addon,nil] The addon with the given ID or nil if it was not found
def find_by_id(id)
raise AddonsNotLoaded unless @cached_addons

@cached_addons.find { |a| a.id == id }
end

Expand Down Expand Up @@ -117,6 +116,7 @@ def registration_order(list)

loop do
break if to_process.empty?

next_addon = to_process.find do |addon|
addon.depends_on.nil? || !to_process.include?(addon.depends_on)
end
Expand Down Expand Up @@ -145,6 +145,7 @@ def create_addon_with_deps(root)
to_process.each do |(pure, dependency)|
# this avoid endless loop if there is circular dependency.
next if processed.include?(pure)

processed << pure
addon = Addon.new(pure)
result << addon
Expand Down Expand Up @@ -378,8 +379,8 @@ def self.dump_addons

require "yaml"
header = "# see " \
"https://github.com/yast/yast-registration/tree/master/devel/dump_reader.rb\n" \
"# for an example how to read this dump file\n"
"https://github.com/yast/yast-registration/tree/master/devel/dump_reader.rb\n" \
"# for an example how to read this dump file\n"
File.write("/var/log/YaST2/registration_addons.yml",
header + @cached_addons.to_yaml)
end
Expand Down
23 changes: 11 additions & 12 deletions src/lib/registration/addon_sorter.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@

module Registration
# Sorter for sorting Addons in required display order
# (first paid extensions, then free extensions, modules at the end
# see https://bugzilla.novell.com/show_bug.cgi?id=888567#c21)
# @param x [Registration::Addon] the first item to compare
# @param y [Registration::Addon] the second item to compare
ADDON_SORTER = proc do |x, y|

# if empty or nil move at the end
if x.product_type != y.product_type
begin
# if empty or nil move at the end
if !x.product_type || x.product_type.empty?
1
elsif !y.product_type || y.product_type.empty?
-1
else
# simplification: "extension" is lexicographically before "module"
# as requested in the display order so take advantage of this...
x.product_type <=> y.product_type
end
if !x.product_type || x.product_type.empty?
1
elsif !y.product_type || y.product_type.empty?
-1
else
# simplification: "extension" is lexicographically before "module"
# as requested in the display order so take advantage of this...
x.product_type <=> y.product_type
end

elsif x.free != y.free
# paid (non-free) first
x.free ? 1 : -1
Expand Down
1 change: 0 additions & 1 deletion src/lib/registration/autoyast_addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def register

private

attr_writer :selected_addons
attr_accessor :registration

# select the requested addons
Expand Down
Loading
Loading