Skip to content

Commit 37730c3

Browse files
committed
bug fix & improvements
1 parent 4f4572e commit 37730c3

15 files changed

+193
-77
lines changed

.rubocop.yml

+117-40
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
require: rubocop-performance
22

3-
inherit_gem:
4-
rubocop-rails_config:
5-
- config/rails.yml
6-
73
AllCops:
84
TargetRubyVersion: 2.5
95
Exclude:
106
- bin/**/*
117
- test/dummy/bin/**/*
128
- test/dummy/db/schema.rb
139

10+
Performance:
11+
Exclude:
12+
- 'test/**/*'
13+
14+
Rails:
15+
Enabled: true
16+
1417
Metrics/LineLength:
1518
Max: 150
1619

17-
# frozen_string_literal: true
18-
Style/FrozenStringLiteralComment:
19-
Enabled: true
20-
EnforcedStyle: when_needed
20+
Style/GuardClause:
21+
Enabled: false
22+
23+
Style/Documentation:
24+
Enabled: false
25+
26+
# Prefer assert_not over assert !
27+
Rails/AssertNot:
28+
Include:
29+
- 'test/**/*'
30+
31+
# Prefer assert_not_x over refute_x
32+
Rails/RefuteMethods:
33+
Include:
34+
- 'test/**/*'
2135

2236
# Prefer &&/|| over and/or.
2337
Style/AndOr:
@@ -27,6 +41,7 @@ Style/AndOr:
2741
# method call.
2842
Style/BracesAroundHashParameters:
2943
Enabled: true
44+
EnforcedStyle: context_dependent
3045

3146
# Align `when` with `case`.
3247
Layout/CaseIndentation:
@@ -36,8 +51,20 @@ Layout/CaseIndentation:
3651
Layout/CommentIndentation:
3752
Enabled: true
3853

39-
# No extra empty lines.
40-
Layout/EmptyLines:
54+
Layout/ElseAlignment:
55+
Enabled: true
56+
57+
# Align `end` with the matching keyword or starting expression except for
58+
# assignments, where it should be aligned with the LHS.
59+
Layout/EndAlignment:
60+
Enabled: true
61+
EnforcedStyleAlignWith: variable
62+
AutoCorrect: true
63+
64+
Layout/EmptyLineAfterMagicComment:
65+
Enabled: true
66+
67+
Layout/EmptyLinesAroundBlockBody:
4168
Enabled: true
4269

4370
# In a regular class definition, no empty lines around the body.
@@ -52,26 +79,35 @@ Layout/EmptyLinesAroundMethodBody:
5279
Layout/EmptyLinesAroundModuleBody:
5380
Enabled: true
5481

55-
# Use Ruby >= 1.9 syntax for hashes. Prefer {a: :b} over { :a => :b }.
82+
Layout/IndentFirstArgument:
83+
Enabled: true
84+
85+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
5686
Style/HashSyntax:
5787
Enabled: true
5888

5989
# Method definitions after `private` or `protected` isolated calls need one
6090
# extra level of indentation.
6191
Layout/IndentationConsistency:
6292
Enabled: true
63-
EnforcedStyle: normal
93+
EnforcedStyle: rails
6494

6595
# Two spaces, no tabs (for indentation).
6696
Layout/IndentationWidth:
6797
Enabled: true
6898

99+
Layout/LeadingCommentSpace:
100+
Enabled: true
101+
69102
Layout/SpaceAfterColon:
70103
Enabled: true
71104

72105
Layout/SpaceAfterComma:
73106
Enabled: true
74107

108+
Layout/SpaceAfterSemicolon:
109+
Enabled: true
110+
75111
Layout/SpaceAroundEqualsInParameterDefault:
76112
Enabled: true
77113

@@ -81,24 +117,38 @@ Layout/SpaceAroundKeyword:
81117
Layout/SpaceAroundOperators:
82118
Enabled: true
83119

120+
Layout/SpaceBeforeComma:
121+
Enabled: true
122+
84123
Layout/SpaceBeforeFirstArg:
85124
Enabled: true
86125

126+
Style/DefWithParentheses:
127+
Enabled: true
128+
87129
# Defining a method with parameters needs parentheses.
88130
Style/MethodDefParentheses:
89131
Enabled: true
90132

133+
Style/FrozenStringLiteralComment:
134+
Enabled: true
135+
EnforcedStyle: always
136+
137+
Style/RedundantFreeze:
138+
Enabled: true
139+
91140
# Use `foo {}` not `foo{}`.
92141
Layout/SpaceBeforeBlockBraces:
93142
Enabled: true
94143

95144
# Use `foo { bar }` not `foo {bar}`.
96145
Layout/SpaceInsideBlockBraces:
97146
Enabled: true
147+
EnforcedStyleForEmptyBraces: space
98148

99-
# Use `{a: 1}` not `{ a:1 }`.
149+
# Use `{ a: 1 }` not `{a:1}`.
100150
Layout/SpaceInsideHashLiteralBraces:
101-
Enabled: false
151+
Enabled: true
102152

103153
Layout/SpaceInsideParens:
104154
Enabled: true
@@ -124,45 +174,72 @@ Layout/TrailingWhitespace:
124174
Style/UnneededPercentQ:
125175
Enabled: true
126176

127-
# Align `end` with the matching keyword or starting expression except for
128-
# assignments, where it should be aligned with the LHS.
129-
Layout/EndAlignment:
177+
Lint/AmbiguousOperator:
178+
Enabled: true
179+
180+
Lint/AmbiguousRegexpLiteral:
181+
Enabled: true
182+
183+
Lint/ErbNewArguments:
130184
Enabled: true
131-
EnforcedStyleAlignWith: variable
132185

133186
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
134187
Lint/RequireParentheses:
135188
Enabled: true
136189

137-
Style/Documentation:
138-
Enabled: false
190+
Lint/ShadowingOuterLocalVariable:
191+
Enabled: true
139192

140-
Metrics/MethodLength:
141-
Enabled: false
193+
Lint/StringConversionInInterpolation:
194+
Enabled: true
142195

143-
Metrics/AbcSize:
144-
Enabled: false
196+
Lint/UriEscapeUnescape:
197+
Enabled: true
145198

146-
Metrics/ParameterLists:
147-
Enabled: false
199+
Lint/UselessAssignment:
200+
Enabled: true
148201

149-
Metrics/BlockLength:
150-
Enabled: false
202+
Lint/DeprecatedClassMethods:
203+
Enabled: true
151204

152-
Lint/HandleExceptions:
153-
Enabled: false
205+
Style/ParenthesesAroundCondition:
206+
Enabled: true
154207

155-
Metrics/ClassLength:
156-
Enabled: false
208+
Style/RedundantBegin:
209+
Enabled: true
157210

158-
Layout/EmptyLinesAroundArguments:
159-
Enabled: false
211+
Style/RedundantReturn:
212+
Enabled: true
213+
AllowMultipleReturnValues: true
160214

161-
Style/ClassAndModuleChildren:
162-
Enabled: false
215+
Style/Semicolon:
216+
Enabled: true
217+
AllowAsExpressionSeparator: true
163218

164-
Naming/UncommunicativeMethodParamName:
165-
Enabled: false
219+
# Prefer Foo.method over Foo::method
220+
Style/ColonMethodCall:
221+
Enabled: true
166222

167-
Style/IfUnlessModifier:
168-
Enabled: false
223+
Style/TrivialAccessors:
224+
Enabled: true
225+
226+
Performance/FlatMap:
227+
Enabled: true
228+
229+
Performance/RedundantMerge:
230+
Enabled: true
231+
232+
Performance/StartWith:
233+
Enabled: true
234+
235+
Performance/EndWith:
236+
Enabled: true
237+
238+
Performance/RegexpMatch:
239+
Enabled: true
240+
241+
Performance/ReverseEach:
242+
Enabled: true
243+
244+
Performance/UnfreezeString:
245+
Enabled: true

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ gem "acts_as_list"
5353
gem "cocoon"
5454

5555
gem "rubocop"
56-
gem "rubocop-rails_config"
5756
gem "rubocop-performance"

Gemfile.lock

+12-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
form_core (0.1.1)
5-
activeentity (>= 0.0.1.beta5)
5+
activeentity (>= 0.0.1.beta7)
66
rails (>= 6.0.0.rc1, < 7)
77

88
GEM
@@ -44,7 +44,7 @@ GEM
4444
erubi (~> 1.4)
4545
rails-dom-testing (~> 2.0)
4646
rails-html-sanitizer (~> 1.0, >= 1.0.3)
47-
activeentity (0.0.1.beta5)
47+
activeentity (0.0.1.beta7)
4848
activemodel (>= 6.0.0.beta3, < 7.0)
4949
activesupport (>= 6.0.0.beta3, < 7.0)
5050
activejob (6.0.0.rc1)
@@ -121,7 +121,7 @@ GEM
121121
nokogiri (1.10.3)
122122
mini_portile2 (~> 2.4.0)
123123
parallel (1.17.0)
124-
parser (2.6.2.1)
124+
parser (2.6.3.0)
125125
ast (~> 2.4.0)
126126
pry (0.12.2)
127127
coderay (~> 1.1.0)
@@ -131,7 +131,6 @@ GEM
131131
pry (~> 0.10)
132132
pry-rails (0.3.9)
133133
pry (>= 0.10.4)
134-
psych (3.1.0)
135134
puma (3.12.1)
136135
rack (2.0.7)
137136
rack-test (1.1.0)
@@ -167,19 +166,15 @@ GEM
167166
rb-fsevent (0.10.3)
168167
rb-inotify (0.10.0)
169168
ffi (~> 1.0)
170-
rubocop (0.67.2)
169+
rubocop (0.68.1)
171170
jaro_winkler (~> 1.5.1)
172171
parallel (~> 1.10)
173172
parser (>= 2.5, != 2.5.1.1)
174-
psych (>= 3.1.0)
175173
rainbow (>= 2.2.2, < 4.0)
176174
ruby-progressbar (~> 1.7)
177175
unicode-display_width (>= 1.4.0, < 1.6)
178-
rubocop-performance (1.1.0)
179-
rubocop (>= 0.67.0)
180-
rubocop-rails_config (0.5.1)
181-
railties (>= 3.0)
182-
rubocop (~> 0.60)
176+
rubocop-performance (1.2.0)
177+
rubocop (>= 0.68.0)
183178
ruby-progressbar (1.10.0)
184179
ruby_dep (1.5.0)
185180
sass (3.7.4)
@@ -204,7 +199,7 @@ GEM
204199
actionpack (>= 4.0)
205200
activesupport (>= 4.0)
206201
sprockets (>= 3.0.0)
207-
sqlite3 (1.4.0)
202+
sqlite3 (1.4.1)
208203
thor (0.20.3)
209204
thread_safe (0.3.6)
210205
tilt (2.0.9)
@@ -222,15 +217,15 @@ GEM
222217
unicode-display_width (1.5.0)
223218
validates_timeliness (5.0.0.alpha4)
224219
timeliness (>= 0.3.10, < 1)
225-
web-console (3.7.0)
226-
actionview (>= 5.0)
227-
activemodel (>= 5.0)
220+
web-console (4.0.0)
221+
actionview (>= 6.0.0.a)
222+
activemodel (>= 6.0.0.a)
228223
bindex (>= 0.4.0)
229-
railties (>= 5.0)
224+
railties (>= 6.0.0.a)
230225
websocket-driver (0.7.0)
231226
websocket-extensions (>= 0.1.0)
232227
websocket-extensions (0.1.3)
233-
zeitwerk (2.1.5)
228+
zeitwerk (2.1.6)
234229

235230
PLATFORMS
236231
ruby
@@ -250,7 +245,6 @@ DEPENDENCIES
250245
puma
251246
rubocop
252247
rubocop-performance
253-
rubocop-rails_config
254248
sassc-rails
255249
selectize-rails
256250
sprockets (~> 4.0.0.beta5)

form_core.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ Gem::Specification.new do |s|
2121

2222
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
2323

24-
s.add_dependency "activeentity", ">= 0.0.1.beta5"
24+
s.add_dependency "activeentity", ">= 0.0.1.beta7"
2525
s.add_dependency "rails", ">= 6.0.0.rc1", "< 7"
2626
end

test/dummy/app/presenters/fields/multiple_resource_field_presenter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def include_blank?
1010

1111
def value_for_preview
1212
return unless @model.collection
13+
return if @model.collection.none?
1314

1415
collection
1516
.where(@model.data_source.value_method => value)

test/dummy/app/presenters/fields/resource_field_presenter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Fields
44
class ResourceFieldPresenter < FieldPresenter
55
def value_for_preview
66
return unless @model.collection
7+
return if @model.collection.none?
78

89
id = value
910
return unless id.present?

test/dummy/app/views/_form_core/fields/_multiple_nested_form_field.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<%= tag.div id: field.name, class: "collection" do %>
55
<%= f.fields_for field.name do |ff| %>
6-
<%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form %>
6+
<%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form, nesting: false %>
77
<% end %>
88

99
<div class="links">
@@ -12,7 +12,7 @@
1212
class: "button is-small",
1313
partial: "_form_core/fields/nested_form",
1414
render_options: {
15-
locals: {field: field, form: field.nested_form}
15+
locals: {field: field, form: field.nested_form, nesting: true}
1616
} %>
1717
<% end %>
1818
<% if field.hint.present? %>

0 commit comments

Comments
 (0)