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

rubocop update #83

Merged
merged 7 commits into from
Jul 22, 2016
Merged
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
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ Style/IfUnlessModifier:
# UI code can use bigger assignments
Metrics/AbcSize:
Max: 100

# some storage API have size method, but without empty? method
# for details see https://github.com/yast/yast-storage-ng/pull/83
Style/ZeroLengthPredicate:
Enabled: false

# the ".freeze" attribute for the constants is not nice
Style/MutableConstant:
Enabled: false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before_install:
# disable rvm, use system Ruby
- rvm reset
- wget https://raw.githubusercontent.com/yast/yast-devtools/master/travis-tools/travis_setup.sh
- sh ./travis_setup.sh -p "yast2-devtools yast2 rake libstorage-ng1 libstorage-ng-ruby" -g "rspec:3.3.0 yast-rake gettext simplecov coveralls rubocop:0.29.1"
- sh ./travis_setup.sh -p "yast2-devtools yast2 rake libstorage-ng1 libstorage-ng-ruby" -g "rspec:3.3.0 yast-rake gettext simplecov coveralls rubocop:0.41.2"
script:
- rake check:syntax
- rake check:pot
Expand Down
2 changes: 1 addition & 1 deletion src/lib/expert_partitioner/dialogs/create_partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create_dialog
VBox(
Id(:custom_size_attachment),
MinWidth(15, InputField(Id(:custom_size_input), Opt(:shrinkable), _("Size"), "50 MiB"))
))
))
)),
ButtonBox(
PushButton(Id(:cancel), Yast::Label.CancelButton),
Expand Down
6 changes: 3 additions & 3 deletions src/lib/expert_partitioner/tab_views/disk/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def create
PushButton(Id(:delete), _("Delete...")),
HStretch(),
MenuButton(Id(:expert), _("Expert..."), [
# menu entry text
Item(Id(:create_partition_table), _("Create New Partition Table"))
])
# menu entry text
Item(Id(:create_partition_table), _("Create New Partition Table"))
])
)
)
end
Expand Down
6 changes: 3 additions & 3 deletions src/lib/expert_partitioner/tab_views/md/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def create
PushButton(Id(:delete), _("Delete...")),
HStretch(),
MenuButton(Id(:expert), _("Expert..."), [
# menu entry text
Item(Id(:create_partition_table), _("Create New Partition Table"))
])
# menu entry text
Item(Id(:create_partition_table), _("Create New Partition Table"))
])
)
)
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/expert_partitioner/tree_views/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def items
staging = storage.staging

return items_disks(staging) + items_mds(staging) + items_lvm_vgs(staging) +
items_lukses(staging) + items_bcaches(staging) + items_bcache_csets(staging)
items_lukses(staging) + items_bcaches(staging) + items_bcache_csets(staging)
end
end
end
10 changes: 5 additions & 5 deletions src/lib/expert_partitioner/tree_views/bcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def create
"Size: #{::Storage.byte_to_humanstring(@bcache.size, false, 2, false)}",
"Used Device: #{@bcache.blk_device.name}"]

if @bcache.has_bcache_cset
tmp << "Bcache Cset: #{@bcache.bcache_cset.uuid}"
else
tmp << "Bcache Cset:"
end
tmp << if @bcache.has_bcache_cset
"Bcache Cset: #{@bcache.bcache_cset.uuid}"
else
"Bcache Cset:"
end

contents = Yast::HTML.List(tmp)

Expand Down
24 changes: 9 additions & 15 deletions src/lib/storage/abstract_device_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def load_yaml_file(yaml_file)
File.open(yaml_file) { |file| YAML.load_stream(file, yaml_file) { |doc| build_tree(doc) } }
end
rescue SystemCallError => ex
log.error("#{ex}")
log.error(ex.to_s)
raise
end

Expand All @@ -91,11 +91,9 @@ def build_tree(obj)
build_tree_toplevel(obj)
when Array
obj.each do |element|
if element.is_a?(Hash)
build_tree_toplevel(element)
else
raise TypeError, "Expected Hash, not #{element}"
end
raise TypeError, "Expected Hash, not #{element}" unless element.is_a?(Hash)

build_tree_toplevel(element)
end
else
raise HierarchyError, "Expected Hash or Array at toplevel"
Expand Down Expand Up @@ -153,13 +151,11 @@ def build_tree_recursive(parent, name, content)
end
when Array
content.each do |element|
if element.is_a?(Hash)
child_name, child_content = break_up_hash(element)
check_hierarchy(name, child_name)
build_tree_recursive(parent, child_name, child_content)
else
raise TypeError, "Expected Hash, not #{element}"
end
raise TypeError, "Expected Hash, not #{element}" unless element.is_a?(Hash)

child_name, child_content = break_up_hash(element)
check_hierarchy(name, child_name)
build_tree_recursive(parent, child_name, child_content)
end
else # Simple value, no hash or array
# Intentionally not calling fixup_param() here since that method would
Expand Down Expand Up @@ -300,11 +296,9 @@ def check_param(name, param)
# @param child [String] name of child factory product
#
def check_hierarchy(parent, child)
# rubocop:disable Style/GuardClause
if !valid_hierarchy[parent].include?(child)
raise HierarchyError, "Unexpected child #{child} for #{parent}"
end
# rubocop:enable Style/GuardClause
end

Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, remove also this four lines below

# rubocop:enable Style/GuardClause

Copy link
Member Author

Choose a reason for hiding this comment

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

it is actually auto correction from rubocop, probably only one half is implemented

# Call the factory 'create' method for factory product 'name'
Expand Down
2 changes: 1 addition & 1 deletion src/lib/storage/clients/proposal_demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProposalDemoClient
attr_writer :verbose

def initialize(verbose)
@verbose = verbose
@verbose = verbose
end

# Create a storage proposal.
Expand Down
3 changes: 0 additions & 3 deletions src/lib/storage/devices_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ class DevicesList

class << self
attr_reader :device_class

# rubocop:disable TrivialAccessors
# Macro-style method to specify the class of the elements
def list_of(klass)
Copy link
Contributor

Choose a reason for hiding this comment

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

again, remove also the enable below.

@device_class = klass
end
# rubocop:enable TrivialAccessors
end

def_delegators :@list, :each, :empty?, :length, :size
Expand Down
10 changes: 5 additions & 5 deletions src/lib/storage/disk_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def find_windows_partitions
windows_partitions[disk_name] ||= []
windows_partitions[disk_name] << partition
end
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
log.info("CAUGHT exception #{ex}")
end
end
Expand Down Expand Up @@ -400,12 +400,12 @@ def installation_disk?(disk_name)
if NO_INSTALLATION_IDS.include?(partition.id)
log.info("Skipping #{partition} (ID 0x#{partition.id.to_s(16)})")
next
else
return true if installation_volume?(partition.name)
elsif installation_volume?(partition.name)
return true
end
end
return false # if we get here, there is a partition table.
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
log.info("CAUGHT exception: #{ex} for #{disk}")
end

Expand Down Expand Up @@ -467,7 +467,7 @@ def mount_and_check(vol_name, &block)
check_result = block.call(mount_point)
umount(mount_point)
check_result
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
rescue RuntimeError => ex # FIXME: rescue ::Storage::Exception when SWIG bindings are fixed
log.error("CAUGHT exception: #{ex} for #{vol_name}")
nil
end
Expand Down
32 changes: 15 additions & 17 deletions src/lib/storage/disk_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class DiskSize
# Accept Numbers, Strings, or DiskSize objects as initializers.
#
def initialize(size = 0)
if size.is_a?(Yast::Storage::DiskSize)
@size = size.to_i
@size = if size.is_a?(Yast::Storage::DiskSize)
size.to_i
elsif size.is_a?(::String)
@size = Yast::Storage::DiskSize.parse(size).size
Yast::Storage::DiskSize.parse(size).size
else
@size = size.round
size.round
end
end

Expand Down Expand Up @@ -145,9 +145,7 @@ def parse(str)
# "MiB", ...). The base of this exponent is 1024. The base unit is KiB.
#
def unit_exponent(unit)
# rubocop:disable Style/AndOr
UNITS.index(unit) or raise ArgumentError, "expected one of #{UNITS}"
Copy link
Contributor

Choose a reason for hiding this comment

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

One more time, deleting disable and leaving enable back.

# rubocop:enable Style/AndOr
end

# Return the unit multiplier for any of the known binary units ("KiB",
Expand Down Expand Up @@ -185,21 +183,21 @@ def -(other)
end

def *(other)
if other.is_a?(Numeric)
return DiskSize.unlimited if unlimited?
DiskSize.new(@size * other)
else
if !other.is_a?(Numeric)
raise TypeError, "Unexpected #{other.class}; expected Numeric value"
end

return DiskSize.unlimited if unlimited?
DiskSize.new(@size * other)
end

def /(other)
if other.is_a?(Numeric)
return DiskSize.unlimited if unlimited?
DiskSize.new(@size.to_f / other)
else
if !other.is_a?(Numeric)
raise TypeError, "Unexpected #{other.class}; expected Numeric value"
end

return DiskSize.unlimited if unlimited?
DiskSize.new(@size.to_f / other)
end

#
Expand Down Expand Up @@ -237,7 +235,7 @@ def to_human_readable
size2 /= 1024.0
unit_index += 1
end
[size2 / 2.0, UNITS[unit_index]] # FIXME: Make unit translatable
[size2 / 2.0, UNITS[unit_index]] # FIXME: Make unit translatable
end

# Return numeric size and unit ("MiB", "GiB", ...) in human-readable form
Expand Down Expand Up @@ -280,7 +278,7 @@ def inspect
end

def pretty_print(*)
print "#{inspect}"
print inspect
end

private
Expand All @@ -298,7 +296,7 @@ def any_operand_unlimited?(other)
#
#----------------------------------------------------------------------
#
if $PROGRAM_NAME == __FILE__ # Called direcly as standalone command? (not via rspec or require)
if $PROGRAM_NAME == __FILE__ # Called direcly as standalone command? (not via rspec or require)
size = Yast::Storage::DiskSize.new(0)
print "0 B: #{size} (#{size.size})\n"

Expand Down
Loading