Skip to content

Commit

Permalink
Merge branch 'korobkov/active_scaffold-rubocop'
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed May 17, 2017
2 parents 960db32 + 0b27055 commit 7941882
Show file tree
Hide file tree
Showing 69 changed files with 211 additions and 217 deletions.
102 changes: 72 additions & 30 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-12-19 13:16:13 +0400 using RuboCop version 0.46.0.
# on 2017-05-17 17:42:33 +0400 using RuboCop version 0.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
Exclude:
- 'Gemfile'

# Offense count: 19
Lint/AmbiguousBlockAssociation:
Exclude:
- 'lib/active_scaffold/helpers/action_link_helpers.rb'
- 'lib/active_scaffold/helpers/search_column_helpers.rb'
- 'lib/active_scaffold/marked_model.rb'
- 'test/bridges/paperclip_test.rb'
- 'test/data_structures/action_columns_test.rb'
- 'test/data_structures/columns_test.rb'
- 'test/misc/configurable_test.rb'

# Offense count: 2
Lint/AmbiguousOperator:
Exclude:
Expand All @@ -21,8 +39,8 @@ Lint/AssignmentInCondition:

# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
# SupportedStyles: keyword, variable, start_of_line
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Lint/EndAlignment:
Exclude:
- 'lib/active_scaffold/actions/field_search.rb'
Expand All @@ -40,55 +58,61 @@ Lint/InheritException:
Exclude:
- 'lib/active_scaffold.rb'

# Offense count: 5
Lint/NestedMethodDefinition:
# Offense count: 1
Lint/NonLocalExitFromIterator:
Exclude:
- 'lib/active_scaffold/config/base.rb'
- 'test/extensions/active_record_test.rb'

# Offense count: 1
Lint/NonLocalExitFromIterator:
Lint/ShadowedException:
Exclude:
- 'lib/active_scaffold/config/base.rb'
- 'lib/active_scaffold/configurable.rb'

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'lib/active_scaffold/bridges/shared/date_bridge.rb'
- 'lib/active_scaffold/finder.rb'

# Offense count: 247
# Offense count: 256
Metrics/AbcSize:
Max: 133
Max: 125

# Offense count: 2
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 57

# Offense count: 22
# Offense count: 18
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 5

# Offense count: 96
# Offense count: 97
Metrics/CyclomaticComplexity:
Max: 27

# Offense count: 1783
# Offense count: 1853
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 994

# Offense count: 188
# Offense count: 193
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 78
Max: 65

# Offense count: 2
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6

# Offense count: 90
# Offense count: 91
Metrics/PerceivedComplexity:
Max: 31
Max: 29

# Offense count: 4
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: Whitelist.
# Whitelist: find_by_sql
Expand All @@ -98,10 +122,9 @@ Rails/DynamicFindBy:
- 'lib/active_scaffold/tableless.rb'
- 'test/data_structures/columns_test.rb'

# Offense count: 21
# Offense count: 19
Rails/OutputSafety:
Exclude:
- 'lib/active_scaffold/bridges/carrierwave/form_ui.rb'
- 'lib/active_scaffold/bridges/carrierwave/list_ui.rb'
- 'lib/active_scaffold/bridges/file_column/form_ui.rb'
- 'lib/active_scaffold/bridges/shared/date_bridge.rb'
Expand All @@ -113,6 +136,13 @@ Rails/OutputSafety:
- 'lib/active_scaffold/helpers/search_column_helpers.rb'
- 'test/helpers/list_column_helpers_test.rb'

# Offense count: 1
# Configuration parameters: Blacklist.
# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
Rails/SkipsModelValidations:
Exclude:
- 'lib/active_scaffold/attribute_params.rb'

# Offense count: 7
Style/AccessorMethodName:
Exclude:
Expand All @@ -136,7 +166,7 @@ Style/CaseEquality:
Exclude:
- 'lib/active_scaffold/core.rb'

# Offense count: 84
# Offense count: 85
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Expand All @@ -148,7 +178,7 @@ Style/ClassVars:

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
Expand All @@ -171,7 +201,23 @@ Style/EmptyCaseCondition:
Exclude:
- 'lib/active_scaffold/data_structures/column.rb'

# Offense count: 18
# Offense count: 3
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'test/mock_app/Rakefile'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'lib/active_scaffold/finder.rb'

# Offense count: 19
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
Expand Down Expand Up @@ -219,19 +265,16 @@ Style/MethodMissing:
- 'lib/active_scaffold/configurable.rb'
- 'lib/active_scaffold/data_structures/action_links.rb'

# Offense count: 11
# Offense count: 8
# Cop supports --auto-correct.
Style/ParallelAssignment:
Exclude:
- 'lib/active_scaffold/actions/list.rb'
- 'lib/active_scaffold/bridges/cancan/cancan_bridge.rb'
- 'lib/active_scaffold/delayed_setup.rb'
- 'lib/active_scaffold/helpers/form_column_helpers.rb'
- 'lib/active_scaffold/helpers/list_column_helpers.rb'
- 'lib/active_scaffold/helpers/view_helpers.rb'
- 'lib/active_scaffold/paginator.rb'
- 'test/bridges/bridge_test.rb'
- 'test/bridges/paperclip_test.rb'
- 'test/config/update_test.rb'

# Offense count: 8
Expand Down Expand Up @@ -263,7 +306,7 @@ Style/RegexpLiteral:
- 'lib/active_scaffold/extensions/action_view_rendering.rb'
- 'lib/active_scaffold/helpers/form_column_helpers.rb'

# Offense count: 13
# Offense count: 12
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
Expand All @@ -273,7 +316,6 @@ Style/RescueModifier:
- 'lib/active_scaffold/bridges/record_select/helpers.rb'
- 'lib/active_scaffold/config/core.rb'
- 'lib/active_scaffold/data_structures/association/active_record.rb'
- 'lib/active_scaffold/data_structures/column.rb'
- 'lib/active_scaffold/finder.rb'
- 'lib/active_scaffold/helpers/association_helpers.rb'

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rubocop (0.46.0)
parser (>= 2.3.1.1, < 3.0)
rubocop (0.48.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
Expand Down
1 change: 1 addition & 0 deletions active_scaffold.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-

$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'active_scaffold/version'

Expand Down
10 changes: 5 additions & 5 deletions lib/active_scaffold/actions/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def marked_records
end

def default_formats
[:html, :js, :json, :xml]
%i[html js json xml]
end

# Returns true if the client accepts one of the MIME types passed to it
Expand Down Expand Up @@ -235,11 +235,11 @@ def conditions_from_params
column = active_scaffold_config._columns_hash[key.to_s]
next unless column
key = key.to_sym
not_string = [:string, :text].exclude?(column.type)
not_string = %i[string text].exclude?(column.type)
next if active_scaffold_constraints[key]
next if nested? && nested.param_name == key

range = %i(date datetime).include?(column.type) && value.is_a?(String) && value.scan('..').size == 1
range = %i[date datetime].include?(column.type) && value.is_a?(String) && value.scan('..').size == 1
value = value.split('..') if range
conditions[key] =
if value.is_a?(Array)
Expand All @@ -258,7 +258,7 @@ def new_model
config = active_scaffold_config_for(relation.klass) if nested? && nested.plural_association?
if config && config._columns_hash[column = relation.klass.inheritance_column]
model_name = params.delete(column) # in new action inheritance_column must be in params
model_name ||= params[:record].delete(column) unless params[:record].blank? # in create action must be inside record key
model_name ||= params[:record].delete(column) if params[:record].present? # in create action must be inside record key
model_name = model_name.camelize if model_name
model_name ||= active_scaffold_config.model.name
build_options = {column.to_sym => model_name} if model_name
Expand Down Expand Up @@ -289,7 +289,7 @@ def active_scaffold_embedded_params

def clear_storage
session_index = active_scaffold_session_storage_key
session.delete(session_index) unless session[session_index].present?
session.delete(session_index) if session[session_index].blank?
end

# at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/actions/create.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveScaffold::Actions
module Create
def self.included(base)
base.before_action :create_authorized_filter, :only => [:new, :create]
base.before_action :create_authorized_filter, :only => %i[new create]
end

def new
Expand Down
4 changes: 2 additions & 2 deletions lib/active_scaffold/actions/field_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def list_columns
end

def grouped_columns
return unless active_scaffold_config.field_search.grouped_columns.present?
return if active_scaffold_config.field_search.grouped_columns.blank?
active_scaffold_config.field_search.grouped_columns.map do |col|
active_scaffold_config.columns[col]
end.compact
Expand Down Expand Up @@ -160,7 +160,7 @@ def do_search
active_scaffold_conditions << search_condition
filtered_columns << column
end
unless filtered_columns.blank?
if filtered_columns.present?
@filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true
end

Expand Down
8 changes: 4 additions & 4 deletions lib/active_scaffold/actions/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def row
end

def list
if %w(index list).include? action_name
if %w[index list].include? action_name
do_list
else
do_refresh_list
Expand Down Expand Up @@ -114,7 +114,7 @@ def do_list

options = {:sorting => active_scaffold_config.list.user.sorting,
:count_includes => active_scaffold_config.list.user.count_includes}
paginate = params[:format].nil? ? (accepts? :html, :js) : %w(html js).include?(params[:format])
paginate = params[:format].nil? ? (accepts? :html, :js) : %w[html js].include?(params[:format])
options[:pagination] = active_scaffold_config.list.pagination if paginate
if options[:pagination]
options[:per_page] = active_scaffold_config.list.user.per_page
Expand Down Expand Up @@ -172,7 +172,7 @@ def list_authorized?
end

def action_update_respond_to_js
do_refresh_list unless @record.present?
do_refresh_list if @record.blank?
super
end

Expand Down Expand Up @@ -200,7 +200,7 @@ def list_formats
alias index_formats list_formats

def row_formats
([:html, :js] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
(%i[html js] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
end

def action_update_formats
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/actions/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def do_search
text_search = active_scaffold_config.search.text_search
query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms
search_conditions = self.class.conditions_for_columns(query, columns, text_search)
@filtered = !search_conditions.blank?
@filtered = search_conditions.present?
active_scaffold_conditions.concat search_conditions if @filtered

references, outer_joins = columns.partition do |column|
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/actions/update.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveScaffold::Actions
module Update
def self.included(base)
base.before_action :update_authorized_filter, :only => [:edit, :update]
base.before_action :update_authorized_filter, :only => %i[edit update]
base.helper_method :update_refresh_list?
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/active_record_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module SecurityMethods
# options[:action] is the name of a method
# options[:reason] if returning reason is expected, it will return array with authorized and reason, or nil if no reason
def authorized_for?(options = {})
raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] && ![:create, :read, :update, :delete].include?(options[:crud_type])
raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] && !%i[create read update delete].include?(options[:crud_type])

not_authorized_reason = ActiveRecordPermissions.not_authorized_reason
# collect other possibly-related methods that actually exist
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/attribute_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def column_value_from_param_simple_value(parent_record, column, value)

def column_plural_assocation_value_from_value(column, value)
# it's an array of ids
if value && !value.empty?
if value.present?
ids = value.select(&:present?)
ids.empty? ? [] : column.association.klass.find(ids)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _load_action_columns
if model.respond_to?(:bitfields) && model.bitfields.present?
model.bitfields.each do |column_name, options|
columns = options.keys.sort_by { |column| self.columns[column].weight }
[:create, :update, :show, :subform].each do |action|
%i[create update show subform].each do |action|
next unless actions.include? action
if send(action).columns.include? column_name
send(action).columns.exclude column_name
Expand Down
Loading

0 comments on commit 7941882

Please sign in to comment.