Skip to content

Commit

Permalink
Merge pull request #1185 from yahonda/rubocop_init
Browse files Browse the repository at this point in the history
Enable RuboCop and configure GitHub Actions to run RuboCop
  • Loading branch information
scarroll32 authored Dec 23, 2020
2 parents 1aa1dda + e083efd commit bdaac5c
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 47 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: rubocop

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.2
- name: Install gems
run: bundle install --jobs 4 --retry 3
- name: Run RuboCop
run: bundle exec rubocop --parallel
42 changes: 42 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
AllCops:
# TargetRubyVersion value is based on `required_ruby_version = '>= 2.3'` in the ransack.gemspec
TargetRubyVersion: 2.3

DisabledByDefault: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

Layout/EmptyLineBetweenDefs:
Enabled: true

Layout/EmptyLines:
Enabled: true

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceInsideBlockBraces:
Enabled: true

Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

Layout/TrailingEmptyLines:
Enabled: true

Style/RedundantReturn:
Enabled: true

Style/SelfAssignment:
Enabled: true

Style/Semicolon:
Enabled: true

5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ group :test do
gem 'rspec', '~> 3'
gem 'simplecov', :require => false
end

# RuboCop 0.81.0 is the last version which supports Ruby 2.3.
# Once Ransack required_ruby_version is bumped, RuboCop version can be bumped.
# https://github.com/rubocop-hq/rubocop/pull/7869
gem 'rubocop', '=0.81.0', require: false
2 changes: 1 addition & 1 deletion lib/polyamorous/polyamorous.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Polyamorous
require 'polyamorous/join'
require 'polyamorous/swapping_reflection_class'

ar_version = ::ActiveRecord::VERSION::STRING[0,3]
ar_version = ::ActiveRecord::VERSION::STRING[0, 3]
%w(join_association join_dependency reflection).each do |file|
require "polyamorous/activerecord_#{ar_version}_ruby_2/#{file}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module Ransack
extend Configuration
class UntraversableAssociationError < StandardError; end;
class UntraversableAssociationError < StandardError; end
end

Ransack.configure do |config|
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/adapters/active_record/ransack/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module Constants
arel_predicate: proc { |v| v ? EQ : NOT_EQ },
compounds: false,
type: :boolean,
validator: proc { |v| BOOLEAN_VALUES.include?(v)},
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
formatter: proc { |v| nil }
}
],
Expand Down
3 changes: 1 addition & 2 deletions lib/ransack/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Constants
'lt'.freeze, 'lteq'.freeze,
'gt'.freeze, 'gteq'.freeze,
'in'.freeze, 'not_in'.freeze
].freeze
].freeze
A_S_I = ['a'.freeze, 's'.freeze, 'i'.freeze].freeze

EQ = 'eq'.freeze
Expand All @@ -52,4 +52,3 @@ module Constants
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
end
end

2 changes: 1 addition & 1 deletion lib/ransack/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'ransack/helpers/form_builder'
require 'ransack/helpers/form_helper'
require 'ransack/helpers/form_helper'
6 changes: 3 additions & 3 deletions lib/ransack/helpers/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def submit(value = nil, options = {})
end

def attribute_select(options = nil, html_options = nil, action = nil)
options = options || {}
html_options = html_options || {}
action = action || Constants::SEARCH
options ||= {}
html_options ||= {}
action ||= Constants::SEARCH
default = options.delete(:default)
raise ArgumentError, formbuilder_error_message(
"#{action}_select") unless object.respond_to?(:context)
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/nodes/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def associated_collection?

def type
if ransacker
return ransacker.type
ransacker.type
else
context.type_for(self)
end
Expand Down
2 changes: 0 additions & 2 deletions lib/ransack/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def combinator=(val)
alias :m= :combinator=
alias :m :combinator


# == build_attribute
#
# This method was originally called from Nodes::Grouping#new_condition
Expand Down Expand Up @@ -263,7 +262,6 @@ def attr_value_for_attribute(attr)
attr.attr
end


def default_type
predicate.type || (attributes.first && attributes.first.type)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/nodes/sort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Sort < Node
class << self
def extract(context, str)
return unless str
attr, direction = str.split(/\s+/,2)
attr, direction = str.split(/\s+/, 2)
self.new(context).build(name: attr, dir: direction)
end
end
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 @@ -50,7 +50,7 @@ def cast_to_date(val)
y, m, d = *[val].flatten
m ||= 1
d ||= 1
Date.new(y,m,d) rescue nil
Date.new(y, m, d) rescue nil
end
end

Expand Down
5 changes: 3 additions & 2 deletions ransack.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- encoding: utf-8 -*-

$:.push File.expand_path("../lib", __FILE__)
require "ransack/version"

Gem::Specification.new do |s|
s.name = "ransack"
s.version = Ransack::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack","Sean Carroll"]
s.email = ["[email protected]", "[email protected]", "[email protected]","[email protected]"]
s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack", "Sean Carroll"]
s.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
s.homepage = "https://github.com/activerecord-hackery/ransack"
s.summary = %q{Object-based searching for Active Record and Mongoid (currently).}
s.description = %q{Ransack is the successor to the MetaSearch gem. It improves and expands upon MetaSearch's functionality, but does not have a 100%-compatible API.}
Expand Down
2 changes: 1 addition & 1 deletion spec/blueprints/articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
person
title
body
end
end
2 changes: 1 addition & 1 deletion spec/blueprints/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
article
person
body
end
end
2 changes: 1 addition & 1 deletion spec/blueprints/notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
note
notable_type { "Article" }
notable_id
end
end
2 changes: 1 addition & 1 deletion spec/blueprints/tags.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Tag.blueprint do
name { Sham.tag_name }
end
end
2 changes: 1 addition & 1 deletion spec/helpers/ransack_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def quote_table_name(table)
def quote_column_name(column)
ActiveRecord::Base.connection.quote_column_name(column)
end
end
end
5 changes: 2 additions & 3 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ def self.simple_escaping?
Comment.create(article: Article.create(title: 'Avenger'), person: Person.create(salary: 100_000)),
Comment.create(article: Article.create(title: 'Avenge'), person: Person.create(salary: 50_000)),
]
expect(Comment.ransack(article_title_cont: 'aven',s: 'person_salary desc').result).to eq(comments)
expect(Comment.ransack(article_title_cont: 'aven', s: 'person_salary desc').result).to eq(comments)
expect(Comment.joins(:person).ransack(s: 'persons_salarydesc', article_title_cont: 'aven').result).to eq(comments)
expect(Comment.joins(:person).ransack(article_title_cont: 'aven',s: 'persons_salary desc').result).to eq(comments)
expect(Comment.joins(:person).ransack(article_title_cont: 'aven', s: 'persons_salary desc').result).to eq(comments)
end

it 'allows sort by `only_sort` field' do
Expand Down Expand Up @@ -545,7 +545,6 @@ def self.simple_escaping?
)
end


it 'should allow passing ransacker arguments to a ransacker' do
s = Person.ransack(
c: [{
Expand Down
3 changes: 1 addition & 2 deletions spec/ransack/adapters/active_record/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module ActiveRecord
describe Context do
subject { Context.new(Person) }


it 'has an Active Record alias tracker method' do
expect(subject.alias_tracker)
.to be_an ::ActiveRecord::Associations::AliasTracker
Expand Down Expand Up @@ -81,7 +80,7 @@ module ActiveRecord
end

it 'build correlated subquery for multiple conditions (default scope)' do
search = Search.new(Person, { comments_body_not_eq: 'some_title'})
search = Search.new(Person, { comments_body_not_eq: 'some_title' })

# Was
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
Expand Down
Loading

0 comments on commit bdaac5c

Please sign in to comment.