Skip to content

Commit

Permalink
auto fixes with -A
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 4, 2024
1 parent 0209243 commit 4d61f68
Show file tree
Hide file tree
Showing 35 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion rakelib/doc_bootspecs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace :doc do
desc "Build boot requirements spec."
task :bootspecs do
files = Dir["**/test/y2storage/boot_requirements_checker_*_test.rb"].sort
files = Dir["**/test/y2storage/boot_requirements_checker_*_test.rb"]
unless files.empty?
sh "PARALLEL_TESTS=0 rspec" \
" --require ./src/tools/md_formatter.rb" \
Expand Down
1 change: 0 additions & 1 deletion src/examples/boot_req_checker_demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))

require "y2storage"
require "pp"

if !Process.euid.zero?
warn "You need to run this script as 'root'."
Expand Down
1 change: 0 additions & 1 deletion src/examples/proposal_settings_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
require "yast"
require "y2storage"
require "y2storage/dialogs/guided_setup"
require "pp"

DATA_DIR = "../../test/data"
FALLBACK_CONTROL_FILE = DATA_DIR + "/control_files/volumes_ng/control.SLE-with-data.xml"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/actions/controllers/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def filesystem
#
# @return [Y2Storage::Filesystems::Type, nil] nil if there is no filesystem
def filesystem_type
filesystem ? filesystem.type : nil
filesystem&.type
end

# Whether the block device will be formatted, i.e. a new filesystem will
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/blk_device_restorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def system_device
# @return [Y2Storage::BlkDevice, nil]
def checkpoint_device
checkpoint = DeviceGraphs.instance.checkpoint(device)
dev = checkpoint.nil? ? nil : checkpoint.find_device(device.sid)
dev = checkpoint&.find_device(device.sid)
dev || system_device
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/dialogs/device_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def info_widget
return @info_widget if @info_widget

entry = WIDGETS.find { |k, _v| device.is?(k) }
@info_widget = entry ? entry.last.new(device) : nil
@info_widget = entry&.last&.new(device)
end

# @see Y2Partitioner::Dialogs::Popup
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/widgets/blk_devices_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def open_items=(value)
# @return [Hash{String => Boolean}] same format as {#open_items}
def ui_open_items
open = Yast::UI.QueryWidget(Id(widget_id), :OpenItems).keys
all_items.map { |i| [i.id, open.include?(i.id) || i.children.none?] }.to_h
all_items.to_h { |i| [i.id, open.include?(i.id) || i.children.none?] }
end

# Updates table content
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/widgets/encrypt_method_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Luks2Options < LuksOptions

# @see LuksOptions#widgets
def widgets
super.concat([pbkdf_widget, label_widget])
super.push(pbkdf_widget, label_widget)
end

# Widget to set the password-based key derivation function
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/widgets/overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def open_items
items_with_children = with_children(tree.items)
open_items = Yast::UI.QueryWidget(Id(tree.widget_id), :OpenItems).keys

items_with_children.map { |i| [i.to_s, open_items.include?(i)] }.to_h
items_with_children.to_h { |i| [i.to_s, open_items.include?(i)] }
end

# Checks whether the current page is associated to a specific device
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/abstract_device_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def build_tree_recursive_from_hash(parent, name, content)

# Split up pure parameters and sub-product descriptions
sub_prod = content.select { |k, _v| factory_products.include?(k) }
param = content.reject { |k, _v| factory_products.include?(k) }
param = content.except(*factory_products)

# Call subclass-defined fixup method if available
# to convert known value types to a better usable type
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/autoinst_profile/drive_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def use_value_from_string(use)
# nil if the root filesystem is not applicable.
def enabled_snapshots?(filesystems)
root_fs = filesystems.find(&:root?)
return nil if root_fs.nil? || (root_fs.multidevice? && !btrfs_drive_section?)
return false if root_fs.nil? || (root_fs.multidevice? && !btrfs_drive_section?)

root_fs.respond_to?(:snapshots?) && root_fs.snapshots?
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/autoinst_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def suitable_ptable_type(disk, drive_spec)
ptable_type = nil
ptable_type = Y2Storage::PartitionTables::Type.find(drive_spec.disklabel) if drive_spec.disklabel

disk_ptable_type = disk.partition_table ? disk.partition_table.type : nil
disk_ptable_type = disk.partition_table&.type
ptable_type || disk_ptable_type || disk.preferred_ptable_type
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/blk_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def part_of_lvm_or_md?
# @return [Array<Device>] a collection of MD RAIDs, DM RAIDs, volume groups,
# multipath, bcache and bcache_cset devices
def component_of
vg = lvm_pv ? lvm_pv.lvm_vg : nil
vg = lvm_pv&.lvm_vg
fs = (formatted? && filesystem.multidevice?) ? filesystem : nil

(dm_raids + [vg, md, multipath, bcache, in_bcache_cset, fs]).compact
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/clients/partitions_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def update_state
self.staging_revision = storage_manager.staging_revision

staging = storage_manager.staging
actiongraph = staging ? staging.actiongraph : nil
actiongraph = staging&.actiongraph
self.actions_presenter = ActionsPresenter.new(actiongraph)
DumpManager.dump(staging)
DumpManager.dump(actions_presenter)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def can_resize?
# each subclass.
# @return [Boolean]
def is?(*types)
(types.map(&:to_sym) & types_for_is).any?
types.map(&:to_sym).intersect?(types_for_is)
end

# Whether there is (or there will be) an entry for this device in the
Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2storage/dialogs/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def help_text
end

def settings_adjustment
proposal ? proposal.auto_settings_adjustment : nil
proposal&.auto_settings_adjustment
end

# Shortcut for Yast::HTML.Para
Expand All @@ -317,7 +317,7 @@ def list(items)
#
# @return [Actiongraph, nil] nil if it's not possible to calculate the actions
def actiongraph
@devicegraph ? @devicegraph.actiongraph : nil
@devicegraph&.actiongraph
rescue ::Storage::Exception => e
# TODO: the code capturing the exception and displaying the error pop-up
# should not be directly in this dialog. It should be in some common
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def systemd_remote?
# disk uses a driver that is known to require a daemon to be started in order to make the
# device available. See bsc#1176140.
log.info "systemd_remote? for #{name}: checking driver - #{driver}"
(SYSTEMD_REMOTE_DRIVERS & driver).any?
SYSTEMD_REMOTE_DRIVERS.intersect?(driver)
end

# Default partition table type for newly created partition tables
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/dump_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def ensure_dump_dir
end

def clear_dump_dir
FileUtils.remove_dir(dump_dir) if File.exist?(dump_dir)
FileUtils.rm_rf(dump_dir)
ensure_dump_dir
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/encryption_processes/pervasive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def post_commit(device)
@secure_key.add_device_and_write(device) unless @secure_key.for_device?(device)

zkey_cryptsetup_output = execute_zkey_cryptsetup(device)
commands = zkey_cryptsetup_output[1..-1]
commands = zkey_cryptsetup_output[1..]
return if commands.nil?

commands.each do |command|
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/hwinfo_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def data_from_hwinfo

lines = output.split(DEVICE_REGEXP).reject(&:empty?)

lines.each_slice(2).each_with_object({}) do |(header, body), data|
lines.each_slice(2).with_object({}) do |(header, body), data|
details = data_from_body(body)
next if details.device_file.nil?

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/planned/assigned_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def compare(one, other, attrs, nils_first, descending)
if result.zero?
if attrs.size > 1
# Try next attribute
compare(one, other, attrs[1..-1], nils_first, descending)
compare(one, other, attrs[1..], nils_first, descending)
else
# Keep original order by checking the indexes
one.last <=> other.last
Expand Down
4 changes: 1 addition & 3 deletions src/lib/y2storage/planned/can_be_resized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def resize_device!(device, resize_info)
device.size =
if max_size > resize_info.max_size || max_size == DiskSize.unlimited
resize_info.max_size
elsif max_size < resize_info.min_size
resize_info.min_size
else
max_size
[max_size, resize_info.min_size].max
end

if max_size != device.size && max_size != DiskSize.unlimited
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/planned/lvm_vg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def self.to_string_attrs
# @return [String, nil]
def forced_disk_name
forced_lv = lvs.find(&:disk)
forced_lv ? forced_lv.disk : nil
forced_lv&.disk
end

protected
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/proposal/autoinst_devices_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize(devicegraph, issues_list)
# @param drives_map [Proposal::AutoinstDrivesMap] Drives map from AutoYaST
# @return [Planned::DevicesCollection]
def planned_devices(drives_map)
devices = drives_map.each_pair.each_with_object([]) do |(disk_name, drive), memo|
devices = drives_map.each_pair.with_object([]) do |(disk_name, drive), memo|
planned_devs = planned_for_drive(drive, disk_name)
memo.concat(planned_devs) if planned_devs
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/proposal/partition_table_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_or_update(device, planned_ptable_type)
# @param planned_ptable_type [Y2Storage::PartitionTables::Type,nil] Wanted partition table type
# @return [Y2Storage::PartitionTables::Type] Partition table type
def suitable_ptable_type(device, planned_ptable_type)
device_ptable_type = device.partition_table ? device.partition_table.type : nil
device_ptable_type = device.partition_table&.type
planned_ptable_type || device_ptable_type || device.preferred_ptable_type
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def hash_product(hash)
keys = hash.keys
# Ensure same order
arrays = keys.map { |key| hash[key] }
product = arrays[0].product(*arrays[1..-1])
product = arrays[0].product(*arrays[1..])
product.map { |p| keys.zip(p).to_h }
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/proposal_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ProposalSettings
# @return [String, nil]
def root_device
if allocate_mode?(:device)
root_volume ? root_volume.device : nil
root_volume&.device
else
@explicit_root_device
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2storage/secret_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module ClassMethods
def secret_attr(name)
define_method(:"#{name}") do
attribute = instance_variable_get(:"@#{name}")
attribute ? attribute.value : nil
attribute&.value
end

define_method(:"#{name}=") do |value|
Expand Down
1 change: 0 additions & 1 deletion test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ module Installation
class ProposalStore; end

class ProposalRunner
def initialize(_runner); end
def run; end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/y2partitioner/ui_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
before { ui_state.select_page(page.tree_path) }

context "if the disk is still there after redrawing" do
before { pages.concat [page, another_disk_page] }
before { pages.push page, another_disk_page }

it "selects the correct disk page" do
expect(ui_state.find_page(pages_ids)).to eq page.id
Expand Down Expand Up @@ -152,7 +152,7 @@
before { ui_state.select_page(page.tree_path) }

context "if the VG is still there after redrawing" do
before { pages.concat [page, another_vg_page] }
before { pages.push page, another_vg_page }

it "selects the correct VG page" do
expect(ui_state.find_page(pages_ids)).to eq page.id
Expand All @@ -179,7 +179,7 @@
before { ui_state.select_page(page.tree_path) }

context "if the bcache is still there after redrawing" do
before { pages.concat [page, another_bcache_page] }
before { pages.push page, another_bcache_page }

it "selects the correct bcache page" do
expect(ui_state.find_page(pages_ids)).to eq page.id
Expand All @@ -206,7 +206,7 @@
before { ui_state.select_page(page.tree_path) }

context "if the filesystem is still there after redrawing" do
before { pages.concat [page, another_btrfs_page] }
before { pages.push page, another_btrfs_page }

it "selects the correct btrfs page" do
expect(ui_state.find_page(pages_ids)).to eq page.id
Expand Down
2 changes: 1 addition & 1 deletion test/y2storage/actions_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
let(:compound_actions) { [ca_create_device, ca_delete_device] }
let(:filename) { "/tmp/saved_actions.txt" }

before { FileUtils.remove(filename) if File.exist?(filename) }
before { FileUtils.rm_f(filename) }
after { FileUtils.remove(filename) }

it "Saves the actions in a plain text file" do
Expand Down
2 changes: 1 addition & 1 deletion test/y2storage/dump_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def base_dir
def dump_dir_list
return [] unless File.exist?(base_dir)

Dir.glob(base_dir + "/storage*").sort
Dir.glob(base_dir + "/storage*")
end

describe "#instance" do
Expand Down
4 changes: 2 additions & 2 deletions test/y2storage/package_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# Let's simulate the first package is already installed
allow(Yast::Package).to receive(:Installed).with(feature_pkg[0]).and_return true

expect(Yast::Package).to receive(:DoInstall).with(feature_pkg[1..-1])
expect(Yast::Package).to receive(:DoInstall).with(feature_pkg[1..])
subject.install(ask: false)
end

Expand All @@ -125,7 +125,7 @@
# Let's simulate the first package is already installed
allow(Yast::Package).to receive(:Installed).with(feature_pkg[0]).and_return true

expect(Yast::Package).to receive(:CheckAndInstallPackages).with(feature_pkg[1..-1])
expect(Yast::Package).to receive(:CheckAndInstallPackages).with(feature_pkg[1..])
subject.install
end

Expand Down
1 change: 0 additions & 1 deletion test/y2storage/secret_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

require_relative "spec_helper"
require "y2storage"
require "pp"
require "y2storage/equal_by_instance_variables"

describe Y2Storage::SecretAttributes do
Expand Down
2 changes: 1 addition & 1 deletion test/y2storage/storage_class_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
describe wrapper do
all_children = ObjectSpace.each_object(Class).select { |c| c < wrapper }
direct_children = all_children.select do |child|
ancestors_classes = child.ancestors[1..-1].select { |c| c.is_a?(Class) }
ancestors_classes = child.ancestors[1..].select { |c| c.is_a?(Class) }
ancestors_classes.first == wrapper
end

Expand Down

0 comments on commit 4d61f68

Please sign in to comment.