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 rubocop #1364

Draft
wants to merge 5 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.
Jump to
Jump to file
Failed to load files.
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

# Don't enforce any particular name for block params
Style/SingleLineBlockParams:
Expand Down
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
240 changes: 240 additions & 0 deletions rubocop-1.59.0_yast_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
AllCops:
Exclude:
# avoid confusion of rpm spec and gem spec
- "**/*.spec"
TargetRubyVersion: 3.3 # 2.5 is the SLE15 version, so ensure that we use proper version
# By default enable all new cops
NewCops: enable

# Does not work well with having indentation in strings
Layout/LineContinuationLeadingSpace:
Enabled: false

Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Metrics/AbcSize:
Max: 30

Layout/LineLength:
Max: 100
# To make it possible to copy or click on URIs in the code, we allow lines
# contaning a URI to be longer than Max.
AllowURI: true
URISchemes:
- http
- https

Layout/HashAlignment:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table

Style/CollectionMethods:
Enabled: false

Layout/EmptyLinesAroundBlockBody:
Enabled: false

Layout/MultilineOperationIndentation:
EnforcedStyle: indented

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/WordArray:
Enabled: false

Style/SymbolArray:
EnforcedStyle: brackets

Style/RegexpLiteral:
Enabled: false

Style/SignalException:
EnforcedStyle: only_raise

# Do not require an underscore each three digits. Both 65536 and 65_536 are allowed.
Style/NumericLiterals:
Enabled: false

# no extra indentation for multiline function calls.
# Reason is that some legacy ruby API call have a lot of parameters and it makes
# looking it ugly. Especially UI constructions with helpers cannot fit into line
# lenght. Same applies to method calls separated by dot.
# required style ( and by default forbidden by rubocop ):
#
# SmartClass.smart_method(boring_parameter1, boring_parameter2,
# boring_parameter3, boring_parameter4)
#
# forbidden style ( require by default by rubocop )
#
# SmartClass.smart_method(boring_parameter1, boring_parameter2,
# boring_parameter3, boring_parameter4)
#
Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

# no extra indentation for case.
# We prefer style
# case a
# when 0
# action_a
# when 1
# action_b
# else
# action_c
# end
#
# before longer and from our POV without advantage style which can confuse as it
# indicate double nesting
# case a
# when 0
# action_a
# when 1
# action_b
# else
# action_c
# end
Layout/CaseIndentation:
EnforcedStyle: end

# "unless" has a different connotation than "if not" so disable this check
Style/NegatedIf:
Enabled: false

# allow more than 10 lines for methods as some team member feel unconfortable with it
Metrics/MethodLength:
Max: 30

# allow more than 100 lines for class as some team member feel unconfortable with it
Metrics/ClassLength:
Max: 250

# Allow using and/or for driving code flow as its original intention.
# Forbid it only in conditionals
# So this rule allow something like
#
# a = action_a or raise "Cannot do a"
#
# and forbids ( due to confusing operator precedence for work-flow and/or )
#
# if a == 5 and b == 6
#
Style/AndOr:
EnforcedStyle: conditionals

# Access modified affect globally all following method definition, so
# it deserve bigger visibility then hiddin in method definition block.
# for that reason we found better style:
# class C
# ...
#
# private
#
# ...
# end
#
# then style where access modifier can be easier to overlook in longer class:
# class C
# ...
#
# private
#
# ...
# end
Layout/AccessModifierIndentation:
EnforcedStyle: outdent

# Forcing ascii only comments prevents examples in code that deal with UTF
# strings so we allow using it
Style/AsciiComments:
Enabled: false

# YaST code still have to deal with types in component system, so we allow
# double negation to enforce boolean value
# so this change allow code
#
# return !!result
#
Style/DoubleNegation:
Enabled: false

# alias method is more convenient method for method aliasing even when in class
# context self scope is not so clear
# see https://github.com/bbatsov/ruby-style-guide#alias-method-lexically
# so force
# class C
# alias_method :a, :b
#
# instead of:
# class C
# alias b a
Style/Alias:
EnforcedStyle: prefer_alias_method

# often return code of shell call is compared and using `exitstatus == 0`
# is more obvious then exitstatus.zero? especially when SCR can return nil
Style/NumericPredicate:
Enabled: false

# no strong preference if 5 == a or a == 5 should be enforced
Style/YodaCondition:
Enabled: false

# Do not enforce neither style of access modifiers as both are useful
Style/AccessModifierDeclarations:
Enabled: false

# when ternany is complex is should be clear enclosed in parentheses for easier read
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex

# format string is not unified and depending on usage. All three usages has advantages
# simple style is understandable for translators, but when there are more params it needs names.
# And template version is needed if there are more params and it needs some formatting.
Style/FormatStringToken:
Enabled: false

Naming/VariableNumber:
# do not check numbers usage in symbols as it often come outside of ruby
# like `x86_64`
CheckSymbols: false

# The detection is buggy and result is in potential bugs in Yast::Path handling.
# It changes
# path + "element"
# to
# "#{path}element"
# so calls path.to_s and append element. Result is wrong path.
Style/StringConcatenation:
Enabled: false

# while there is agreement on reducing openstruct usage,
# it is still used too widely, so disable only per module when
# it is ready
Style/OpenStructUse:
Enabled: false

# Skip warning for constant definition in tests
# as in rspec we often locate testing data close to respective test
Lint/ConstantDefinitionInBlock:
Exclude:
- "**/test/**/*.rb"

# Both styles has advantages and disadvantages and we decided to keep it
# up to code writer which one fits better. Can be changed when we use more
# widely type checking which needs separated style.
Style/AccessorGrouping:
Enabled: false

Metrics/BlockLength:
# rspec is known as DSL with big blocks
Exclude:
- "**/test/**/*"
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
2 changes: 1 addition & 1 deletion src/examples/device_demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
settings = Y2Storage::ProposalSettings.new_for_current_product
settings.use_lvm = opt_lvm
settings.encryption_password = opt_encryption
proposal = Y2Storage::GuidedProposal.new(settings: settings)
proposal = Y2Storage::GuidedProposal.new(settings:)
proposal.propose
devicegraph = proposal.devices
end
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/installation/console/plugins/luks2_checkbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def store

def help
# TRANSLATORS: help text for the checkbox enabling LUKS2 support
_("<p>You can enable experimental LUKS2 encryption support in "\
_("<p>You can enable experimental LUKS2 encryption support in " \
"the YaST partitioner. It is not supported and is designed as a " \
"technology preview only.</p>")
end
Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2partitioner/actions/add_partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def not_formatted_validation
accept = Yast::Popup.YesNo(
# TRANSLATORS: %{name} is a device name (e.g. "/dev/sda")
format(
_("The device %{name} is directly formatted.\n"\
_("The device %{name} is directly formatted.\n" \
"Remove the filesystem on %{name}?"),
name: device_name
)
Expand Down Expand Up @@ -201,7 +201,7 @@ def unmount
# TRANSLATORS: Note added to the dialog for trying to unmount devices
note = _("A new partition cannot be created while the file system is mounted.")

Dialogs::Unmount.new(controller.committed_filesystem, note: note).run == :finish
Dialogs::Unmount.new(controller.committed_filesystem, note:).run == :finish
end

# Convenience method for returning the device available partition types
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/actions/configure_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def perform_action

Yast::WFM.call(client) if client
reset_activation if reset_activation?
reprobe(activate: activate)
reprobe(activate:)

:finish
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ module AvailableDevices
# @yield [Y2Storage::BlkDevice]
#
# @return [Array<Y2Storage::BlkDevice>]
def available_devices(devicegraph, &block)
def available_devices(devicegraph, &)
finder = Finder.new(devicegraph)

finder.available_devices(&block)
finder.available_devices(&)
end

# Helper class to find available devices
Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2partitioner/actions/controllers/encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_secure_key_generation(apqns: [])
key_name = "yast2_tmp_secure_key_test"

begin
key = Y2Storage::EncryptionProcesses::SecureKey.generate!(key_name, apqns: apqns)
key = Y2Storage::EncryptionProcesses::SecureKey.generate!(key_name, apqns:)
rescue Cheetah::ExecutionFailed => e
return e.message
end
Expand Down Expand Up @@ -358,7 +358,7 @@ def finish_remove
def finish_encrypt
blk_device.remove_encryption if blk_device.encrypted?
blk_device.encrypt(
method: method, password: password, apqns: apqns, label: label, pbkdf: pbkdf
method:, password:, apqns:, label:, pbkdf:
)
end

Expand Down
8 changes: 4 additions & 4 deletions 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 Expand Up @@ -240,12 +240,12 @@ def new_filesystem(type)
end

delete_filesystem
create_filesystem(type, label: label)
create_filesystem(type, label:)
self.partition_id = filesystem.type.default_partition_id

return if mount_path.nil?

create_mount_point(mount_path, mount_by: mount_by, manual_mount_by: manual)
create_mount_point(mount_path, mount_by:, manual_mount_by: manual)
end

# Makes the changes related to the option "do not format" in the UI, which
Expand Down Expand Up @@ -550,7 +550,7 @@ def restore_filesystem
@restorer.restore_from_system
@encrypt = blk_device.encrypted?

restore_mount_point(mount_path, mount_by: mount_by, manual_mount_by: manual)
restore_mount_point(mount_path, mount_by:, manual_mount_by: manual)
blk_device.update_etc_status
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2partitioner/actions/controllers/fstabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def not_importable_entries_error
# TRANSLATORS: %{mount_points} is replaced by a list of mount points, please
# do not modify it.
format(_("The following mount points cannot be imported:\n%{mount_points}"),
mount_points: mount_points)
mount_points:)
end

# Entries in the current selected fstab that can be imported
Expand Down