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

experimental new rubocop with auto fixes #1298

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# use the shared Yast defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml
./rubocop-1.59.0_yast_style.yml

Metrics/AbcSize:
Max: 446
Expand Down
2 changes: 1 addition & 1 deletion library/control/src/modules/InstError.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main
end

def SaveLogs
env_home = ENV["HOME"]
env_home = Dir.home

homedir = if env_home && !env_home.empty?
env_home
Expand Down
2 changes: 1 addition & 1 deletion library/control/src/modules/ProductControl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def ReadControlFile(controlfile)
control_log_dir_rotator.prepare
control_log_dir_rotator.copy(controlfile, "control.xml")

control_log_dir_rotator.write("README", "The first number in the filename is the merge "\
control_log_dir_rotator.write("README", "The first number in the filename is the merge " \
"counter, the second number\nis the add-on counter.\n")

@workflows = Ops.get_list(@productControl, "workflows", [])
Expand Down
2 changes: 1 addition & 1 deletion library/control/src/modules/WorkflowManager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def addon_control_dir(src_id, cleanup: false)
# Directory.tmpdir is automatically removed at exit
dir = File.join(Directory.tmpdir, "installer-extension-#{src_id}")
::FileUtils.remove_entry(dir) if cleanup && Dir.exist?(dir)
::FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
::FileUtils.mkdir_p(dir)
dir
end

Expand Down
6 changes: 3 additions & 3 deletions library/control/test/installation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

describe ".sourcedir" do
before do
allow(::File).to receive(:exist?).and_return(true)
allow(File).to receive(:exist?).and_return(true)
end

it "returns string" do
expect(subject.sourcedir).to eq "/run/YaST2/mount"
end

it "ensures that directory exists" do
expect(::File).to receive(:exist?).and_return(false)
expect(::FileUtils).to receive(:mkdir_p)
expect(File).to receive(:exist?).and_return(false)
expect(FileUtils).to receive(:mkdir_p)

subject.sourcedir
end
Expand Down
7 changes: 0 additions & 7 deletions library/control/test/workflow_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,6 @@
expect { subject.addon_control_dir(src_id) }.to_not(change { File.exist?(path) })
end
end

it "does not create the directory if it already exists" do
dir = subject.addon_control_dir(src_id)
expect(File.directory?(subject.addon_control_dir(src_id))).to be true
expect(FileUtils).to_not receive(:mkdir_p).with(dir)
subject.addon_control_dir(src_id)
end
end

describe "#merge_product_workflow" do
Expand Down
2 changes: 1 addition & 1 deletion library/cwm/examples/date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def label
end
end

class Event < ::CWM::Popup
class Event < CWM::Popup
def initialize
super

Expand Down
6 changes: 3 additions & 3 deletions library/cwm/examples/object_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def run
abort_handler = proc { Yast::Popup.YesNo("Really abort?") }
CWM.show(contents,
caption: _("Lucky number"),
next_handler: next_handler,
back_handler: back_handler,
abort_handler: abort_handler)
next_handler:,
back_handler:,
abort_handler:)
Yast::Wizard.CloseDialog

lucky_number_widget.result
Expand Down
10 changes: 5 additions & 5 deletions library/cwm/examples/object_api_tabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Yast.import "Popup"
Yast.import "Wizard"

class LuckyNumberWidget < ::CWM::IntField
class LuckyNumberWidget < CWM::IntField
attr_reader :result, :minimum, :maximum

def initialize
Expand All @@ -31,7 +31,7 @@ def store
end
end

class GenerateButton < ::CWM::PushButton
class GenerateButton < CWM::PushButton
def initialize(lucky_number_widget)
super()

Expand All @@ -49,7 +49,7 @@ def handle
end
end

class LuckyNumberTab < ::CWM::Tab
class LuckyNumberTab < CWM::Tab
def initialize
super

Expand Down Expand Up @@ -82,7 +82,7 @@ def lucky_number_widget
end
end

class TrueLoveSelector < ::CWM::RadioButtons
class TrueLoveSelector < CWM::RadioButtons
def initialize
super

Expand Down Expand Up @@ -122,7 +122,7 @@ def result
end
end

class TrueLoveTab < ::CWM::Tab
class TrueLoveTab < CWM::Tab
def contents
HBox(
true_love_selector
Expand Down
10 changes: 5 additions & 5 deletions library/cwm/examples/object_api_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Yast.import "Popup"
Yast.import "Wizard"

class LuckyNumberWidget < ::CWM::IntField
class LuckyNumberWidget < CWM::IntField
attr_reader :result, :minimum, :maximum

def initialize
Expand All @@ -32,7 +32,7 @@ def store
end
end

class GenerateButton < ::CWM::PushButton
class GenerateButton < CWM::PushButton
def initialize(lucky_number_widget)
super()

Expand All @@ -50,7 +50,7 @@ def handle
end
end

class LuckyNumberTab < ::CWM::Tab
class LuckyNumberTab < CWM::Tab
def initialize
super
self.initial = true
Expand Down Expand Up @@ -82,7 +82,7 @@ def lucky_number_widget
end
end

class TrueLoveSelector < ::CWM::RadioButtons
class TrueLoveSelector < CWM::RadioButtons
def initialize
super

Expand Down Expand Up @@ -122,7 +122,7 @@ def result
end
end

class TrueLoveTab < ::CWM::Tab
class TrueLoveTab < CWM::Tab
def contents
HBox(
true_love_selector
Expand Down
2 changes: 1 addition & 1 deletion library/cwm/examples/popup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def help
end
end

class Ferryman < ::CWM::Popup
class Ferryman < CWM::Popup
def initialize
super

Expand Down
4 changes: 2 additions & 2 deletions library/cwm/examples/service_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def run
abort_handler = proc { Yast::Popup.YesNo("Really abort?") }
CWM.show(contents,
caption: _("Lucky number"),
back_handler: back_handler,
abort_handler: abort_handler)
back_handler:,
abort_handler:)
Yast::Wizard.CloseDialog

lucky_number_widget.result
Expand Down
4 changes: 2 additions & 2 deletions library/cwm/src/lib/cwm/abstract_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def refresh_help
# shortcut from Yast namespace to avoid including whole namespace
# @todo kill converts in CWM module, to avoid this workaround for funrefs
# @return [Yast::FunRef]
def fun_ref(*args)
Yast::FunRef.new(*args)
def fun_ref(*)
Yast::FunRef.new(*)
end

private
Expand Down
14 changes: 7 additions & 7 deletions library/cwm/src/lib/cwm/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def title
def initialize(*args, **kws); end

# A shortcut for `.new(*args).run`
def self.run(*args, **kws)
def self.run(*, **kws)
# Argument delegation is handled differently since ruby 2.7:
#
# An empty Hash argument is automatically converted and absorbed into **kws, and the delegation
Expand All @@ -41,7 +41,7 @@ def self.run(*args, **kws)
# * Ruby 2.7 or later: run("foo") passes new("foo")
#
# See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
dialog = kws.empty? ? new(*args) : new(*args, **kws)
dialog = kws.empty? ? new(*) : new(*, **kws)
dialog.run
end

Expand Down Expand Up @@ -163,11 +163,11 @@ def cwm_show
Yast::CWM.show(
Yast::Term.new(:HBox, FakeHelp.new(help), contents),
caption: title,
back_button: back_button,
abort_button: abort_button,
next_button: next_button,
skip_store_for: skip_store_for,
disable_buttons: disable_buttons,
back_button:,
abort_button:,
next_button:,
skip_store_for:,
disable_buttons:,
next_handler: proc { next_handler },
back_handler: proc { back_handler },
abort_handler: proc { abort_handler }
Expand Down
10 changes: 5 additions & 5 deletions library/cwm/src/lib/cwm/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def sort_key(value)
#
# @example
# cell(icon("/tmp/cool_icon.png"), "Really cool!!!")
def cell(*args)
Yast::Term.new(:cell, *args)
def cell(*)
Yast::Term.new(:cell, *)
end

# helper to create a {TableItem}
Expand All @@ -152,8 +152,8 @@ def cell(*args)
#
# @example
# item(:joe, ["Joe", "Doe"], children: [[:joeson, "Joeson", "Doe"]], open: false)
def item(*args)
TableItem.new(*args)
def item(*)
TableItem.new(*)
end

# helper to say if table have multiselection
Expand All @@ -171,7 +171,7 @@ def format_items(items)

# @see #format_items
def format_item(item)
return Item(Id(item.first), *item[1..-1]) if item.is_a?(Array)
return Item(Id(item.first), *item[1..]) if item.is_a?(Array)

children = format_items(item.children)
open_tag = item.open ? :open : :closed
Expand Down
6 changes: 3 additions & 3 deletions library/cwm/src/lib/cwm/tabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Tabs < Pager
# {Tabs} does not have instances:
# `Tabs.new` overrides `Class.new` and calls
# either {DumbTabPager}.new or {PushButtonTabPager}.new.
def self.new(*args)
def self.new(*)
if Yast::UI.HasSpecialWidget(:DumbTab)
DumbTabPager.new(*args)
DumbTabPager.new(*)
else
PushButtonTabPager.new(*args)
PushButtonTabPager.new(*)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions library/cwm/src/lib/cwm/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(id, label, icon: nil, open: true, children: [])
@label = label
@icon = icon
@open = open
@children = children.map { |c| [c.id, c] }.to_h
@children = children.to_h { |c| [c.id, c] }
end

def ui_term
Expand Down Expand Up @@ -51,8 +51,8 @@ def value=(val)
end

# An alias for {TreeItem#initialize TreeItem.new}
def new_item(*args, **kwargs)
TreeItem.new(*args, **kwargs)
def new_item(*, **)
TreeItem.new(*, **)
end

# @return [Enumerable<TreeItem>]
Expand Down
2 changes: 1 addition & 1 deletion library/cwm/src/lib/cwm/tree_pager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PagerTreeItem < TreeItem
def initialize(page, icon: nil, open: true, children: [])
@page = page
super(page.widget_id, page.label,
icon: icon, open: open, children: children)
icon:, open:, children:)
end

# @return [Array<Page>] My page and all pages of descendant items
Expand Down
4 changes: 2 additions & 2 deletions library/cwm/src/lib/cwm/ui_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def create_instance
@instance = new
end

# Make sure only .instance and .create_instance can be used to
# create objects
# Make sure only .instance and .create_instance can be used to
# create objects
private :new, :allocate
end
end
Expand Down
10 changes: 5 additions & 5 deletions library/cwm/src/modules/CWM.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,10 @@ def MergeHelps(widgets)
def PrepareDialog(dialog, widgets)
return dialog.clone if dialog.empty?

m = widgets.map do |w|
m = widgets.to_h do |w|
widget_key = w.fetch("_cwm_key", "")
[widget_key, w]
end.to_h
end
ProcessTerm(dialog, m)
end

Expand Down Expand Up @@ -915,7 +915,7 @@ def show(contents, caption: nil, back_button: nil, next_button: nil, abort_butto
options = {
"contents" => widgets_contents(contents),
"widget_names" => widgets.map(&:widget_id),
"widget_descr" => widgets.map { |w| [w.widget_id, w.cwm_definition] }.to_h
"widget_descr" => widgets.to_h { |w| [w.widget_id, w.cwm_definition] }
}
options["caption"] = caption if caption
options["back_button"] = back_button if back_button
Expand All @@ -942,7 +942,7 @@ def ShowAndRun(settings)
settings["widget_names"] ||= []
settings["widget_names"] += widgets.map(&:widget_id)
settings["widget_descr"] ||= {}
settings["widget_descr"] = widgets.map { |w| [w.widget_id, w.cwm_definition] }.to_h
settings["widget_descr"] = widgets.to_h { |w| [w.widget_id, w.cwm_definition] }
end
widget_descr = Ops.get_map(settings, "widget_descr", {})
contents = Ops.get_term(settings, "contents", VBox())
Expand Down Expand Up @@ -973,7 +973,7 @@ def ShowAndRun(settings)
DisableButtons(Ops.get_list(settings, "disable_buttons", []))

skip_store_for = settings["skip_store_for"] || []
Run(w, fallback, skip_store_for: skip_store_for)
Run(w, fallback, skip_store_for:)
end

# Display the dialog and run its event loop
Expand Down
Loading