Skip to content

Commit

Permalink
Enable RuboCop Style/HashSyntax (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarroll32 authored Nov 9, 2022
1 parent ade89a0 commit 2269d26
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Layout/SpaceInsideParens:
Layout/TrailingEmptyLines:
Enabled: true

Style/HashSyntax:
Enabled: true

Style/RedundantFileExtensionInRequire:
Enabled: true

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ when /\// # A path
gem 'actionpack', path: "#{rails}/actionpack"
gem 'actionview', path: "#{rails}/actionview"
when /^v/ # A tagged version
git 'https://github.com/rails/rails.git', :tag => rails do
git 'https://github.com/rails/rails.git', tag: rails do
gem 'activesupport'
gem 'activemodel'
gem 'activerecord', require: false
gem 'actionpack'
end
else
git 'https://github.com/rails/rails.git', :branch => rails do
git 'https://github.com/rails/rails.git', branch: rails do
gem 'activesupport'
gem 'activemodel'
gem 'activerecord', require: false
Expand All @@ -47,7 +47,7 @@ gem 'mysql2'
group :test do
gem 'machinist', '~> 1.0.6'
gem 'rspec'
gem 'simplecov', :require => false
gem 'simplecov', require: false
end

gem 'rubocop', require: false
2 changes: 1 addition & 1 deletion lib/ransack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UntraversableAssociationError < StandardError; end

Ransack.configure do |config|
Ransack::Constants::AREL_PREDICATES.each do |name|
config.add_predicate name, :arel_predicate => name
config.add_predicate name, arel_predicate: name
end
Ransack::Constants::DERIVED_PREDICATES.each do |args|
config.add_predicate(*args)
Expand Down
24 changes: 12 additions & 12 deletions lib/ransack/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def []=(key, value)
self.predicates = PredicateCollection.new

self.options = {
:search_key => :q,
:ignore_unknown_conditions => true,
:hide_sort_order_indicators => false,
:up_arrow => '&#9660;'.freeze,
:down_arrow => '&#9650;'.freeze,
:default_arrow => nil,
:sanitize_scope_args => true,
:postgres_fields_sort_option => nil,
:strip_whitespace => true
search_key: :q,
ignore_unknown_conditions: true,
hide_sort_order_indicators: false,
up_arrow: '&#9660;'.freeze,
down_arrow: '&#9650;'.freeze,
default_arrow: nil,
sanitize_scope_args: true,
postgres_fields_sort_option: nil,
strip_whitespace: true
}

def configure
Expand All @@ -55,11 +55,11 @@ def add_predicate(name, opts = {})
compound_name = name + suffix
self.predicates[compound_name] = Predicate.new(
opts.merge(
:name => compound_name,
:arel_predicate => arel_predicate_with_suffix(
name: compound_name,
arel_predicate: arel_predicate_with_suffix(
opts[:arel_predicate], suffix
),
:compound => true
compound: true
)
)
end if compounds
Expand Down
6 changes: 3 additions & 3 deletions lib/ransack/helpers/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def label(method, *args, &block)
text = args.first
i18n = options[:i18n] || {}
text ||= object.translate(
method, i18n.reverse_merge(:include_associations => true)
method, i18n.reverse_merge(include_associations: true)
) if object.respond_to? :translate
super(method, text, options, &block)
end
Expand Down Expand Up @@ -240,7 +240,7 @@ def attribute_collection_for_bases(action, bases)
def get_attribute_element(action, base)
begin
[
Translate.association(base, :context => object.context),
Translate.association(base, context: object.context),
collection_for_base(action, base)
]
rescue UntraversableAssociationError
Expand All @@ -253,7 +253,7 @@ def attribute_collection_for_base(attributes, base = nil)
[
attr_from_base_and_column(base, c),
Translate.attribute(
attr_from_base_and_column(base, c), :context => object.context
attr_from_base_and_column(base, c), context: object.context
)
]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ransack/nodes/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Attribute < Node

attr_reader :name, :ransacker_args

delegate :blank?, :present?, :to => :name
delegate :engine, :to => :context
delegate :blank?, :present?, to: :name
delegate :engine, to: :context

def initialize(context, name = nil, ransacker_args = [])
super(context)
Expand Down
12 changes: 6 additions & 6 deletions lib/ransack/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Ransack
module Nodes
class Condition < Node
i18n_word :attribute, :predicate, :combinator, :value
i18n_alias :a => :attribute, :p => :predicate,
:m => :combinator, :v => :value
i18n_alias a: :attribute, p: :predicate,
m: :combinator, v: :value

attr_accessor :predicate

Expand All @@ -15,10 +15,10 @@ def extract(context, key, values)
if attributes.size > 0 && predicate
condition = self.new(context)
condition.build(
:a => attributes,
:p => predicate.name,
:m => combinator,
:v => predicate.wants_array ? Array(values) : [values]
a: attributes,
p: predicate.name,
m: combinator,
v: predicate.wants_array ? Array(values) : [values]
)
# TODO: Figure out what to do with multiple types of attributes,
# if anything. Tempted to go with "garbage in, garbage out" here.
Expand Down
6 changes: 3 additions & 3 deletions lib/ransack/nodes/grouping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Grouping < Node
alias :m= :combinator=

i18n_word :condition, :and, :or
i18n_alias :c => :condition, :n => :and, :o => :or
i18n_alias c: :condition, n: :and, o: :or

delegate :each, :to => :values
delegate :each, to: :values

def initialize(context, combinator = nil)
super(context)
Expand All @@ -22,7 +22,7 @@ def persisted?

def translate(key, options = {})
super or Translate.attribute(
key.to_s, options.merge(:context => context)
key.to_s, options.merge(context: context)
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/nodes/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Ransack
module Nodes
class Node
attr_reader :context
delegate :contextualize, :to => :context
delegate :contextualize, to: :context
class_attribute :i18n_words
class_attribute :i18n_aliases
self.i18n_words = []
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/nodes/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Ransack
module Nodes
class Value < Node
attr_accessor :value
delegate :present?, :blank?, :to => :value
delegate :present?, :blank?, to: :value

def initialize(context, value = nil)
super(context)
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/ransacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Ransacker

attr_reader :name, :type, :formatter, :args

delegate :call, :to => :@callable
delegate :call, to: :@callable

def initialize(klass, name, opts = {}, &block)
@klass, @name = klass, name
Expand Down
4 changes: 2 additions & 2 deletions lib/ransack/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Search

attr_reader :base, :context

delegate :object, :klass, :to => :context
delegate :object, :klass, to: :context
delegate :new_grouping, :new_condition,
:build_grouping, :build_condition,
:translate, :to => :base
:translate, to: :base

def initialize(object, params = {}, options = {})
strip_whitespace = options.fetch(:strip_whitespace, Ransack.options[:strip_whitespace])
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/translate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def association(key, options = {})
[:"ransack.associations.#{i18n_key(context.klass)}.#{key}"]
end
defaults << context.traverse(key).model_name.human
options = { :count => 1, :default => defaults }
options = { count: 1, default: defaults }
I18n.translate(defaults.shift, **options)
end

Expand Down
18 changes: 9 additions & 9 deletions spec/ransack/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Ransack
Ransack.configure do |config|
config.add_predicate(
:test_predicate_without_compound,
:compounds => false
compounds: false
)
end
expect(Ransack.predicates)
Expand Down Expand Up @@ -138,8 +138,8 @@ module Ransack
Ransack.configure do |config|
config.add_predicate(
:test_array_predicate,
:wants_array => true,
:compounds => true
wants_array: true,
compounds: true
)
end

Expand All @@ -153,11 +153,11 @@ module Ransack
Ransack.configure do |config|
config.add_predicate(
:test_in_predicate,
:arel_predicate => 'in'
arel_predicate: 'in'
)
config.add_predicate(
:test_not_in_predicate,
:arel_predicate => 'not_in'
arel_predicate: 'not_in'
)
end

Expand All @@ -171,13 +171,13 @@ module Ransack
Ransack.configure do |config|
config.add_predicate(
:test_in_predicate_no_array,
:arel_predicate => 'in',
:wants_array => false
arel_predicate: 'in',
wants_array: false
)
config.add_predicate(
:test_not_in_predicate_no_array,
:arel_predicate => 'not_in',
:wants_array => false
arel_predicate: 'not_in',
wants_array: false
)
end

Expand Down
16 changes: 8 additions & 8 deletions spec/ransack/helpers/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Helpers
# @s.created_at_eq = date_values # This works in Rails 4.x but not 3.x
@s.created_at_eq = [2011, 1, 2, 3, 4, 5] # so we have to do this
html = @f.datetime_select(
:created_at_eq, :use_month_numbers => true, :include_seconds => true
:created_at_eq, use_month_numbers: true, include_seconds: true
)
date_values.each { |val| expect(html).to include date_select_html(val) }
end
Expand Down Expand Up @@ -70,13 +70,13 @@ module Helpers

describe '#sort_link' do
it 'sort_link for ransack attribute' do
sort_link = @f.sort_link :name, :controller => 'people'
sort_link = @f.sort_link :name, controller: 'people'
expect(sort_link).to match /people\?q(%5B|\[)s(%5D|\])=name\+asc/
expect(sort_link).to match /sort_link/
expect(sort_link).to match /Full Name<\/a>/
end
it 'sort_link for common attribute' do
sort_link = @f.sort_link :id, :controller => 'people'
sort_link = @f.sort_link :id, controller: 'people'
expect(sort_link).to match /id<\/a>/
end
end
Expand All @@ -99,14 +99,14 @@ module Helpers
it 'returns ransackable attributes for associations with :associations' do
attributes = Person.ransackable_attributes +
Article.ransackable_attributes.map { |a| "articles_#{a}" }
html = @f.attribute_select(:associations => ['articles'])
html = @f.attribute_select(associations: ['articles'])
expect(html.split(/\n/).size).to eq(attributes.size)
attributes.each do |attribute|
expect(html).to match /<option value="#{attribute}">/
end
end
it 'returns option groups for base and associations with :associations' do
html = @f.attribute_select(:associations => ['articles'])
html = @f.attribute_select(associations: ['articles'])
[Person, Article].each do |model|
expect(html).to match /<optgroup label="#{model}">/
end
Expand All @@ -121,19 +121,19 @@ module Helpers
end
end
it 'filters predicates with single-value :only' do
html = @f.predicate_select :only => 'eq'
html = @f.predicate_select only: 'eq'
Predicate.names.reject { |k| k =~ /^eq/ }.each do |key|
expect(html).not_to match /<option value="#{key}">/
end
end
it 'filters predicates with multi-value :only' do
html = @f.predicate_select :only => [:eq, :lt]
html = @f.predicate_select only: [:eq, :lt]
Predicate.names.reject { |k| k =~ /^(eq|lt)/ }.each do |key|
expect(html).not_to match /<option value="#{key}">/
end
end
it 'excludes compounds when compounds: false' do
html = @f.predicate_select :compounds => false
html = @f.predicate_select compounds: false
Predicate.names.select { |k| k =~ /_(any|all)$/ }.each do |key|
expect(html).not_to match /<option value="#{key}">/
end
Expand Down
4 changes: 2 additions & 2 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ module Helpers
describe 'with symbol q:, #sort_link should include search params' do
subject { @controller.view_context.sort_link(Person.ransack, :name) }
let(:params) { ActionController::Parameters.new(
{ :q => { name_eq: 'TEST' }, controller: 'people' }
{ q: { name_eq: 'TEST' }, controller: 'people' }
) }
before { @controller.instance_variable_set(:@params, params) }

Expand All @@ -489,7 +489,7 @@ module Helpers
describe 'with symbol q:, #sort_url should include search params' do
subject { @controller.view_context.sort_url(Person.ransack, :name) }
let(:params) { ActionController::Parameters.new(
{ :q => { name_eq: 'TEST' }, controller: 'people' }
{ q: { name_eq: 'TEST' }, controller: 'people' }
) }
before { @controller.instance_variable_set(:@params, params) }

Expand Down
2 changes: 1 addition & 1 deletion spec/ransack/translate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Ransack
ar_translation = ::Namespace::Article.human_attribute_name(:title)
ransack_translation = Ransack::Translate.attribute(
:title,
:context => ::Namespace::Article.ransack.context
context: ::Namespace::Article.ransack.context
)
expect(ransack_translation).to eq ar_translation
end
Expand Down

0 comments on commit 2269d26

Please sign in to comment.