radius-spec 0.4.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ require_relative 'bm_setup'
5
5
 
6
6
  display_benchmark_header
7
7
 
8
- # rubocop:disable Performance/UnfreezeString
9
8
  section "Unfreezing empty string" do |bench|
10
9
  bench.report("String.new") do
11
10
  String.new
@@ -34,7 +33,6 @@ section "Unfreezing string" do |bench|
34
33
  STRING.dup
35
34
  end
36
35
  end
37
- # rubocop:enable Performance/UnfreezeString
38
36
 
39
37
  __END__
40
38
 
data/bin/ci CHANGED
@@ -15,7 +15,7 @@ bin/rspec
15
15
  # bundle-audit provides patch-level verification for Bundler
16
16
  # https://github.com/rubysec/bundler-audit.
17
17
  echo " ---> Running bundler-audit"
18
- gem install --no-rdoc --no-ri bundler-audit
18
+ gem install --no-document bundler-audit
19
19
  bundle-audit check --update
20
20
 
21
21
  # Run style checker
data/common_rubocop.yml CHANGED
@@ -1,15 +1,26 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.5.0
2
+ TargetRubyVersion: 2.7.0
3
+ # We choose to opt-in to new checks by default. This allows us to update
4
+ # version by version without having to worry about adding an entry for each
5
+ # new "enabled by default" check. If we want to jump multiple versions and
6
+ # wish to be notified of all the enw check, then we'll need to change
7
+ # `NewCops` to `pending.
8
+ NewCops: enable
3
9
  Exclude:
4
10
  # Exclude generated binstubs
5
11
  - 'bin/bundle'
6
12
  - 'bin/bundler-travis'
13
+ - 'bin/pronto'
7
14
  - 'bin/pry'
15
+ - 'bin/radius-cli'
8
16
  - 'bin/rake'
9
17
  - 'bin/rspec'
10
18
  - 'bin/rubocop'
11
19
  - 'bin/travis'
20
+ - 'bin/webpack'
21
+ - 'bin/webpack-dev-server'
12
22
  - 'bin/yard'
23
+ - 'bin/yarn'
13
24
  # Exclude vendored content
14
25
  - 'vendor/**/*'
15
26
 
@@ -25,6 +36,37 @@ Layout/AccessModifierIndentation:
25
36
  similar to `rescue` and `ensure` in a method.
26
37
  EnforcedStyle: outdent
27
38
 
39
+ # Rubocop 0.60.0 changed how it handled value alignments in this cop. This
40
+ # breaks our preference for wanting keys to be aligned, but allowing values to
41
+ # either use the `key` or `table` style:
42
+ #
43
+ # key_style = {
44
+ # key: :value,
45
+ # another: :value,
46
+ # yet_another: :value
47
+ # }
48
+ # table_style = {
49
+ # key: :value,
50
+ # another: :value
51
+ # yet_another: :value
52
+ # }
53
+ #
54
+ # This is logged with Rubocop: https://github.com/rubocop-hq/rubocop/issues/6410
55
+ #
56
+ # Until Rubocop resolves this we've decided to enforce the key style so that we
57
+ # do not lose all associated formatting checks. Additionally, in response to
58
+ # the referenced issue the Rubocop disables the alignment check by default. To
59
+ # continue using it we force enable it here.
60
+ #
61
+ # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
62
+ # SupportedHashRocketStyles: key, separator, table
63
+ # SupportedColonStyles: key, separator, table
64
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
65
+ Layout/HashAlignment:
66
+ Enabled: true
67
+ EnforcedHashRocketStyle: key
68
+ EnforcedColonStyle: key
69
+
28
70
  # Disabling this until it is fixed to support multi-line block chains using the
29
71
  # semantic style.
30
72
  #
@@ -43,7 +85,10 @@ Layout/BlockAlignment:
43
85
  # Configuration parameters: EnforcedStyle, IndentationWidth.
44
86
  # SupportedStyles: consistent, consistent_relative_to_receiver,
45
87
  # special_for_inner_method_call, special_for_inner_method_call_in_parentheses
46
- Layout/FirstParameterIndentation:
88
+ #
89
+ # TODO: At some point this is split into both Layout/FirstArgumentIndentation
90
+ # and Layout/FirstParameterIndentation
91
+ Layout/FirstArgumentIndentation:
47
92
  Enabled: false
48
93
 
49
94
  # This project only uses newer Ruby versions which all support the "squiggly"
@@ -52,9 +97,44 @@ Layout/FirstParameterIndentation:
52
97
  #
53
98
  # Configuration parameters: EnforcedStyle.
54
99
  # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
55
- Layout/IndentHeredoc:
100
+ Layout/HeredocIndentation:
56
101
  EnforcedStyle: squiggly
57
102
 
103
+ # We generally prefer to use the default line length of 80. Though sometimes
104
+ # we just need a little extra space because it makes it easier to read.
105
+ #
106
+ # The only way to disable Rubocop for a single line is either to wrap the line
107
+ # with two comments or append the disable comment to the end of the line. For
108
+ # guard clauses, we tend to prefer trailing comments to avoid adding two lines
109
+ # just to disable a cop on one line.
110
+ #
111
+ # Sometimes comments include ASCII diagrams, flow charts, etc. These cannot
112
+ # always be reformatted to fit within the 80 column limit. Also, we write most
113
+ # comments in markdown format. Rubocop isn't very good at understanding when
114
+ # the line is long because of a URL in a markdown link. Instead of requiring
115
+ # additional comments to turn this cop off for comments we ignore any long
116
+ # lines which are only comments.
117
+ #
118
+ # There are also cases where for one valid reason or another we have a trailing
119
+ # comment that extends a little too far. We'd like to be able to ignore those
120
+ # as well. This _attempts_ to do that, however, as this uses simple regular
121
+ # expressions we can only attempt to match so much. We probably should change
122
+ # this for a node pattern matcher in the future.
123
+ #
124
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes,
125
+ # IgnoreCopDirectives, IgnoredPatterns.
126
+ # URISchemes: http, https
127
+ Layout/LineLength:
128
+ IgnoreCopDirectives: true
129
+ IgnoredPatterns:
130
+ # Leading comments
131
+ - '\A\s*#'
132
+ # Attempt at trailing comments
133
+ - '\A.{1,78}\s#\s.*\z'
134
+ Max: 100
135
+ Exclude:
136
+ - '**/*.gemspec'
137
+
58
138
  # We tend to indent multi-line operation statements. I think this is because it
59
139
  # tends to be the default style auto-formatted by VIM (which many of us use).
60
140
  # It also helps show the continuation of the statement instead of it
@@ -88,6 +168,31 @@ Lint/AmbiguousBlockAssociation:
88
168
  Exclude:
89
169
  - 'spec/**/*_spec.rb'
90
170
 
171
+ # We prefer to enforce a consistent usage for readability
172
+ #
173
+ # <<~SQL.strip
174
+ # bar
175
+ # SQL
176
+ #
177
+ # display(<<~SQL.strip)
178
+ # bar
179
+ # SQL
180
+ #
181
+ # Alternatively, refactoring the heredoc into a local also improves
182
+ # readability:
183
+ #
184
+ # custom_sql = <<~SQL
185
+ # bar
186
+ # SQL
187
+ # display(custom_sql.strip)
188
+ Lint/HeredocMethodCallPosition:
189
+ Enabled: true
190
+
191
+ # We prefer people suggesting people subclass `StandardError` for their custom
192
+ # exceptions as this is a relatively common Ruby idiom.
193
+ Lint/InheritException:
194
+ EnforcedStyle: standard_error
195
+
91
196
  # Often with benchmarking we don't explicitly "use" a variable or return value.
92
197
  # We simply need to perform the operation which generates said value for the
93
198
  # benchmark.
@@ -97,6 +202,15 @@ Lint/Void:
97
202
  Exclude:
98
203
  - 'benchmarks/**/*'
99
204
 
205
+ Metrics/AbcSize:
206
+ # TODO: When we are able to upgrade to Rubocop 1.5.0 we want to enable the
207
+ # following `CountRepeatedAttributes` option. We often find the
208
+ # multi-references to the same object to be necessary for reability and that
209
+ # for our team it does not increase complexity.
210
+ #
211
+ # CountRepeatedAttributes: false
212
+ Max: 17
213
+
100
214
  # Configuration parameters: CountComments, ExcludedMethods, Max.
101
215
  # ExcludedMethods: refine
102
216
  Metrics/BlockLength:
@@ -106,39 +220,18 @@ Metrics/BlockLength:
106
220
  - 'spec/spec_helper.rb'
107
221
  - 'spec/**/*_spec.rb'
108
222
  - 'spec/support/model_factories.rb'
223
+ ExcludedMethods:
224
+ - 'chdir'
225
+ - 'refine'
226
+ - 'Capybara.register_driver'
227
+ - 'RSpec.configure'
228
+ - 'VCR.configure'
109
229
 
110
- # We generally prefer to use the default line length of 80. Though sometimes
111
- # we just need a little extra space because it makes it easier to read.
112
- #
113
- # The only way to disable Rubocop for a single line is either to wrap the line
114
- # with two comments or append the disable comment to the end of the line. For
115
- # guard clauses, we tend to prefer trailing comments to avoid adding two lines
116
- # just to disable a cop on one line.
117
- #
118
- # Sometimes comments include ASCII diagrams, flow charts, etc. These cannot
119
- # always be reformatted to fit within the 80 column limit. Also, we write most
120
- # comments in markdown format. Rubocop isn't very good at understanding when
121
- # the line is long because of a URL in a markdown link. Instead of requiring
122
- # additional comments to turn this cop off for comments we ignore any long
123
- # lines which are only comments.
124
- #
125
- # There are also cases where for one valid reason or another we have a trailing
126
- # comment that extends a little too far. We'd like to be able to ignore those
127
- # as well. This _attempts_ to do that, however, as this uses simple regular
128
- # expressions we can only attempt to match so much. We probably should change
129
- # this for a node pattern matcher in the future.
230
+ # TODO: Remove this when we get to 0.89.0 as the new default max is 8
130
231
  #
131
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes,
132
- # IgnoreCopDirectives, IgnoredPatterns.
133
- # URISchemes: http, https
134
- Metrics/LineLength:
135
- IgnoreCopDirectives: true
136
- IgnoredPatterns:
137
- # Leading comments
138
- - '\A\s*#'
139
- # Attempt at trailing comments
140
- - '\A.{1,78}\s#\s.*\z'
141
- Max: 100
232
+ # Configuration parameters: IgnoredMethods, Max
233
+ Metrics/PerceivedComplexity:
234
+ Max: 8
142
235
 
143
236
  # This is overly pedantic (only allowing `other` as the parameter name). Ruby
144
237
  # core doesn't follow this consistently either. Looking at several classes
@@ -161,14 +254,14 @@ Naming/FileName:
161
254
  # `EOF` is a common terminal abbreviate indicating end-of-file. We allow this
162
255
  # for those heredocs which represent "file" text.
163
256
  #
164
- # Configuration parameters: Blacklist.
165
- # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
257
+ # Configuration parameters: ForbiddenDelimiters.
258
+ # ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
166
259
  Naming/HeredocDelimiterNaming:
167
260
  Details: |
168
261
 
169
262
  Use meaningful delimiter names to provide context to the text. The only
170
263
  allowed `EO*` variant if `EOF` which has specific meaning for file content.
171
- Blacklist:
264
+ ForbiddenDelimiters:
172
265
  - !ruby/regexp '/(^|\s)(EO[A-EG-Z]{1}|END)(\s|$)/'
173
266
 
174
267
  # It is generally a good idea to match the instance variable names with their
@@ -190,6 +283,13 @@ Naming/MemoizedInstanceVariableName:
190
283
  acceptable.
191
284
  EnforcedStyleForLeadingUnderscores: optional
192
285
 
286
+ # We don't really care about this check. Sometimes using something simple such
287
+ # as `err` is just fine. Other times it may improve readability to have a more
288
+ # descriptive name. We feel this is a personal judgement call and not something
289
+ # that needs to be enforced.
290
+ Naming/RescuedExceptionsVariableName:
291
+ Enabled: false
292
+
193
293
  # `alias` behavior changes on scope. In general we expect the behavior to be
194
294
  # that which is defined by `alias_method`.
195
295
  #
@@ -239,7 +339,10 @@ Style/AsciiComments:
239
339
  # - Prefer `{...}` over `do...end` for functional blocks.
240
340
  #
241
341
  # When the return value of the method receiving the block is important prefer
242
- # `{..}` over `do..end`.
342
+ # `{...}` over `do...end`.
343
+ #
344
+ # Some people enjoy the compact readability of `{...}` for one-liners so we
345
+ # allow that style as well.
243
346
  #
244
347
  # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
245
348
  # SupportedStyles: line_count_based, semantic, braces_for_chaining
@@ -252,6 +355,7 @@ Style/BlockDelimiters:
252
355
 
253
356
  When the return value of the method receiving the block is important prefer
254
357
  `{..}` over `do..end`.
358
+ AllowBracesOnProceduralOneLiners: true
255
359
  Enabled: true
256
360
  EnforcedStyle: semantic
257
361
  ProceduralMethods:
@@ -266,7 +370,9 @@ Style/BlockDelimiters:
266
370
  - create!
267
371
  - build
268
372
  - build!
373
+ - default_scope
269
374
  - each_with_object
375
+ - filter_sensitive_data
270
376
  - find
271
377
  - git_source
272
378
  - let
@@ -280,6 +386,19 @@ Style/BlockDelimiters:
280
386
  - proc
281
387
  - it
282
388
 
389
+ # Prefer `Time` over `DateTime`.
390
+ #
391
+ # While these are not necessarily interchangeable we prefer `Time`. According
392
+ # to the Ruby docs `DateTime` is meant more for historical dates; it also does
393
+ # not consider leap seconds or summer time rules.
394
+ #
395
+ # Lastly, `DateTime` is part of the stdlib which is written in Ruby; where as
396
+ # `Time` is part of core and written in C.
397
+ #
398
+ # Configuration parameters: AllowCoercion
399
+ Style/DateTime:
400
+ Enabled: true
401
+
283
402
  # The double negation idiom is a common Ruby-ism. All languages have various
284
403
  # idioms and part of learning the language is learning the common idioms. Once
285
404
  # learning the meaning it is not cryptic as Rubocop implies.
@@ -341,6 +460,13 @@ Style/EmptyCaseCondition:
341
460
  Style/EmptyMethod:
342
461
  EnforcedStyle: expanded
343
462
 
463
+ # Always require the pragma comment to be true
464
+ #
465
+ # Configuration parameters: EnforcedStyle.
466
+ # SupportedStyles: always, always_true, never
467
+ Style/FrozenStringLiteralComment:
468
+ EnforcedStyle: always_true
469
+
344
470
  # Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
345
471
  # use a consistent mapping style; which generally means using hash rockets:
346
472
  #
@@ -391,9 +517,10 @@ Style/MethodCalledOnDoEndBlock:
391
517
  Style/MultilineBlockChain:
392
518
  Enabled: false
393
519
 
394
- # Context for this cop is too dependent. Often using the numeric comparison is
395
- # faster. An in certain contexts, Also, depending on the context a numeric
396
- # comparison is more consistent and can even be more natural:
520
+ # Context for this cop is too dependent.
521
+ #
522
+ # Often using the numeric comparison is faster. Also, depending on the context
523
+ # a numeric comparison may produce a more consistent style:
397
524
  #
398
525
  # # numeric comparison is more natural and consistent
399
526
  # if n < 0
@@ -1,3 +1,5 @@
1
+ require: rubocop-rails
2
+
1
3
  inherit_mode:
2
4
  merge:
3
5
  - Exclude
@@ -5,10 +7,6 @@ inherit_mode:
5
7
 
6
8
  inherit_from: common_rubocop.yml
7
9
 
8
- # Enable additional Rails cops
9
- Rails:
10
- Enabled: true
11
-
12
10
  AllCops:
13
11
  Exclude:
14
12
  - 'bin/puma'
@@ -22,24 +20,26 @@ AllCops:
22
20
  - 'db/migrate/**/*'
23
21
 
24
22
  # Rails project's are not concerned with API docs normally
25
- Documentation:
23
+ Style/Documentation:
26
24
  Enabled: false
27
25
 
28
- Metrics/BlockLength:
29
- Exclude:
30
- - 'config/routes.rb'
31
- - 'spec/rails_helper.rb'
32
-
33
26
  # Rails foreign keys and indexes can get long. We want to ignore our annotation
34
27
  # comments which are for these entries.
35
28
  #
36
29
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
37
30
  # URISchemes: http, https
38
- Metrics/LineLength:
31
+ Layout/LineLength:
39
32
  IgnoredPatterns:
40
33
  - '\A# fk_rails_'
41
34
  - '\A# index_'
42
35
 
36
+ Metrics/BlockLength:
37
+ Exclude:
38
+ - 'bin/setup'
39
+ - 'bin/update'
40
+ - 'config/routes.rb'
41
+ - 'spec/rails_helper.rb'
42
+
43
43
  # For our Rails apps several of them use the `respond_to` with `format` blocks
44
44
  # to handle various mime types (mostly HTML and JSON). Given our `do` / `end`
45
45
  # block style for non-functional blocks (which includes both `respond_to` and
@@ -106,6 +106,34 @@ Rails/ApplicationRecord:
106
106
  Rails/CreateTableWithTimestamps:
107
107
  Enabled: false
108
108
 
109
+ # Usage of `find_by` is more expressive of intent than `where.first`. We should
110
+ # check all app code, not just the models to improve intent expression.
111
+ #
112
+ # Since rake tasks often live in `lib` we also check all of lib as well.
113
+ #
114
+ # Configuration parameters: Include.
115
+ # Include: app/models/**/*.rb
116
+ Rails/FindBy:
117
+ Enabled: true
118
+ Include:
119
+ - 'app/**/*.rb'
120
+ - 'lib/**/*.rb'
121
+
122
+ # Usage of `each` for large datasets can be a performance issue; specially a
123
+ # drain on system memory. When possible it's better to use `find_each` so that
124
+ # chunks of data are evaluated at a time.
125
+ #
126
+ # We should check all app code, not just the models to help prevent this. Since
127
+ # rake tasks often live in `lib` we also check all of lib as well.
128
+ #
129
+ # Configuration parameters: Include.
130
+ # Include: app/models/**/*.rb
131
+ Rails/FindEach:
132
+ Enabled: true
133
+ Include:
134
+ - 'app/**/*.rb'
135
+ - 'lib/**/*.rb'
136
+
109
137
  # We understand the trade-offs for using the through model versus a lookup
110
138
  # table. As such this cop is just noise as it flags only those cases we really
111
139
  # do want a lookup table.
@@ -115,6 +143,37 @@ Rails/CreateTableWithTimestamps:
115
143
  Rails/HasAndBelongsToMany:
116
144
  Enabled: false
117
145
 
146
+ # We find the combo `:only` and `:if` readable. While the `:except` and `:if`
147
+ # combo is easier to read as a combined proc. As a team we are fine with
148
+ # handling this in PR reviews, until such time which Rubocop provides an option
149
+ # for us to configure this.
150
+ Rails/IgnoredSkipActionFilterOption:
151
+ Enabled: false
152
+
153
+ # We do not care about this check due to its lack of configuration.
154
+ #
155
+ # Some of the team finds the naming of this method is more confusing than using
156
+ # `each_with_object`. We all agree the other examples are bad and should not be
157
+ # used:
158
+ #
159
+ # # OK for us
160
+ # [1, 2, 3].each_with_object({}) { |el, h| h[foo(el)] = el }
161
+ #
162
+ # # Bad
163
+ # [1, 2, 3].to_h { |el| [foo(el), el] }
164
+ # [1, 2, 3].map { |el| [foo(el), el] }.to_h
165
+ # Hash[[1, 2, 3].collect { |el| [foo(el), el] }]
166
+ #
167
+ # If this check supports configuration in the future so that we can allow
168
+ # `each_with_object` then we'll turn it back on.
169
+ Rails/IndexBy:
170
+ Enabled: false
171
+
172
+ # We find the name of this method to be very confusing. We'd prefer this method
173
+ # is never used.
174
+ Rails/IndexWith:
175
+ Enabled: false
176
+
118
177
  # The ActiveSupport monkey patches for `present?` are nearly all defined as:
119
178
  #
120
179
  # !blank?
@@ -122,7 +181,7 @@ Rails/HasAndBelongsToMany:
122
181
  # For most of us `unless blank?` reads just as easily as `if present?`.
123
182
  # Sometimes contextually, it can read better depending on the branch logic and
124
183
  # surrounding context. As `if present?` requires an additional negation and
125
- # method call it is technically slower. In the general case the perf different
184
+ # method call it is technically slower. In the general case the perf difference
126
185
  # isn't much but in some cases it matters. Thus, we are not enforcing changing
127
186
  # `unless blank?` to `if present?` and are leaving it up to the context to
128
187
  # decide which is a better fit.
@@ -144,6 +203,37 @@ Rails/Present:
144
203
  Rails/ReadWriteAttribute:
145
204
  Enabled: false
146
205
 
206
+ # This ensures we do not ignore potential validation issues in the code. Doing
207
+ # so can lead to strange and surprising bugs where records are expected to
208
+ # be created, or be modified, but are not.
209
+ #
210
+ # # If author is a new record the book may not be created since the FK is
211
+ # # invalid. Perhaps omitting other fields, maybe new required fields, is
212
+ # # an oversight in the book creation as well.
213
+ # author.save
214
+ # Book.create(author: author)
215
+ #
216
+ # Or side effects are expected to occur but they do not:
217
+ #
218
+ # # This is a condensed default Rails scaffold controller for `destroy`.
219
+ # #
220
+ # # Once a `has_many` or `has_one` associations is added which specifies
221
+ # # `dependent: :restrict_with_error` this no longer behaves as expected.
222
+ # # Given such associations are often added much later in time errors in
223
+ # # this action are an all to common oversight in Rails.
224
+ # def destroy
225
+ # @book.destroy
226
+ # respond_to do |format|
227
+ # format.html do
228
+ # redirect_to books_url, notice: 'Book was successfully destroyed.'
229
+ # end
230
+ # end
231
+ # end
232
+ #
233
+ # Configuration parameters: AllowImplicitReturn, AllowedReceivers.
234
+ Rails/SaveBang:
235
+ Enabled: true
236
+
147
237
  # According to the Rails docs while the following methods skip validations they
148
238
  # only update the specified (single) attribute reducing risks. We'd rather not
149
239
  # warn for those cases:
@@ -161,17 +251,13 @@ Rails/ReadWriteAttribute:
161
251
  # - http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html
162
252
  # - http://api.rubyonrails.org/classes/ActiveRecord/Relation.html
163
253
  #
254
+ # Configuration parameters: Blacklist, Whitelist.
164
255
  # Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
165
256
  Rails/SkipsModelValidations:
166
- Blacklist:
167
- - 'decrement_counter'
168
- - 'increment_counter'
169
- - 'toggle!'
170
- - 'update_all'
171
- - 'update_attribute'
172
- - 'update_column'
173
- - 'update_columns'
174
- - 'update_counters'
257
+ Whitelist:
258
+ - 'decrement!'
259
+ - 'increment!'
260
+ - 'touch'
175
261
 
176
262
  # Rails uses compact style by default so we're disabling this with a :hammer:
177
263
  # for things likely to be generated by Rails (i.e. most things in app).