Skip to content

Commit

Permalink
Merge pull request #4204 from DavidKang/feature/rubocop/rubocop_todo
Browse files Browse the repository at this point in the history
Rubocop friendly cops
  • Loading branch information
Moisés Déniz Alemán committed Dec 12, 2017
2 parents 57b0f74 + e709d72 commit c26b290
Show file tree
Hide file tree
Showing 52 changed files with 315 additions and 354 deletions.
49 changes: 0 additions & 49 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,13 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 19
# Cop supports --auto-correct.
Layout/AlignArray:
Exclude:
- 'src/api/lib/activexml/transport.rb'
- 'src/api/lib/xpath_engine.rb'
- 'src/api/test/functional/source_controller_test.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, SupportedHashRocketStyles, EnforcedColonStyle, SupportedColonStyles, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/AlignHash:
Exclude:
- 'src/api/app/views/webui/feeds/commits.atom.builder'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Layout/AlignParameters:
Exclude:
- 'src/api/app/views/statistics/rating.xml.builder'

# Offense count: 31
# Cop supports --auto-correct.
Layout/ClosingParenthesisIndentation:
Exclude:
- 'src/api/app/views/statistics/rating.xml.builder'
- 'src/api/test/unit/project_test.rb'

# Offense count: 68
# Cop supports --auto-correct.
Layout/CommentIndentation:
Enabled: false

# Offense count: 78
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: leading, trailing
Layout/DotPosition:
Enabled: false

# Offense count: 17
# Cop supports --auto-correct.
Layout/EmptyLineAfterMagicComment:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLinesAroundBeginBody:
Exclude:
- 'src/api/app/controllers/webui/patchinfo_controller.rb'

# Offense count: 35
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
2 changes: 1 addition & 1 deletion src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ group :production do
# if you have an account, it can be configured by
# placing a config/newrelic.yml
# be aware about the non-OSS license
# gem 'newrelic_rpm'
# gem 'newrelic_rpm'
end

# Gems used only for testing the application and not required in production environments by default.
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ConfigurationsController < ApplicationController
skip_before_action :validate_params, only: [:update] # we use an array for archs here

validate_action show: {method: :get, response: :configuration}
# webui is using this route with parameters instead of content
# validate_action :update => {:method => :put, :request => :configuration}
# webui is using this route with parameters instead of content
# validate_action :update => {:method => :put, :request => :configuration}

# GET /configuration
# GET /configuration.xml
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ def show_package_meta
pack = Package.get_by_project_and_name(@project_name, @package_name, use_source: false)

if params.has_key?(:meta) || params.has_key?(:rev) || params.has_key?(:view) || pack.nil?
# check if this comes from a remote project, also true for _project package
# or if meta is specified we need to fetch the meta from the backend
# check if this comes from a remote project, also true for _project package
# or if meta is specified we need to fetch the meta from the backend
path = request.path_info
path += build_query_from_hash(params, [:meta, :rev, :view])
pass_to_backend path
Expand Down Expand Up @@ -1228,9 +1228,9 @@ def package_command_showlinked
# FIXME: return an empty list for now
# we could request the links on remote instance via that: but we would need to search also localy and merge ...

# path = "/search/package/id?match=(@linkinfo/package=\"#{CGI.escape(package_name)}\"+and+@linkinfo/project=\"#{CGI.escape(project_name)}\")"
# answer = Backend::Connection.post path
# render :text => answer.body, :content_type => 'text/xml'
# path = "/search/package/id?match=(@linkinfo/package=\"#{CGI.escape(package_name)}\"+and+@linkinfo/project=\"#{CGI.escape(project_name)}\")"
# answer = Backend::Connection.post path
# render :text => answer.body, :content_type => 'text/xml'
render xml: '<collection/>'
return
end
Expand Down
1 change: 0 additions & 1 deletion src/api/app/controllers/webui/patchinfo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def new_tracker
end
if issue.length > 1
begin

issueurl = IssueTracker.find_by_name(issue[0])
if issueurl
Rails.logger.debug "URL2 #{issueurl.inspect}"
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/mixins/request_source_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def diff_for_source(spkg, options = {})
query[:opackage] = @target_package
query[:rev] = action.source_rev if action.source_rev
elsif action.source_rev # Use source rev for diffing (if available)
# No target package means diffing the source package against itself.
# No target package means diffing the source package against itself.
query[:orev] = 0
query[:rev] = action.source_rev
else # Otherwise generate diff for latest source package revision
# FIXME: move to Package model
# FIXME: move to Package model
spkg_rev = Directory.find_hashed(project: action.source_project, package: spkg)['rev']
query[:orev] = 0
query[:rev] = spkg_rev
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/models/binary_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def self.update_binary_releases(repository, key, time = Time.now)

def self.update_binary_releases_via_json(repository, json, time = Time.now)
oldlist = where(repository: repository, obsolete_time: nil, modify_time: nil)
processed_item = {} # we can not just remove it from relation
# delete would affect the object
# we can not just remove it from relation, delete would affect the object.
processed_item = {}

BinaryRelease.transaction do
json.each do |binary|
Expand All @@ -59,7 +59,7 @@ def self.update_binary_releases_via_json(repository, json, time = Time.now)
if entry.binary_disturl == binary["disturl"] &&
entry.binary_supportstatus == binary["supportstatus"] &&
entry.binary_buildtime.to_datetime.utc == ::Time.at(binary["buildtime"].to_i).to_datetime.utc
# same binary, don't touch
# same binary, don't touch
processed_item[entry.id] = true
next
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/branch_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def create_branch_packages(tprj)
ret = ActiveXML::Node.new(tpkg.source_file('_link'))
ret.delete_attribute('project') # its a local link, project name not needed
linked_package = p[:link_target_package]
# user enforce a rename of base package
# user enforce a rename of base package
linked_package = params[:target_package] if params[:target_package] && params[:package] == ret.value('package')
linked_package += '.' + p[:link_target_project].name.tr(':', '_') if @extend_names
ret.set_attribute('package', linked_package)
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/models/bs_request_permission_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def cmd_changestate_permissions(opts)

attr_accessor :opts, :req

# check if the request can change state - or throw an APIException if not
# check if the request can change state - or throw an APIException if not
def initialize(_req, _opts)
self.req = _req
self.opts = _opts
Expand All @@ -379,7 +379,7 @@ def initialize(_req, _opts)
@write_permission_in_target = false
end

# Is the user involved in any project or package ?
# Is the user involved in any project or package ?
def require_permissions_in_target_or_source
unless @write_permission_in_target || @write_permission_in_source
raise AddReviewNotPermitted, "You have no role in request #{req.number}"
Expand All @@ -391,14 +391,14 @@ def extra_permissions_check_changestate
err =
case opts[:newstate]
when 'superseded'
# Is the user involved in any project or package ?
# Is the user involved in any project or package ?
unless @write_permission_in_target || @write_permission_in_source
"You have no role in request #{req.number}"
end
when 'accepted'
# requires write permissions in all targets, this is already handled in each action check
# requires write permissions in all targets, this is already handled in each action check
when 'revoked'
# general revoke permission check based on source maintainership. We don't get here if the user is the creator of request
# general revoke permission check based on source maintainership. We don't get here if the user is the creator of request
unless @write_permission_in_source
"No permission to revoke request #{req.number}"
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/history_element.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module HistoryElement
# This class represents some kind of history element within the build service
# This class represents some kind of history element within the build service
class Base < ApplicationRecord
belongs_to :user

Expand Down
22 changes: 11 additions & 11 deletions src/api/app/models/issue_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def update_issues_bugzilla

# skip callbacks to avoid scheduling expensive jobs

# rubocop:disable Rails/SkipsModelValidations
# rubocop:disable Rails/SkipsModelValidations
update_columns(issues_updated: @update_time_stamp)
# rubocop:enable Rails/SkipsModelValidations
# rubocop:enable Rails/SkipsModelValidations
end

def update_issues_github
Expand All @@ -111,9 +111,9 @@ def update_issues_github
parse_github_issues(ActiveSupport::JSON.decode(response.body))

# we skip callbacks to avoid scheduling expensive jobs
# rubocop:disable Rails/SkipsModelValidations
# rubocop:disable Rails/SkipsModelValidations
update_columns(issues_updated: mtime - 1.second)
# rubocop:enable Rails/SkipsModelValidations
# rubocop:enable Rails/SkipsModelValidations
end

def update_issues_cve
Expand All @@ -135,9 +135,9 @@ def update_issues_cve
parser = Nokogiri::XML::SAX::Parser.new(listener)
parser.parse_io(unzipedio)
# we skip callbacks to avoid scheduling expensive jobs
# rubocop:disable Rails/SkipsModelValidations
# rubocop:disable Rails/SkipsModelValidations
update_columns(issues_updated: mtime - 1.second)
# rubocop:enable Rails/SkipsModelValidations
# rubocop:enable Rails/SkipsModelValidations
end

def update_issues
Expand All @@ -162,9 +162,9 @@ def enforced_update_all_issues
if private_fetch_issues(ids)
# don't use "last_change_time" from bugzilla, since we may have different clocks
# and skip callbacks to avoid scheduling expensive jobs
# rubocop:disable Rails/SkipsModelValidations
# rubocop:disable Rails/SkipsModelValidations
update_columns(issues_updated: @update_time_stamp)
# rubocop:enable Rails/SkipsModelValidations
# rubocop:enable Rails/SkipsModelValidations
return true
end
false
Expand Down Expand Up @@ -232,10 +232,10 @@ def parse_single_bugzilla_issue(bugzilla_response)
end

if bugzilla_response["creation_time"].present?
# rubocop:disable Rails/Date
# rubocop bug, this is XMLRPC/DateTime not Rails/Date
# rubocop:disable Rails/Date
# rubocop bug, this is XMLRPC/DateTime not Rails/Date
issue.created_at = bugzilla_response["creation_time"].to_time
# rubocop:enable Rails/Date
# rubocop:enable Rails/Date
else
issue.created_at = Time.now
end
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/owner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 i*-

require 'api_exception'

class Owner
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 i*-

require_dependency 'api_exception'
require 'builder/xchar'
require 'rexml/document'
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/statistics/latest_updated.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ xml.latest_updated do
:updated => item[0].xmlschema
)
else
### item is a project
### item is a project
xml.project(
:name => item[1],
:updated => item[0].xmlschema
Expand Down
12 changes: 6 additions & 6 deletions src/api/app/views/statistics/rating.xml.builder
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

if @package && @project
xml.rating( @rating[:score],
:count => @rating[:count], :project => @project, :package => @package,
:user_score => @rating[:user_score]
)
:count => @rating[:count], :project => @project, :package => @package,
:user_score => @rating[:user_score]
)
elsif @project
xml.rating( @rating[:score],
:count => @rating[:count], :project => @project,
:user_score => @rating[:user_score]
)
:count => @rating[:count], :project => @project,
:user_score => @rating[:user_score]
)
else
xml.rating
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/feeds/commits.atom.builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Don't ask me why atom_feed helper does not work. Reimplementing its logic
feed_opts = { "xml:lang" => "en-US",
"xmlns" => 'http://www.w3.org/2005/Atom' }
"xmlns" => 'http://www.w3.org/2005/Atom' }
schema_date = "2013-11-22"
obs_host = URI.parse(::Configuration.obs_url).host

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/main/sitemap_projects.builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rubocop:disable Metrics/LineLength
xml.urlset(xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd") do
# rubocop:enable Metrics/LineLength
# rubocop:enable Metrics/LineLength

xml.url do
xml.loc url_for controller: :main, action: :index, only_path: false
Expand Down
1 change: 1 addition & 0 deletions src/api/bin/pry
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/ruby.ruby2.4
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
Expand Down
1 change: 1 addition & 0 deletions src/api/bin/rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/ruby.ruby2.4
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
Expand Down
1 change: 1 addition & 0 deletions src/api/bin/ri
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/ruby.ruby2.4
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
Expand Down
1 change: 1 addition & 0 deletions src/api/bin/rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/ruby.ruby2.4
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
Expand Down
1 change: 1 addition & 0 deletions src/api/bin/rubocop
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/ruby.ruby2.4
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
Expand Down
4 changes: 2 additions & 2 deletions src/api/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

config.active_support.deprecation = :log

# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

config.active_support.deprecation = :log
# Print deprecation notices to the stderr.
# config.active_support.deprecation = :stderr
# config.active_support.deprecation = :stderr

config.eager_load = false

Expand Down
2 changes: 1 addition & 1 deletion src/api/db/attribute_descriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def update_all_attrib_type_descriptions
"Maintained" => "Marks this as object as maintained. For instance to find packages automatically when using the maintenance features like \"osc mbranch\".",
"MaintenanceProject" => "Mark this project as central maintenance project, which is used to coordinate all official updates.",
"MaintenanceIdTemplate" => "Released maintenance updates get an ID on first release. This attribute can be used to modify the default scheme.",
# "ScreenShots" => "", # to be dropped?
# "ScreenShots" => "", # to be dropped?
"ImageTemplates" => "Mark this project as source for image templates.",
"OwnerRootProject" => "Mark this project as starting point for the package ownership search. Optional values: \"DisableDevel\": don't follow devel project links. \"BugownerOnly\": limit the result to bugowners (ignoring the maintainer role).",
"RequestCloned" => "Use this attribute to reference a request which will get superseded when a new submit request from this project gets created.",
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/activexml/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def load_external_url(uri)
content = response.body
end
rescue SocketError, Errno::EINTR, Errno::EPIPE, EOFError, Net::HTTPBadResponse, IOError, Errno::ENETUNREACH,
Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error => err
Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error => err
logger.debug "#{err} when fetching #{uri}"
http = nil
end
Expand Down
Loading

0 comments on commit c26b290

Please sign in to comment.