8000 Merge pull request #154 from activeadmin/feature/rubocop · activeadmin/activeadmin-mongoid@71039f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71039f2

Browse files
Merge pull request #154 from activeadmin/feature/rubocop
Introduce rubocop
2 parents 119d9fc + cf8b73a commit 71039f2

40 files changed

+192
-106
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ spec/reports
2121
/test_app/.sass-cache
2222
/test_app/config/mongoid.yml
2323
/spec/rails
24+
.ruby-version

.rubocop.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
TargetRubyVersion: 2.4
4+
5+
DisplayCopNames: true
6+
7+
StyleGuideCopsOnly: false
8+
9+
Layout/EndAlignment:
10+
Enabled: true
11+
12+
Lint/ParenthesesAsGroupedExpression:
13+
Enabled: true
14+
15+
Layout/AccessModifierIndentation:
16+
Enabled: true
17+
18+
Layout/CaseIndentation:
19+
Enabled: true
20+
21+
Layout/CommentIndentation:
22+
Enabled: true
23+
24+
Layout/ElseAlignment:
25+
Enabled: true
26+
27+
Layout/EmptyLines:
28+
Enabled: true
29+
30+
Layout/EmptyLinesAroundBlockBody:
31+
Enabled: true
32+
33+
Layout/EndOfLine:
34+
Enabled: true
35+
36+
Layout/ExtraSpacing:
37+
Enabled: true
38+
39+
Style/Dir:
40+
Enabled: true
41+
42+
Style/Encoding:
43+
Enabled: true
44+
45+
Style/ExpandPathArguments:
46+
Enabled: true
47+
48+
Style/FrozenStringLiteralComment:
49+
Enabled: true
50+
EnforcedStyle: never
51+
52+
Style/HashSyntax:
53+
Enabled: true
54+
55+
Style/ParallelAssignment:
56+
Enabled: true
57+
58+
Layout/IndentationConsistency:
59+
Enabled: true
60+
61+
Layout/IndentationWidth:
62+
Enabled: true
63+
64+
Naming/PredicateName:
65+
Enabled: true
66+
67+
ForbiddenPrefixes:
68+
- is_
69+
- have_
70+
71+
AllowedMethods:
72+
- has_many
73+
- has_many_actions
74+
- is_association?
75+
76+
Style/TrailingCommaInArguments:
77+
Enabled: true
78+
79+
Layout/TrailingEmptyLines:
80+
Enabled: true
81+
82+
Layout/TrailingWhitespace:
83+
Enabled: true
84+
85+
Layout/SpaceAfterComma:
< F987 code>86+
Enabled: true
87+
88+
Layout/SpaceAroundEqualsInParameterDefault:
89+
Enabled: true
90+
91+
Layout/SpaceAroundOperators:
92+
Enabled: true
93+
94+
Layout/SpaceBeforeBlockBraces:
95+
Enabled: true
96+
97+
Layout/SpaceInsideBlockBraces:
98+
Enabled: true
99+
100+
Layout/SpaceInsideHashLiteralBraces:
101+
Enabled: true
102+
103+
Layout/SpaceInsideParens:
104+
Enabled: true

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ before_install:
55
- gem update --system
66
- gem install bundler
77
- bundle update --bundler
8+
after_script:
9+
- bundle exec rubocop
810
rvm:
911
- 2.4
1012
- 2.5

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ group :test do
2020
gem 'launchy'
2121
gem 'simplecov', require: false
2222
end
23+
24+
group :lint do
25+
gem 'rubocop', '0.80.0'
26+
end

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ GEM
7474
arbre (1.2.1)
7575
activesupport (>= 3.0.0)
7676
arel (9.0.0)
77+
ast (2.4.0)
7778
bcrypt (3.1.13)
7879
bson (4.7.1)
7980
builder (3.2.3)
@@ -114,6 +115,7 @@ GEM
114115
has_scope (~> 0.6)
115116
railties (>= 5.0, < 6.1)
116117
responders (>= 2, < 4)
118+
jaro_winkler (1.5.4)
117119
jquery-rails (4.3.3)
118120
rails-dom-testing (>= 1, < 3)
119121
railties (>= 4.2.0)
@@ -161,6 +163,9 @@ GEM
161163
nokogiri (1.10.5)
162164
mini_portile2 (~> 2.4.0)
163165
orm_adapter (0.5.0)
166+
parallel (1.19.1)
167+
parser (2.7.0.2)
168+
ast (~> 2.4.0)
164169
poltergeist (1.18.1)
165170
capybara (>= 2.1, < 4)
166171
cliver (~> 0.3.1)
@@ -200,6 +205,7 @@ GEM
200205
method_source
201206
rake (>= 0.8.7)
202207
thor (>= 0.19.0, < 2.0)
208+
rainbow (3.0.0)
203209
rake (12.3.3)
204210
ransack (2.3.2)
205211
activerecord (>= 5.2.1)
@@ -210,6 +216,7 @@ GEM
210216
responders (2.4.1)
211217
actionpack (>= 4.2.0, < 6.0)
212218
railties (>= 4.2.0, < 6.0)
219+
rexml (3.2.4)
213220
rspec-core (3.8.0)
214221
rspec-support (~> 3.8.0)
215222
rspec-expectations (3.8.2)
@@ -227,6 +234,15 @@ GEM
227234
rspec-mocks (~> 3.8.0)
228235
rspec-support (~> 3.8.0)
229236
rspec-support (3.8.0)
237+
rubocop (0.80.0)
238+
jaro_winkler (~> 1.5.1)
239+
parallel (~> 1.10)
240+
parser (>= 2.7.0.1)
241+
rainbow (>= 2.2.2, < 4.0)
242+
rexml
243+
ruby-progressbar (~> 1.7)
244+
unicode-display_width (>= 1.4.0, < 1.7)
245+
ruby-progressbar (1.10.1)
230246
sass-rails (6.0.0)
231247
sassc-rails (~> 2.1, >= 2.1.1)
232248
sassc (2.2.1)
@@ -254,6 +270,7 @@ GEM
254270
tilt (2.0.10)
255271
tzinfo (1.2.5)
256272
thread_safe (~> 0.1)
273+
unicode-display_width (1.6.1)
257274
warden (1.2.8)
258275
rack (>= 2.0.6)
259276
websocket-driver (0.7.0)
@@ -278,6 +295,7 @@ DEPENDENCIES
278295
rails (>= 5.2, < 6.1)
279296
ransack-mongoid!
280297
rspec-rails (~> 3.6)
298+
rubocop (= 0.80.0)
281299
simplecov
282300

283301
BUNDLED WITH

activeadmin-mongoid.gemspec

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
43
require 'active_admin/mongoid/version'
54

@@ -10,7 +9,7 @@ Gem::Specification.new do |gem|
109
gem.summary = 10000 %q{ActiveAdmin hacks to support Mongoid}
1110
gem.homepage = ''
1211

13-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
1413
gem.files = `git ls-files`.split("\n")
1514
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
1615
gem.name = 'activeadmin-mongoid'
@@ -24,7 +23,7 @@ Gem::Specification.new do |gem|
2423
gem.add_runtime_dependency 'activeadmin', '>= 1.4.3'
2524
gem.add_runtime_dependency 'kaminari-mongoid'
2625
gem.add_runtime_dependency 'jquery-rails'
27-
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4']
26+
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4']
2827

29-
gem.add_development_dependency 'rspec-rails', '~> 3.6'
28+
gem.add_development_dependency 'rspec-rails', '~> 3.6'
3029
end

lib/active_admin/mongoid/association/relatable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def foreign_key
1111
return if embeds?
1212
foreign_key.to_sym rescue nil
1313
end
14-
end
14+
end

lib/active_admin/mongoid/controllers/resource_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'active_admin/engine'
22

33
ActiveAdmin::Engine.module_eval do
4-
54
initializer 'active_admin.mongoid.resource_controller' do
65
class ActiveAdmin::ResourceController
76
def build_new_resource

lib/active_admin/mongoid/criteria.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ def from(*a)
1919
end
2020
end
2121
end
22-

lib/active_admin/mongoid/csv_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def build(controller, csv)
1111
csv << bom if bom
1212

1313
if column_names
14-
csv << CSV.generate_line(columns.map{ |c| encode c.name, options }, csv_options)
14+
csv << CSV.generate_line(columns.map { |c| encode c.name, options }, csv_options)
1515
end
1616

1717
(1..paginated_collection.total_pages).each do |page|

lib/active_admin/mongoid/document.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
module ActiveAdmin::Mongoid::Document
44
extend ActiveSupport::Concern
55

6-
7-
8-
96
# PROXY CLASSES
107

118
class ColumnWrapper < SimpleDelegator
@@ -30,9 +27,6 @@ def quote_column_name name
3027
end
3128
end
3229

33-
34-
35-
3630
# CLASS METHODS
3731

3832
included do
@@ -47,7 +41,6 @@ class << self
4741
def column_for_attribute(name)
4842
self.class.fields[name.to_sym]
4943
end
50-
5144
end
5245

5346
module ClassMethods
@@ -63,7 +56,7 @@ def connection
6356
end
6457

6558
def find_by_id id
66-
find_by(:_id => id)
59+
find_by(_id: id)
6760
end
6861

6962
def quoted_table_name
@@ -74,7 +67,6 @@ def associations
7467
@associations ||= new.associations
7568
end
7669

77-
7870
def reflections *a
7971
relations *a
8072
end

lib/active_admin/mongoid/filter_form_builder.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def filter(method, options = {})
99
def default_input_type(method, options = {})
1010
if column = column_for(method)
1111
case column.type.name.downcase.to_sym
12-
when :date, :datetime, :time; :date_range
13-
when :string, :text, :object; :string
14-
when :float, :decimal; :numeric
12+
when :date, :datetime, :time; :date_range
13+
when :string, :text, :object; :string
14+
when :float, :decimal; :numeric
1515
when :integer
16-
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
16+
return :select if reflection_for(method.to_s.gsub('_id', '').to_sym)
1717
return :numeric
1818
end
1919
elsif is_association?(method)

lib/active_admin/mongoid/filters/resource_extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ActiveAdmin::Filters::ResourceExtension
44
def default_association_filters
55
if resource_class.respond_to?(:reflect_on_all_associations)
66
without_embedded = resource_class.reflect_on_all_associations.reject { |e| e.embeds? }
7-
poly, not_poly = without_embedded.partition{ |r| r.macro == :belongs_to && r.options[:polymorphic] }
7+
poly, not_poly = without_embedded.partition { |r| r.macro == :belongs_to && r.options[:polymorphic] }
88

99
filters = poly.map(&:foreign_key) + not_poly.map(&:name)
1010
filters.map &:to_sym

lib/active_admin/mongoid/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Resource
66
# another. I'm not going to investigate any deeper, let's just remove the
77
# underscore prefixed fields as was the prior behavior
88
def default_filters
9-
super.reject { |filter| filter == :_id }
9+
super.reject { |filter| filter == :_id }
1010
end
1111

1212
module Attributes

lib/active_admin/mongoid/resource/attributes.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Resource
66
module Attributes
77
def foreign_methods
88
@foreign_methods ||= resource_class.reflect_on_all_associations.
9-
select{ |r| r.macro == :belongs_to }.
10-
index_by{ |r| r.foreign_key.to_sym }
9+
select { |r| r.macro == :belongs_to }.
10+
index_by { |r| r.foreign_key.to_sym }
1111
end
1212

1313
def primary_col?(c)
@@ -20,4 +20,3 @@ def sti_col?(c)
2020
end
2121
end
2222
end
23-

lib/meta_search/searches/mongoid.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class MongoidSearchBuilder < SimpleDelegator
1010
def initialize relation, params, options
1111
super(relation)
1212
@relation = relation
13-
@params, @options = params, options
13+
@params = params
14+
@options = options
1415
end
1516

1617
def build
@@ -78,7 +79,6 @@ def method_missing name, *attrs, &block
7879
relation.send(name, *attrs, &block)
7980
end
8081

81-
8282
def respond_to? name, include_private = false
8383
name.to_s =~ metasearch_regexp or super
8484
end
@@ -92,8 +92,8 @@ def method_missing name, *args, &block
9292
end
9393

9494
def metasearch_regexp
95-
field_names = klass.fields.map{ |field| field.second.name }
96-
conditions = MetaSearch::DEFAULT_WHERES.map {|condition| condition[0...-1]} # pop tail options
95+
field_names = klass.fields.map { |field| field.second.name }
96+
conditions = MetaSearch::DEFAULT_WHERES.map { |condition| condition[0...-1] } # pop tail options
9797

9898
/\A(#{field_names.join('|')})_(#{conditions.join('|')})\z/
9999
end

0 commit comments

Comments
 (0)
0