Skip to content

Commit

Permalink
Merge pull request #393 from yast/update_rubocop
Browse files Browse the repository at this point in the history
Update rubocop
  • Loading branch information
jreidinger committed Jan 8, 2024
2 parents 64cd568 + 21390f0 commit 4348c24
Show file tree
Hide file tree
Showing 35 changed files with 78 additions and 51 deletions.
14 changes: 12 additions & 2 deletions .rubocop.yml
@@ -1,19 +1,29 @@
# use the shared YaST defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop-0.71.0_yast_style.yml
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml

# Don't enforce any particular name for block params
SingleLineBlockParams:
Style/SingleLineBlockParams:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Metrics/AbcSize:
Max: 40

Metrics/CyclomaticComplexity:
Max: 10

Metrics/BlockLength:
# rspec is known as DSL with big blocks
Exclude:
- test/**/*

# do not break API
Naming/MethodParameterName:
Enabled: false

AllCops:
Exclude:
- 'src/modules/**/*'
Expand Down
12 changes: 5 additions & 7 deletions src/lib/users/clients/auto.rb
Expand Up @@ -19,14 +19,13 @@

require "yast"
require "installation/auto_client"
require "y2issues"
require "y2users"
require "y2users/autoinst/reader"
require "y2issues"
require "y2users/config_merger"
require "y2users/config_manager"
require "y2users/autoinst/reader"
require "y2users/users_module/reader"
require "y2users/config_merger"
require "y2users/linux/writer"
require "y2users/users_module/reader"

Yast.import "Users"
Yast.import "Linuxrc"
Expand All @@ -41,6 +40,7 @@ module Clients
# AutoYaST users client
class Auto < ::Installation::AutoClient
def initialize
super
textdomain "users"

Yast.include self, "users/wizards.rb"
Expand All @@ -55,9 +55,7 @@ def import(param)
result = reader.read
read_linuxrc_root_pwd(result.config)

if result.issues?
return false unless Y2Issues.report(result.issues)
end
return false if result.issues? && !Y2Issues.report(result.issues)

Y2Users::ConfigManager.instance.target = result.config

Expand Down
1 change: 1 addition & 0 deletions src/lib/users/clients/users_finish.rb
Expand Up @@ -37,6 +37,7 @@ class UsersFinishClient < ::Installation::FinishClient
include Logger

def initialize
super
textdomain "users"

Yast.import "Users"
Expand Down
1 change: 1 addition & 0 deletions src/lib/users/dialogs/inst_root_first.rb
Expand Up @@ -33,6 +33,7 @@ class InstRootFirstDialog < ::CWM::Dialog
#
# @param root_user [Y2Users::Users] object holding the root user configuration
def initialize(root_user)
super()
textdomain "users"

@root_user = root_user
Expand Down
1 change: 1 addition & 0 deletions src/lib/users/encryption_proposal.rb
Expand Up @@ -26,6 +26,7 @@ class EncryptionProposal < ::Installation::ProposalClient
include Yast::Logger

def initialize
super
Yast.import "Wizard"
textdomain "users"
end
Expand Down
1 change: 1 addition & 0 deletions src/lib/users/proposal.rb
Expand Up @@ -29,6 +29,7 @@ class Proposal < ::Installation::ProposalClient
include Yast::Logger

def initialize
super
Yast.import "Wizard"
Yast.import "Mode"
textdomain "users"
Expand Down
3 changes: 3 additions & 0 deletions src/lib/users/ssh_authorized_keys_file.rb
Expand Up @@ -100,9 +100,12 @@ def keys=(new_keys)
keys
end

# it is not our regexp
# rubocop:disable Lint/MixedRegexpCaptureTypes
# https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/ssh_authorized_key.rb#L138
AUTHORIZED_KEYS_REGEX =
/\A(?<env>(.+)\s+)?(?<type>(ssh|ecdsa)-\S+)\s+(?<key>[^ ]+)\s*(?<comment>.*)\z/.freeze
# rubocop:enable Lint/MixedRegexpCaptureTypes

# Determine is a string qualifies like a valid key
#
Expand Down
4 changes: 2 additions & 2 deletions src/lib/users/ssh_public_key.rb
Expand Up @@ -47,7 +47,7 @@ def initialize(raw)
#
# @return [String] Comment field
def comment
@comment ||= raw.split(" ")[2]
@comment ||= raw.split[2]
end

# Returns the string version of the public key
Expand All @@ -64,7 +64,7 @@ def to_s
#
# @see https://github.com/openssh/openssh-portable/blob/1a4a9cf80f5b92b9d1dadd0bfa8867c04d195391/sshkey.c#L955
def formatted_fingerprint
fp = fingerprint.sub(/\=+\Z/, "")
fp = fingerprint.sub(/=+\Z/, "")
"SHA256:#{fp}"
end

Expand Down
3 changes: 1 addition & 2 deletions src/lib/users/widgets.rb
Expand Up @@ -51,6 +51,7 @@ class << self
# @param focus [Boolean] if set, then widget set focus to first password input field
# @param allow_empty [Boolean] whether the user can left the password empty or not
def initialize(user, little_space: false, focus: false, allow_empty: false)
super()
textdomain "users"

@user = user
Expand Down Expand Up @@ -105,7 +106,6 @@ def init
# FIXME: Validation methods should only check values. Note that with the current implementation,
# this method is taking care of setting/removing the user's password. This method should not
# modify the user.
# rubocop:disable Metrics/CyclomaticComplexity
def validate
password1 = Yast::UI.QueryWidget(Id(:pw1), :Value)
password2 = Yast::UI.QueryWidget(Id(:pw2), :Value)
Expand Down Expand Up @@ -139,7 +139,6 @@ def validate

true
end
# rubocop:enable Metrics/CyclomaticComplexity

def help # rubocop:disable Metrics/MethodLength
# help text ( explain what the user "root" is and does ) 1
Expand Down
1 change: 1 addition & 0 deletions src/lib/users/widgets/inst_root_first.rb
Expand Up @@ -31,6 +31,7 @@ class InstRootFirst < ::CWM::CustomWidget
#
# @param user [Y2Users::User] the root user to work with
def initialize(user)
super()
textdomain "users"

@user = user
Expand Down
1 change: 1 addition & 0 deletions src/lib/users/widgets/public_key_selector.rb
Expand Up @@ -40,6 +40,7 @@ class << self
#
# @param user [Y2Users::User] the user to work with
def initialize(user)
super()
textdomain "users"

@user = user
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/autoinst_profile/groups_section.rb
Expand Up @@ -41,6 +41,7 @@ def new_from_hashes(hashes)
end

def initialize(groups = [])
super()
@groups = groups
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/autoinst_profile/users_section.rb
Expand Up @@ -40,6 +40,7 @@ def new_from_hashes(hashes)
end

def initialize(users = [])
super()
@users = users
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/config.rb
Expand Up @@ -188,7 +188,7 @@ def detach_element(element)

if !exist
log.warn("Detach element: element #{element} is attached to the config #{self}, but " \
"it cannot be found.")
"it cannot be found.")
end

collection_for(element).delete(element.id) if exist
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/config_element.rb
Expand Up @@ -74,7 +74,7 @@ def attached?
# @param other [ConfigElement]
# @return [Boolean]
def is?(other)
return false unless self.class == other.class
return false unless instance_of?(other.class)
return false if id.nil? || other.id.nil?

id == other.id
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/config_element_collection.rb
Expand Up @@ -26,7 +26,7 @@ class ConfigElementCollection < Collection
#
# @param elements [Array<ConfigElement>]
def initialize(elements = [])
@elements = elements
super
end

# Deletes the element with the given id from the collection
Expand Down
2 changes: 0 additions & 2 deletions src/lib/y2users/config_manager.rb
Expand Up @@ -34,13 +34,11 @@ def initialize
# @param [Config] config
# @param [Symbol] as id of config
# @note if given id is already registered, it is overwritten
# rubocop:disable Naming/UncommunicativeMethodParamName
def register(config, as:)
raise ArgumentError, "#{as.inspect} is not Symbol" unless as.is_a?(Symbol)

@register[as] = config
end
# rubocop:enable Naming/UncommunicativeMethodParamName

# Unregister given id
# @param [Symbol] id of config
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/linux/groups_writer.rb
Expand Up @@ -42,6 +42,7 @@ class GroupsWriter < ActionWriter
# @param initial_config [Config] see #initial_config
# @param commit_config [CommitConfig] see #commit_config
def initialize(target_config, initial_config, commit_config)
super()
textdomain "users"

@initial_config = initial_config
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/linux/local_reader.rb
Expand Up @@ -27,6 +27,7 @@ class LocalReader < BaseReader
#
# @param source_dir [String, Pathname] path of source directory for reading files
def initialize(source_dir = "/")
super()
@source_dir = source_dir
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/linux/set_user_password_action.rb
Expand Up @@ -125,7 +125,7 @@ def chpasswd_options
def chage_options
return [] unless user.password

opts = chage_options_hash.reject { |_, v| v.nil? }.flatten
opts = chage_options_hash.compact.flatten
return [] if opts.empty?

opts + root_path_options
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/linux/useradd_config_writer.rb
Expand Up @@ -115,7 +115,7 @@ def initial_value(attr)
def write_useradd(issues)
if !write_useradd?
log.info "Not writing useradd file. " \
"#{useradd_config.inspect} - #{initial_useradd_config.inspect}"
"#{useradd_config.inspect} - #{initial_useradd_config.inspect}"
return
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/linux/users_writer.rb
Expand Up @@ -53,6 +53,7 @@ class UsersWriter < ActionWriter
# @param initial_config [Config] see #initial_config
# @param commit_config [CommitConfig]
def initialize(target_config, initial_config, commit_config)
super()
textdomain "users"

@initial_config = initial_config
Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/password.rb
Expand Up @@ -176,6 +176,7 @@ class PasswordValue < ShadowField
#
# @param content [String] password value
def initialize(content)
super()
self.content = content
end

Expand Down
6 changes: 3 additions & 3 deletions src/lib/y2users/password_validator.rb
Expand Up @@ -73,14 +73,14 @@ def issues
NUMBERS = "0123456789".freeze
# This regexp is allowed characters. It is what can be easily press on default keyboard layout
# to prevent issues with emergency login from console.
PASSWORD_REGEXP = /\A[-#{NUMBERS}#{LETTERS}!@#\:!\$%^&*() ,;:._+\/|?{}=\['\"`~<>\]\\]+\z/.freeze
PASSWORD_REGEXP = /\A[-#{NUMBERS}#{LETTERS}!@#:$%^&*() ,;._+\/|?{}=\['"`~<>\]\\]+\z/.freeze
def check_password
# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
return _("No password entered.\nTry again.") if !content || content.empty?

return "" if content =~ PASSWORD_REGEXP

# note duplicite string as in UsersSimple. Keep them in sync. Be aware of different
# NOTE: duplicite string as in UsersSimple. Keep them in sync. Be aware of different
# escaping in perl
_("The password may only contain the following characters:\n" \
"0-9, a-z, A-Z, and any of \"`~!@#$%^&* ,.;:._-+/|?='{[(<>)]}\\\".\n" \
Expand Down
12 changes: 6 additions & 6 deletions src/lib/y2users/user_validator.rb
Expand Up @@ -93,14 +93,14 @@ def add_fatal_issue(list, error, location)
# reason: see for example man utmp, UT_NAMESIZE
MAX_LENGTH = 32
def check_length
# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
return _("No username entered.\nTry again.") if user.name.nil? || user.name.empty?

return "" if (MIN_LENGTH..MAX_LENGTH).include?(user.name.size)

# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
format(_("The username must be between %i and %i characters in length.\n" \
"Try again."), MIN_LENGTH, MAX_LENGTH)
"Try again."), MIN_LENGTH, MAX_LENGTH)
end

LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".freeze
Expand All @@ -111,7 +111,7 @@ def check_length
def check_characters
return "" if user.name =~ CHAR_REGEXP

# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
_("The username may contain only\n" \
"Latin letters and digits, \"-\", \".\", and \"_\"\n" \
"and must begin with a letter or \"_\".\n" \
Expand Down Expand Up @@ -208,7 +208,7 @@ def check_username_conflict

return "" unless usernames.include?(user.name)

# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
_("There is a conflict between the entered\n" \
"username and an existing username.\n" \
"Try another one.")
Expand All @@ -219,7 +219,7 @@ def check_full_name

return "" if user.full_name !~ /[:,]/

# note duplicite string as in UsersSimple. Keep them in sync.
# NOTE: duplicite string as in UsersSimple. Keep them in sync.
_("The user's full name cannot contain\n" \
"\":\" or \",\" characters.\n" \
"Try again.")
Expand Down
6 changes: 6 additions & 0 deletions src/lib/y2users/useradd_config.rb
Expand Up @@ -92,6 +92,7 @@ def initialize(attrs = {})
#
# @return [String, nil]
attr_reader :group

attr_setter :group

# This value is used as prefix to calculate the home directory for a new user, if no home
Expand All @@ -103,6 +104,7 @@ def initialize(attrs = {})
#
# @return [String, nil]
attr_reader :home

attr_setter :home

# The file mode mask used to create new home directories, if HOME_MODE is not specified in
Expand All @@ -120,6 +122,7 @@ def initialize(attrs = {})
#
# @return [String, nil]
attr_reader :umask

attr_setter :umask

# Password expiration date to use when creating a user, if none was set
Expand All @@ -131,6 +134,7 @@ def initialize(attrs = {})
#
# @return [String, nil]
attr_reader :expiration

attr_setter :expiration

# Inactivity period to set when creating a user, if none was set
Expand All @@ -141,6 +145,7 @@ def initialize(attrs = {})
#
# @return [Integer, nil]
attr_reader :inactivity_period

attr_setter :inactivity_period

# Login shell to set for a newly created user, if none was specified
Expand All @@ -149,6 +154,7 @@ def initialize(attrs = {})
#
# @return [String, nil]
attr_reader :shell

attr_setter :shell

# Skeleton directory from which the files will be copied when creating a home directory for
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2users/username.rb
Expand Up @@ -28,7 +28,7 @@ class << self
# @param text [String] text for generating the username (usually the user fullname)
# @return [String] a valid username
def generate_from(text)
username = text.split(" ").first || ""
username = text.split.first || ""
username = transliterate(username)
username = sanitize(username)
username.downcase
Expand Down

0 comments on commit 4348c24

Please sign in to comment.