Skip to content

Commit

Permalink
[frontend] Fix Style/ClassCheck offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kang committed Dec 20, 2017
1 parent 7a9fd50 commit 35ac68b
Show file tree
Hide file tree
Showing 32 changed files with 84 additions and 91 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,6 @@ Rails/TimeZone:
Style/ClassAndModuleChildren:
Enabled: false

# Offense count: 85
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: is_a?, kind_of?
Style/ClassCheck:
Enabled: false

# Offense count: 35
Style/ClassVars:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def validate_params
params.each do |key, value|
next if value.nil?
next if key == 'xmlhash' # perfectly fine
unless value.kind_of? String
unless value.is_a? String
raise InvalidParameterError, "Parameter #{key} has non String class #{value.class}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def project_index

if !allowed && !params[:package].nil?
package_names = nil
if params[:package].kind_of? Array
if params[:package].is_a? Array
package_names = params[:package]
else
package_names = [params[:package]]
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def delete_project
project = Project.get_by_name(params[:project])

# checks
unless project.kind_of?(Project) && User.current.can_modify_project?(project)
unless project.is_a?(Project) && User.current.can_modify_project?(project)
logger.debug "No permission to delete project #{project}"
render_error status: 403, errorcode: 'delete_project_no_permission',
message: "Permission denied (delete project #{project})"
Expand Down Expand Up @@ -690,7 +690,7 @@ def update_package_meta
end
else
prj = Project.get_by_name(@project_name)
unless prj.kind_of?(Project) && User.current.can_create_package_in?(prj)
unless prj.is_a?(Project) && User.current.can_create_package_in?(prj)
render_error status: 403, errorcode: 'create_package_no_permission',
message: "no permission to create a package in project '#{@project_name}'"
return
Expand Down Expand Up @@ -1286,7 +1286,7 @@ def package_command_undelete
raise PackageExists, "the package exists already #{@target_project_name} #{@target_package_name}"
end
tprj = Project.get_by_name(@target_project_name)
unless tprj.kind_of?(Project) && User.current.can_create_package_in?(tprj)
unless tprj.is_a?(Project) && User.current.can_create_package_in?(tprj)
raise CmdExecutionNoPermission, "no permission to create package in project #{@target_project_name}"
end

Expand Down Expand Up @@ -1553,7 +1553,7 @@ def verify_can_modify_target!

if Package.exists_by_project_and_name(@target_project_name, @target_package_name, follow_project_links: false)
verify_can_modify_target_package!
elsif !@project.kind_of?(Project) || !User.current.can_create_package_in?(@project)
elsif !@project.is_a?(Project) || !User.current.can_create_package_in?(@project)
raise CmdExecutionNoPermission, "no permission to create package in project #{@target_project_name}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/flag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def set_repository_by_product(flag, status, product_name, patchlevel = nil)
validate_type flag

prj = self
prj = project if kind_of? Package
prj = project if is_a? Package
update = nil

# we find all repositories targeted by given products
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _release_package(source_package, target_project, target_package_name, action
def release_package(source_package, target, target_package_name,
filter_source_repository = nil, multibuild_container = nil, action = nil,
setrelease = nil, manual = nil)
if target.kind_of? Repository
if target.is_a? Repository
target_project = target.project
else
# project
Expand All @@ -61,7 +61,7 @@ def release_package(source_package, target, target_package_name,
end

# copy binaries
if target.kind_of? Repository
if target.is_a? Repository
u_ids = copy_binaries_to_repository(filter_source_repository, source_package, target, target_package_name, multibuild_container, setrelease)
else
u_ids = copy_binaries(filter_source_repository, source_package, target_package_name, target_project, multibuild_container, setrelease)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/validation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def valid_multibuild_package_name!(package_name)
# load last package meta file and just check if sourceaccess flag was used at all, no per user checking atm
def validate_read_access_of_deleted_package(project, name)
prj = Project.get_by_name project
if prj.kind_of? Project
if prj.is_a? Project
raise Project::ReadAccessError, project.to_s if prj.disabled_for? 'access', nil, nil
raise Package::ReadSourceAccessError, "#{target_project_name}/#{target_package_name}" if prj.disabled_for? 'sourceaccess', nil, nil
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def project_bread_crumb(*args)
@crumb_list = [link_to('Projects', project_list_public_path)]
return if @spider_bot
# FIXME: should also work for remote
if @project && @project.kind_of?(Project) && !@project.new_record?
if @project && @project.is_a?(Project) && !@project.new_record?
prj_parents = nil
if @namespace # corner case where no project object is available
prj_parents = Project.parent_projects(@namespace)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/jobs/consistency_check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def hash_diff(a, b)
# we need to ignore the ordering in some cases
# old xml generator wrote them in a different order
# but in other cases the order of elements matters
if k == 'person' && a_.kind_of?(Array)
if k == 'person' && a_.is_a?(Array)
a_ = a_.map { |i| "#{i['userid']}/#{i['role']}" }.sort
b_ = b_.map { |i| "#{i['userid']}/#{i['role']}" }.sort
end
if k == 'group' && a_.kind_of?(Array)
if k == 'group' && a_.is_a?(Array)
a_ = a_.map { |i| "#{i['groupid']}/#{i['role']}" }.sort
b_ = b_.map { |i| "#{i['groupid']}/#{i['role']}" }.sort
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/mixins/has_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def group_has_role?(group, role)
def remove_role(what, role)
check_write_access!

if what.kind_of? Group
if what.is_a? Group
rel = relationships.where(group_id: what.id)
else
rel = relationships.where(user_id: what.id)
Expand All @@ -67,7 +67,7 @@ def add_role(what, role)
check_write_access!

transaction do
if what.kind_of? Group
if what.is_a? Group
relationships.create!(role: role, group: what)
else
relationships.create!(role: role, user: what)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/attrib_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def update_from_xml(xmlhash)
def as_json(options = nil)
if options
if options.key?(:methods)
if options[:methods].kind_of? Array
if options[:methods].is_a? Array
options[:methods] << :attrib_namespace_name unless options[:methods].include?(:attrib_namespace_name)
elsif options[:methods] != :attrib_namespace_name
options[:methods] = [options[:methods]] + [:attrib_namespace_name]
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/branch_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def find_package_targets
end

def lookup_incident_pkg(p)
return unless p[:package].kind_of? Package
return unless p[:package].is_a? Package
@obs_maintenanceproject ||= AttribType.find_by_namespace_and_name!('OBS', 'MaintenanceProject')
@maintenance_projects ||= Project.find_by_attribute_type(@obs_maintenanceproject)
incident_pkg = nil
Expand Down Expand Up @@ -314,7 +314,7 @@ def determine_details_about_package_to_branch(p)
p[:target_package] += ".#{p[:link_target_project].name}" if @extend_names
end
if @extend_names
p[:release_name] = p[:package].kind_of?(String) ? p[:package] : p[:package].name
p[:release_name] = p[:package].is_a?(String) ? p[:package] : p[:package].name
end

# validate and resolve devel package or devel project definitions
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def self.new_from_xml(xml)
request.number = theid if theid

actions = hashed.delete('action')
if actions.kind_of? Hash
if actions.is_a? Hash
actions = [actions]
end

Expand Down Expand Up @@ -222,7 +222,7 @@ def self.new_from_xml(xml)
hashed.delete('history')

reviews = hashed.delete('review')
if reviews.kind_of? Hash
if reviews.is_a? Hash
reviews = [reviews]
end
reviews.each do |r|
Expand Down Expand Up @@ -496,7 +496,7 @@ def changestate_accepted(opts)
bs_request_actions.each do |action|
source_project = Project.find_by_name(action.source_project)
if action.source_project && action.is_maintenance_release?
if source_project.kind_of?(Project)
if source_project.is_a?(Project)
at = AttribType.find_by_namespace_and_name!('OBS', 'EmbargoDate')
attrib = source_project.attribs.find_by(attrib_type: at)
v = attrib.values.first if attrib
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/models/bs_request_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def create_expand_package(packages, opts = {})
new_targets = Array.new

packages.each do |pkg|
unless pkg.kind_of? Package
unless pkg.is_a? Package
raise RemoteSource, 'No support for auto expanding from remote instance. You need to submit a full specified request in that case.'
end
# find target via linkinfo or submit to all.
Expand Down Expand Up @@ -812,7 +812,7 @@ def check_action_permission!(skip_source = nil)
end
end
end
if action_type == :submit && tprj.kind_of?(Project)
if action_type == :submit && tprj.is_a?(Project)
at = AttribType.find_by_namespace_and_name!('OBS', 'MakeOriginOlder')
self.makeoriginolder = true if tprj.attribs.find_by(attrib_type: at)
end
Expand Down Expand Up @@ -952,8 +952,8 @@ def check_for_expand_errors!(add_revision)
dir = Xmlhash.parse(c)
if action_type == :maintenance_release && dir['entry']
# patchinfos in release requests get not frozen to allow to modify meta data
return if dir['entry'].kind_of?(Array) && dir['entry'].map { |e| e['name'] }.include?('_patchinfo')
return if dir['entry'].kind_of?(Hash) && dir['entry']['name'] == '_patchinfo'
return if dir['entry'].is_a?(Array) && dir['entry'].map { |e| e['name'] }.include?('_patchinfo')
return if dir['entry'].is_a?(Hash) && dir['entry']['name'] == '_patchinfo'
end
self.source_rev = dir['srcmd5']
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/event_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class EventSubscription < ApplicationRecord
scope :for_eventtype, ->(eventtype) { where(eventtype: eventtype) }
scope :defaults, -> { where(user_id: nil, group_id: nil) }
scope :for_subscriber, lambda { |subscriber|
if subscriber.kind_of? User
if subscriber.is_a? User
where(user: subscriber)
elsif subscriber.kind_of? Group
elsif subscriber.is_a? Group
where(group: subscriber)
else
defaults
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def compute_status(variant)
repo_flag = main_object.flags.find_by('flag = ? AND repo = ? AND architecture_id IS NULL', flag, repo)
arch_flag = main_object.flags.find_by('flag = ? AND repo IS NULL AND architecture_id = ?', flag, architecture_id)
same_flag = main_object.flags.find_by('flag = ? AND repo = ? AND architecture_id = ?', flag, repo, architecture_id)
if main_object.kind_of? Package
if main_object.is_a? Package
if variant == 'effective'
same_flag = main_object.project.flags.find_by('flag = ? AND repo = ? AND architecture_id = ?', flag, repo, architecture_id) unless
all_flag || same_flag || repo_flag || arch_flag
Expand Down Expand Up @@ -89,7 +89,7 @@ def compute_status(variant)
if same_flag || arch_flag || repo_flag
return all_flag.status if all_flag
end
if main_object.kind_of? Package
if main_object.is_a? Package
all_flag = main_object.project.flags.find_by('flag = ? AND repo IS NULL AND architecture_id IS NULL', flag)
return all_flag.status if all_flag
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ def self.valid_multibuild_name?(name)
end

def self.valid_name?(name, allow_multibuild = false)
return false unless name.kind_of? String
return false unless name.is_a? String
# this length check is duplicated but useful for other uses for this function
return false if name.length > 200
return false if name == '0'
Expand Down Expand Up @@ -1333,7 +1333,7 @@ def self.verify_file!(pkg, name, content)

# file is an ActionDispatch::Http::UploadedFile and Suse::Validator.validate
# will call to_s therefore we have to read the content first
content = File.open(content.path).read if content.kind_of?(ActionDispatch::Http::UploadedFile)
content = File.open(content.path).read if content.is_a?(ActionDispatch::Http::UploadedFile)

# schema validation, if possible
%w{aggregate constraints link service patchinfo channel}.each do |schema|
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def bsrequest_repos_map(project)
private :bsrequest_repos_map

def self.valid_name?(name)
return false unless name.kind_of? String
return false unless name.is_a? String
return false if name == '0';
return false if name =~ /::/
return false if name.end_with?(':')
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class SaveError < APIException; end

def self.add_user(obj, user, role, ignore_lock = nil, check = nil)
obj.check_write_access!(ignore_lock)
unless role.kind_of? Role
unless role.is_a? Role
role = Role.find_by_title!(role)
end
if role.global
# only nonglobal roles may be set in an object
raise SaveError, "tried to set global role '#{role.title}' for user '#{user}' in #{obj.class} '#{name}'"
end

unless user.kind_of? User
unless user.is_a? User
user = User.find_by_login!(user)
end

Expand All @@ -89,7 +89,7 @@ def self.add_user(obj, user, role, ignore_lock = nil, check = nil)
def self.add_group(obj, group, role, ignore_lock = nil, check = nil)
obj.check_write_access!(ignore_lock)

unless role.kind_of? Role
unless role.is_a? Role
role = Role.find_by_title!(role)
end

Expand All @@ -98,7 +98,7 @@ def self.add_group(obj, group, role, ignore_lock = nil, check = nil)
raise SaveError, "tried to set global role '#{role_title}' for group '#{group}' in #{obj.class} '#{name}'"
end

unless group.kind_of? Group
unless group.is_a? Group
group = Group.find_by_title(group.to_s)
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.make_stub(_opt)
end

def self.valid_name?(name)
return false unless name.kind_of?(String)
return false unless name.is_a?(String)
return false if name.length > 200 || name.blank?
return false if name =~ %r{^[_\.]}
return false if name =~ %r{::}
Expand Down
14 changes: 7 additions & 7 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def has_global_permission?(perm_string)

# project is instance of Project
def can_modify_project?(project, ignore_lock = nil)
unless project.kind_of? Project
unless project.is_a? Project
raise ArgumentError, "illegal parameter type to User#can_modify_project?: #{project.class.name}"
end

Expand All @@ -434,7 +434,7 @@ def can_modify_project?(project, ignore_lock = nil)
# package is instance of Package
def can_modify_package?(package, ignore_lock = nil)
return false if package.nil? # happens with remote packages easily
unless package.kind_of? Package
unless package.is_a? Package
raise ArgumentError, "illegal parameter type to User#can_modify_package?: #{package.class.name}"
end
return false if !ignore_lock && package.is_locked?
Expand All @@ -446,7 +446,7 @@ def can_modify_package?(package, ignore_lock = nil)

# project is instance of Project
def can_create_package_in?(project, ignore_lock = nil)
unless project.kind_of? Project
unless project.is_a? Project
raise ArgumentError, "illegal parameter type to User#can_change?: #{project.class.name}"
end

Expand Down Expand Up @@ -475,10 +475,10 @@ def can_modify_attribute_definition?(object)
end

def can_create_attribute_definition?(object)
if object.kind_of? AttribType
if object.is_a? AttribType
object = object.attrib_namespace
end
unless object.kind_of? AttribNamespace
unless object.is_a? AttribNamespace
raise ArgumentError, "illegal parameter type to User#can_change?: #{object.class.name}"
end

Expand All @@ -496,7 +496,7 @@ def can_create_attribute_definition?(object)

# rubocop:disable Style/GuardClause
def can_create_attribute_in?(object, opts)
if !object.kind_of?(Project) && !object.kind_of?(Package)
if !object.is_a?(Project) && !object.is_a?(Package)
raise ArgumentError, "illegal parameter type to User#can_change?: #{object.class.name}"
end
unless opts[:namespace]
Expand All @@ -515,7 +515,7 @@ def can_create_attribute_in?(object, opts)
abies = atype.attrib_type_modifiable_bies.includes([:user, :group, :role])
if abies.empty?
# no rules set for attribute, just check package maintainer rules
if object.kind_of? Project
if object.is_a? Project
return can_modify_project?(object)
else
return can_modify_package?(object)
Expand Down
Loading

0 comments on commit 35ac68b

Please sign in to comment.