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

Update rubocop #1753

Merged
merged 15 commits into from
Mar 18, 2020
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
3 changes: 2 additions & 1 deletion .hound.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ruby:
rubocop:
config_file: .rubocop.yml
version: 0.80.0
scss:
enabled: false
coffeescript:
Expand Down
39 changes: 20 additions & 19 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Relaxed.Ruby.Style

AllCops:
TargetRubyVersion: 2.3
Exclude:
- 'bin/rspec'
- 'vendor/**/*'
Expand All @@ -9,24 +10,20 @@ AllCops:
- 'alchemy_cms.gemspec'
- 'Rakefile'

TargetRubyVersion: 2.3

# Really, rubocop?
Bundler/OrderedGems:
Enabled: false

# Sometimes I believe this reads better
# This also causes spacing issues on multi-line fixes
Style/BracesAroundHashParameters:
Enabled: false

Style/EmptyLiteral:
Enabled: false

# We use class vars and will have to continue doing so for compatability
Style/ClassVars:
Enabled: false

Style/FloatDivision:
EnforcedStyle: left_coerce

# This has been used for customization
Style/MutableConstant:
Enabled: false
Expand Down Expand Up @@ -55,13 +52,13 @@ Style/MixinUsage:
Exclude:
- spec/**/*

Performance/Count:
Layout/ArgumentAlignment:
Enabled: false

Layout/AlignHash:
Layout/HashAlignment:
Enabled: false

Layout/AlignParameters:
Layout/ParameterAlignment:
Enabled: false

Layout/ClosingParenthesisIndentation:
Expand All @@ -77,18 +74,22 @@ Layout/ElseAlignment:
Layout/EmptyLineAfterMagicComment:
Enabled: false

Layout/IndentArray:
Enabled: false
Layout/EmptyLinesAroundAccessModifier:
Exclude:
- lib/alchemy/test_support/factories/*.rb

Layout/IndentHash:
Layout/FirstArrayElementIndentation:
Enabled: false

Layout/IndentHeredoc:
EnforcedStyle: active_support
Layout/FirstHashElementIndentation:
Enabled: false

Layout/IndentationWidth:
Enabled: false

Layout/LineLength:
Enabled: false

Layout/MultilineHashBraceLayout:
Enabled: false

Expand All @@ -115,7 +116,10 @@ Layout/SpaceInsideParens:
Layout/EndAlignment:
Enabled: false

Lint/HandleExceptions:
Layout/RescueEnsureAlignment:
Enabled: false

Lint/SuppressedException:
Exclude:
- 'config/initializers/mini_profiler.rb'

Expand Down Expand Up @@ -268,9 +272,6 @@ Metrics/ModuleLength:
Metrics/CyclomaticComplexity:
Enabled: false

Metrics/LineLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gemspec
Expand All @@ -21,7 +22,7 @@ group :development, :test do
gem 'yard'
gem 'redcarpet'
gem 'pry-byebug'
gem 'rubocop', '0.54', require: false
gem 'rubocop', '~> 0.80.1', require: false
gem 'listen'
gem 'localeapp', '~> 3.0', require: false
gem 'dotenv', '~> 2.2'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def reset_stamper
# Returns true if the current_alchemy_user (The logged-in Alchemy User) has the admin role.
def is_admin?
return false if !current_alchemy_user

current_alchemy_user.admin?
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/clipboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def set_clipboard

def model_class
raise ActionController::BadRequest unless remarkable_type

"alchemy/#{remarkable_type}".classify.constantize
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def update_check
def latest_alchemy_version
versions = get_alchemy_versions
return '' if versions.blank?

# reject any non release version
versions.reject! { |v| v =~ /[a-z]/ }
versions.max
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def ratio_from_size_or_settings
if @min_size.value?(0) && @essence_picture.content.settings[:fixed_ratio].to_s =~ FLOAT_REGEX
@essence_picture.content.settings[:fixed_ratio].to_f
elsif !@min_size[:width].zero? && !@min_size[:height].zero?
@min_size[:width].to_f / @min_size[:height].to_f
@min_size[:width].to_f / @min_size[:height]
else
false
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,13 @@ def secure_attributes
def page_is_locked?
return false if !@page.locker.try(:logged_in?)
return false if !current_alchemy_user.respond_to?(:id)

@page.locked? && @page.locker.id != current_alchemy_user.id
end

def page_needs_lock?
return true unless @page.locker

@page.locker.try!(:id) != current_alchemy_user.try!(:id)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/alchemy/admin/pictures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def items_per_page
end
else
cookies[:alchemy_pictures_per_page] = params[:per_page] ||
cookies[:alchemy_pictures_per_page] ||
pictures_per_page_for_size(params[:size])
cookies[:alchemy_pictures_per_page] ||
pictures_per_page_for_size(params[:size])
end
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def resource_handler
# The key should look like "Modelname successfully created|updated|destroyed."
def flash_notice_for_resource_action(action = params[:action])
return if resource_instance_variable.errors.any?

case action.to_sym
when :create
verb = "created"
Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/styleguide_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Alchemy
module Admin
class StyleguideController < BaseController
Expand Down
1 change: 1 addition & 0 deletions app/controllers/alchemy/admin/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def tag_params

def tags_from_term(term)
return [] if term.blank?

Gutentag::Tag.where(['LOWER(name) LIKE ?', "#{term.downcase}%"])
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def handle_redirect_for_guest
def exception_logger(error)
Rails.logger.error("\n#{error.class} #{error.message} in #{error.backtrace.first}")
Rails.logger.error(error.backtrace[1..50].each { |line|
line.gsub(/#{Rails.root.to_s}/, '')
line.gsub(/#{Rails.root}/, '')
}.join("\n"))
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/alchemy/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def create #:nodoc:
if @element.nil?
raise ActiveRecord::RecordNotFound, "Contact form id not found. Please pass the :contact_form_id in a hidden field. Example: <%= f.hidden_field :contact_form_id, value: element.id %>"
end

@page = @element.page
@root_page = @page.get_language_root
if @message.valid?
Expand Down Expand Up @@ -121,6 +122,7 @@ def get_page
if @page.blank?
raise "Page for page_layout #{mailer_config['page_layout_name']} not found"
end

@root_page = @page.get_language_root
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/alchemy/admin/archive_overlay.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Alchemy
module Admin
module ArchiveOverlay
Expand Down
1 change: 1 addition & 0 deletions app/decorators/alchemy/element_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def css_classes
# Tells us, if we should show the element footer and form inputs.
def editable?
return false if folded?

content_definitions.present? || taggable?
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/alchemy/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def alchemy_datepicker(object, method, html_options = {})
# The model class needs to include the hints module
def render_hint_for(element)
return unless element.has_hint?

content_tag :span, class: 'hint-with-icon' do
render_icon('question-circle') +
content_tag(:span, element.hint.html_safe, class: 'hint-bubble')
Expand Down
1 change: 1 addition & 0 deletions app/helpers/alchemy/admin/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module ElementsHelper
#
def elements_for_select(elements)
return [] if elements.nil?

elements.collect do |e|
[
Element.display_name_for(e['name']),
Expand Down
1 change: 1 addition & 0 deletions app/helpers/alchemy/admin/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def url_for_module(alchemy_module)
def url_for_module_sub_navigation(navigation)
alchemy_module = module_definition_for(navigation)
return if alchemy_module.nil?

route_from_engine_or_main_app(
alchemy_module['engine_name'],
url_options_for_navigation_entry(navigation)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/alchemy/admin/tags_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module TagsHelper
#
def render_tag_list(class_name)
raise ArgumentError, 'Please provide a String as class_name' if class_name.nil?

sorted_tags_from(class_name: class_name).map do |tag|
content_tag('li', name: tag.name, class: filtered_by_tag?(tag) ? 'active' : nil) do
link_to(
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/alchemy/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def page_or_find(page)
end
if page.blank?
warning("No Page found for #{page.inspect}")
return
nil
else
page
end
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def render_element(element, options = {}, counter = 1)
# Returns a string for the id attribute of a html element for the given element
def element_dom_id(element)
return "" if element.nil?

"#{element.name}_#{element.id}".html_safe
end

Expand All @@ -189,6 +190,7 @@ def element_preview_code(element)
# Returns a hash containing the HTML tag attributes required for preview mode.
def element_preview_code_attributes(element)
return {} unless element.present? && @preview_mode && element.page == @page

{ 'data-alchemy-element' => element.id }
end

Expand Down Expand Up @@ -226,6 +228,7 @@ def element_tags_attributes(element, options = {})
}.merge(options)

return {} if !element.taggable? || element.tag_list.blank?

{ 'data-element-tags' => options[:formatter].call(element.tag_list) }
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def language_links(options = {})
}.merge(options)
languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? 'DESC' : 'ASC'}")
return nil if languages.count < 2

render(
partial: "alchemy/language_links/language",
collection: languages,
Expand Down Expand Up @@ -152,6 +153,7 @@ def render_breadcrumb(options = {})
#
def page_title(options = {})
return "" if @page.title.blank?

options = {
prefix: "",
suffix: "",
Expand Down
1 change: 1 addition & 0 deletions app/helpers/alchemy/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def show_alchemy_page_url(page, optional_params = {})
# Returns the correct params-hash for passing to show_page_path
def show_page_path_params(page, optional_params = {})
raise ArgumentError, 'Page is nil' if page.nil?

url_params = {urlname: page.urlname}.update(optional_params)
prefix_locale? ? url_params.update(locale: page.language_code) : url_params
end
Expand Down
18 changes: 9 additions & 9 deletions app/models/alchemy/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ def extension
def icon_css_class
case file_mime_type
when "application/pdf"
then "file-pdf"
"file-pdf"
when "application/msword"
then "file-word"
"file-word"
when *TEXT_FILE_TYPES
then "file-alt"
"file-alt"
when *EXCEL_FILE_TYPES
then "file-excel"
"file-excel"
when *VCARD_FILE_TYPES
then "address-card"
"address-card"
when *ARCHIVE_FILE_TYPES
then "file-archive"
"file-archive"
when *AUDIO_FILE_TYPES
then "file-audio"
"file-audio"
when *IMAGE_FILE_TYPES
then "file-image"
"file-image"
when *VIDEO_FILE_TYPES
then "file-video"
"file-video"
else
"file"
end
Expand Down
1 change: 1 addition & 0 deletions app/models/alchemy/base_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Alchemy
def self.table_name_prefix
'alchemy_'
Expand Down
Loading