radius-spec 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,26 +1,66 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.5.0
2
+ TargetRubyVersion: 2.7.0
3
3
  Exclude:
4
4
  # Exclude generated binstubs
5
5
  - 'bin/bundle'
6
6
  - 'bin/bundler-travis'
7
+ - 'bin/pronto'
7
8
  - 'bin/pry'
9
+ - 'bin/radius-cli'
8
10
  - 'bin/rake'
9
11
  - 'bin/rspec'
10
12
  - 'bin/rubocop'
11
13
  - 'bin/travis'
14
+ - 'bin/webpack'
15
+ - 'bin/webpack-dev-server'
12
16
  - 'bin/yard'
17
+ - 'bin/yarn'
13
18
  # Exclude vendored content
14
19
  - 'vendor/**/*'
15
20
 
16
- # Modifiers should be indented as deep as method definitions, or as deep as the
17
- # class/module keyword, depending on configuration.
21
+ # We prefer outdented access modifiers as we feel they provide demarcation of
22
+ # the class similar to `rescue` and `ensure` in a method.
18
23
  #
19
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
24
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
20
25
  # SupportedStyles: outdent, indent
21
26
  Layout/AccessModifierIndentation:
27
+ Details: |
28
+
29
+ Prefer outdented access modifiers to provide demarcation of the class
30
+ similar to `rescue` and `ensure` in a method.
22
31
  EnforcedStyle: outdent
23
32
 
33
+ # Rubocop 0.60.0 changed how it handled value alignments in this cop. This
34
+ # breaks our preference for wanting keys to be aligned, but allowing values to
35
+ # either use the `key` or `table` style:
36
+ #
37
+ # key_style = {
38
+ # key: :value,
39
+ # another: :value,
40
+ # yet_another: :value
41
+ # }
42
+ # table_style = {
43
+ # key: :value,
44
+ # another: :value
45
+ # yet_another: :value
46
+ # }
47
+ #
48
+ # This is logged with Rubocop: https://github.com/rubocop-hq/rubocop/issues/6410
49
+ #
50
+ # Until Rubocop resolves this we've decided to enforce the key style so that we
51
+ # do not lose all associated formatting checks. Additionally, in response to
52
+ # the referenced issue the Rubocop disables the alignment check by default. To
53
+ # continue using it we force enable it here.
54
+ #
55
+ # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
56
+ # SupportedHashRocketStyles: key, separator, table
57
+ # SupportedColonStyles: key, separator, table
58
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
59
+ Layout/AlignHash:
60
+ Enabled: true
61
+ EnforcedHashRocketStyle: key
62
+ EnforcedColonStyle: key
63
+
24
64
  # Disabling this until it is fixed to support multi-line block chains using the
25
65
  # semantic style.
26
66
  #
@@ -34,12 +74,15 @@ Layout/BlockAlignment:
34
74
  # Disabling this until it is fixed to handle multi-line method chains where the
35
75
  # first method call is multi-line.
36
76
  #
37
- # See # https://github.com/bbatsov/rubocop/issues/5650
77
+ # See https://github.com/bbatsov/rubocop/issues/5650
38
78
  #
39
79
  # Configuration parameters: EnforcedStyle, IndentationWidth.
40
80
  # SupportedStyles: consistent, consistent_relative_to_receiver,
41
81
  # special_for_inner_method_call, special_for_inner_method_call_in_parentheses
42
- Layout/FirstParameterIndentation:
82
+ #
83
+ # TODO: At some point this is split into both Layout/FirstArgumentIndentation
84
+ # and Layout/FirstParameterIndentation
85
+ Layout/IndentFirstArgument:
43
86
  Enabled: false
44
87
 
45
88
  # This project only uses newer Ruby versions which all support the "squiggly"
@@ -51,14 +94,15 @@ Layout/FirstParameterIndentation:
51
94
  Layout/IndentHeredoc:
52
95
  EnforcedStyle: squiggly
53
96
 
54
- # We tend to indent multi-line operation statements. I think this is because
55
- # it's tends to be the default style auto-formatted by VIM (which many of us
56
- # use). It also helps show the continuation of the statement instead of it
97
+ # We tend to indent multi-line operation statements. I think this is because it
98
+ # tends to be the default style auto-formatted by VIM (which many of us use).
99
+ # It also helps show the continuation of the statement instead of it
57
100
  # potentially blending in with the start of the next statement.
58
101
  #
59
102
  # Configuration parameters: EnforcedStyle, IndentationWidth.
60
103
  # SupportedStyles: aligned, indented
61
104
  Layout/MultilineOperationIndentation:
105
+ Details: "This helps show expression continuation setting it apart from the following LOC."
62
106
  EnforcedStyle: indented
63
107
 
64
108
  # In our specs Rubocop inconsistently complains when using the block form of
@@ -83,7 +127,32 @@ Lint/AmbiguousBlockAssociation:
83
127
  Exclude:
84
128
  - 'spec/**/*_spec.rb'
85
129
 
86
- # Often with benchmarking we don't explictly "use" a variable or return value.
130
+ # We prefer to enforce a consistent usage for readability
131
+ #
132
+ # <<~SQL.strip
133
+ # bar
134
+ # SQL
135
+ #
136
+ # display(<<~SQL.strip)
137
+ # bar
138
+ # SQL
139
+ #
140
+ # Alternatively, refactoring the heredoc into a local also improves
141
+ # readability:
142
+ #
143
+ # custom_sql = <<~SQL
144
+ # bar
145
+ # SQL
146
+ # display(custom_sql.strip)
147
+ Lint/HeredocMethodCallPosition:
148
+ Enabled: true
149
+
150
+ # We prefer people suggesting people subclass `StandardError` for their custom
151
+ # exceptions as this is a relatively common Ruby idiom.
152
+ Lint/InheritException:
153
+ EnforcedStyle: standard_error
154
+
155
+ # Often with benchmarking we don't explicitly "use" a variable or return value.
87
156
  # We simply need to perform the operation which generates said value for the
88
157
  # benchmark.
89
158
  #
@@ -92,7 +161,17 @@ Lint/Void:
92
161
  Exclude:
93
162
  - 'benchmarks/**/*'
94
163
 
164
+ Metrics/AbcSize:
165
+ # TODO: When we are able to upgrade to Rubocop 1.5.0 we want to enable the
166
+ # following `CountRepeatedAttributes` option. We often find the
167
+ # multi-references to the same object to be necessary for reability and that
168
+ # for our team it does not increase complexity.
169
+ #
170
+ # CountRepeatedAttributes: false
171
+ Max: 17
172
+
95
173
  # Configuration parameters: CountComments, ExcludedMethods, Max.
174
+ # ExcludedMethods: refine
96
175
  Metrics/BlockLength:
97
176
  Exclude:
98
177
  - '**/Rakefile'
@@ -100,6 +179,12 @@ Metrics/BlockLength:
100
179
  - 'spec/spec_helper.rb'
101
180
  - 'spec/**/*_spec.rb'
102
181
  - 'spec/support/model_factories.rb'
182
+ ExcludedMethods:
183
+ - 'chdir'
184
+ - 'refine'
185
+ - 'Capybara.register_driver'
186
+ - 'RSpec.configure'
187
+ - 'VCR.configure'
103
188
 
104
189
  # We generally prefer to use the default line length of 80. Though sometimes
105
190
  # we just need a little extra space because it makes it easier to read.
@@ -133,6 +218,22 @@ Metrics/LineLength:
133
218
  # Attempt at trailing comments
134
219
  - '\A.{1,78}\s#\s.*\z'
135
220
  Max: 100
221
+ Exclude:
222
+ - '**/*.gemspec'
223
+
224
+ # TODO: Remove this when we get to 0.89.0 as the new default max is 8
225
+ #
226
+ # Configuration parameters: IgnoredMethods, Max
227
+ Metrics/PerceivedComplexity:
228
+ Max: 8
229
+
230
+ # This is overly pedantic (only allowing `other` as the parameter name). Ruby
231
+ # core doesn't follow this consistently either. Looking at several classes
232
+ # throughout Ruby core we do often see `other`, but also often `obj` or
233
+ # `other_*`. In some cases, the parameter is named more meaningfully with names
234
+ # like `real`, `numeric`, or `str`.
235
+ Naming/BinaryOperatorParameterName:
236
+ Enabled: false
136
237
 
137
238
  # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
138
239
  # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
@@ -148,11 +249,41 @@ Naming/FileName:
148
249
  # for those heredocs which represent "file" text.
149
250
  #
150
251
  # Configuration parameters: Blacklist.
151
- # Blacklist: END, (?-mix:EO[A-Z]{1})
252
+ # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
152
253
  Naming/HeredocDelimiterNaming:
254
+ Details: |
255
+
256
+ Use meaningful delimiter names to provide context to the text. The only
257
+ allowed `EO*` variant if `EOF` which has specific meaning for file content.
153
258
  Blacklist:
154
259
  - !ruby/regexp '/(^|\s)(EO[A-EG-Z]{1}|END)(\s|$)/'
155
260
 
261
+ # It is generally a good idea to match the instance variable names with their
262
+ # methods to keep consistent with the attribute reader / writer pattern.
263
+ # However, this can pose an issue in Rails. Most notably, when writing modules
264
+ # that will be used as controller plugins. The reason is that the Rails
265
+ # controllers-to-view interface is ivars. Using a leading underscore can help
266
+ # avoid accidental controller ivar naming conflicts.
267
+ #
268
+ # Configuration parameters: EnforcedStyleForLeadingUnderscores.
269
+ # SupportedStylesForLeadingUnderscores: disallowed, required, optional
270
+ Naming/MemoizedInstanceVariableName:
271
+ Details: |
272
+
273
+ It is generally a good idea to match the instance variable names with their
274
+ methods to keep consistent with the attribute reader / writer pattern. An
275
+ exception can be made for modules that want to avoid naming conflicts with
276
+ classes that include them. In this case a single leading underscore is
277
+ acceptable.
278
+ EnforcedStyleForLeadingUnderscores: optional
279
+
280
+ # We don't really care about this check. Sometimes using something simple such
281
+ # as `err` is just fine. Other times it may improve readability to have a more
282
+ # descriptive name. We feel this is a personal judgement call and not something
283
+ # that needs to be enforced.
284
+ Naming/RescuedExceptionsVariableName:
285
+ Enabled: false
286
+
156
287
  # `alias` behavior changes on scope. In general we expect the behavior to be
157
288
  # that which is defined by `alias_method`.
158
289
  #
@@ -161,6 +292,13 @@ Naming/HeredocDelimiterNaming:
161
292
  # Configuration parameters: EnforcedStyle.
162
293
  # SupportedStyles: prefer_alias, prefer_alias_method
163
294
  Style/Alias:
295
+ Details: |
296
+
297
+ Prefer `alias_method` because `alias` behavior changes based on scope.
298
+
299
+ See:
300
+ - https://stackoverflow.com/questions/4763121/should-i-use-alias-or-alias-method
301
+ - https://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html
164
302
  EnforcedStyle: prefer_alias_method
165
303
 
166
304
  # Keeping with our semantic style we allow use of `and` / `or` conditionals
@@ -175,6 +313,12 @@ Style/Alias:
175
313
  # Configuration parameters: EnforcedStyle.
176
314
  # SupportedStyles: always, conditionals
177
315
  Style/AndOr:
316
+ Details: |
317
+
318
+ Use `&&` / `||` for conditionals or general comparison. Use `and` / `or`
319
+ for control flow to provide additional semantic hints:
320
+
321
+ system("some command") or system("another command")
178
322
  EnforcedStyle: conditionals
179
323
 
180
324
  # These days most people have editors which support unicode and other
@@ -189,19 +333,23 @@ Style/AsciiComments:
189
333
  # - Prefer `{...}` over `do...end` for functional blocks.
190
334
  #
191
335
  # When the return value of the method receiving the block is important prefer
192
- # `{..}` over `do..end`.
336
+ # `{...}` over `do...end`.
193
337
  #
194
- # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods,
195
- # FunctionalMethods, IgnoredMethods.
338
+ # Some people enjoy the compact readability of `{...}` for one-liners so we
339
+ # allow that style as well.
340
+ #
341
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
196
342
  # SupportedStyles: line_count_based, semantic, braces_for_chaining
197
343
  Style/BlockDelimiters:
198
344
  Details: |
345
+
199
346
  Use semantic style for blocks:
200
347
  - Prefer `do...end` over `{...}` for procedural blocks.
201
348
  - Prefer `{...}` over `do...end` for functional blocks.
202
349
 
203
350
  When the return value of the method receiving the block is important prefer
204
351
  `{..}` over `do..end`.
352
+ AllowBracesOnProceduralOneLiners: true
205
353
  Enabled: true
206
354
  EnforcedStyle: semantic
207
355
  ProceduralMethods:
@@ -212,7 +360,13 @@ Style/BlockDelimiters:
212
360
  - realtime
213
361
  - with_object
214
362
  FunctionalMethods:
363
+ - create
364
+ - create!
365
+ - build
366
+ - build!
367
+ - default_scope
215
368
  - each_with_object
369
+ - filter_sensitive_data
216
370
  - find
217
371
  - git_source
218
372
  - let
@@ -226,6 +380,19 @@ Style/BlockDelimiters:
226
380
  - proc
227
381
  - it
228
382
 
383
+ # Prefer `Time` over `DateTime`.
384
+ #
385
+ # While these are not necessarily interchangeable we prefer `Time`. According
386
+ # to the Ruby docs `DateTime` is meant more for historical dates; it also does
387
+ # not consider leap seconds or summer time rules.
388
+ #
389
+ # Lastly, `DateTime` is part of the stdlib which is written in Ruby; where as
390
+ # `Time` is part of core and written in C.
391
+ #
392
+ # Configuration parameters: AllowCoercion
393
+ Style/DateTime:
394
+ Enabled: true
395
+
229
396
  # The double negation idiom is a common Ruby-ism. All languages have various
230
397
  # idioms and part of learning the language is learning the common idioms. Once
231
398
  # learning the meaning it is not cryptic as Rubocop implies.
@@ -303,6 +470,7 @@ Style/EmptyMethod:
303
470
  # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
304
471
  Style/HashSyntax:
305
472
  Details: |
473
+
306
474
  Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
307
475
  use a consistent mapping style; which generally means using hash rockets.
308
476
  EnforcedStyle: ruby19_no_mixed_keys
@@ -316,6 +484,7 @@ Style/HashSyntax:
316
484
  # SupportedStyles: line_count_dependent, lambda, literal
317
485
  Style/Lambda:
318
486
  Details: |
487
+
319
488
  As part of our semantic style we generally use the literal `-> { }` format
320
489
  to indicate this is a function with a return value we care about. As this
321
490
  cop doesn't have a more flexible setting we prefer the literal syntax to
@@ -335,9 +504,10 @@ Style/MethodCalledOnDoEndBlock:
335
504
  Style/MultilineBlockChain:
336
505
  Enabled: false
337
506
 
338
- # Context for this cop is too dependent. Often using the numeric comparision is
339
- # faster. An in certain contexts, Also, depending on the context a numeric
340
- # comparison is more consistent and can even be more natural:
507
+ # Context for this cop is too dependent.
508
+ #
509
+ # Often using the numeric comparison is faster. Also, depending on the context
510
+ # a numeric comparison may produce a more consistent style:
341
511
  #
342
512
  # # numeric comparison is more natural and consistent
343
513
  # if n < 0
@@ -350,6 +520,32 @@ Style/MultilineBlockChain:
350
520
  Style/NumericPredicate:
351
521
  Enabled: false
352
522
 
523
+ # In Ruby every method returns a value. Implicitly this is the value of the
524
+ # last line of the method. This means using `return` is often redundant.
525
+ # However, there isn't anything inherently wrong about doing so. In fact, in
526
+ # some cases it can help with a consistent style in a method:
527
+ #
528
+ # def transform(value)
529
+ # return value.call if value.is_a?(Proc)
530
+ # return value if value.frozen?
531
+ # return value.dup
532
+ # end
533
+ #
534
+ # Other times it can add context to a seemingly oddly place value:
535
+ #
536
+ # def munge(data)
537
+ # data.slice! 5
538
+ # return nil
539
+ # end
540
+ #
541
+ # We often omit the explicit `return` in our code. Though sometimes we include
542
+ # it for improved contextual clues and we don't want Rubocop to complain for
543
+ # those cases.
544
+ #
545
+ # Configuration parameters: AllowMultipleReturnValues.
546
+ Style/RedundantReturn:
547
+ Enabled: false
548
+
353
549
  # Prefer slashes for simple expressions. For multi-line use percent literal
354
550
  # to support comments and other advanced features. By using the mixed style we
355
551
  # are choosing to use `%r{}` for multi-line regexps. In general we are not a
@@ -366,6 +562,13 @@ Style/NumericPredicate:
366
562
  # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
367
563
  # SupportedStyles: slashes, percent_r, mixed
368
564
  Style/RegexpLiteral:
565
+ Details: |
566
+
567
+ Prefer slashes for simple expressions. Use `%r` for expressions containing
568
+ slashes and for complex expressions so then can be written across multiple
569
+ lines (allowing advanced features such as comments). Use of `%r` for
570
+ expressions spanning multiple lines provides some comprehension parity with
571
+ general code blocks.
369
572
  EnforcedStyle: mixed
370
573
 
371
574
  # If you only need to rescue a single, or predefined set of exceptions, then
@@ -407,13 +610,28 @@ Style/RegexpLiteral:
407
610
  # Configuration parameters: EnforcedStyle.
408
611
  # SupportedStyles: implicit, explicit
409
612
  Style/RescueStandardError:
613
+ Details: |
614
+
615
+ If you only need to rescue a single, or predefined set of exceptions, then
616
+ catch each exception explicitly. When you need to include a general error
617
+ handler or "catch-all" use the "unspecified rescue":
618
+
619
+ begin
620
+ # do something that may cause a standard error
621
+ rescue TypeError
622
+ handle_type_error
623
+ rescue => e
624
+ handle_error e
625
+ end
626
+
627
+ Avoid rescuing `Exception` as this may hide system errors.
410
628
  EnforcedStyle: implicit
411
629
 
412
630
  # We generally prefer double quotes but many generators use single quotes. We
413
631
  # don't view the performance difference to be all that much so we don't care
414
632
  # if the style is mixed or double quotes are used for static strings.
415
633
  #
416
- # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
634
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
417
635
  # SupportedStyles: single_quotes, double_quotes
418
636
  Style/StringLiterals:
419
637
  Enabled: false
@@ -440,7 +658,7 @@ Style/SymbolArray:
440
658
  MinSize: 3
441
659
 
442
660
  # When ternaries become complex they can be difficult to read due to increased
443
- # cognative load parsing the expression. Cognative load can increase further
661
+ # cognitive load parsing the expression. Cognitive load can increase further
444
662
  # when assignment is involved.
445
663
  #
446
664
  # Configuration parameters: EnforcedStyle, AllowSafeAssignment.
@@ -448,9 +666,10 @@ Style/SymbolArray:
448
666
  Style/TernaryParentheses:
449
667
  AllowSafeAssignment: false
450
668
  Details: |
669
+
451
670
  When ternaries become complex they can be difficult to read due to
452
- increased cognative load parsing the expression. Cognative load can
453
- increase further when assignment is involved. To help reduce this cognative
671
+ increased cognitive load parsing the expression. Cognitive load can
672
+ increase further when assignment is involved. To help reduce this cognitive
454
673
  use parentheses for complex expressions.
455
674
  EnforcedStyle: require_parentheses_when_complex
456
675
 
@@ -466,6 +685,7 @@ Style/TernaryParentheses:
466
685
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
467
686
  Style/TrailingCommaInArguments:
468
687
  Details: |
688
+
469
689
  Always use trailing commas for multiline arguments. This makes git diffs
470
690
  easier to read by cutting down on noise when commas are appended. It also
471
691
  simplifies adding, removing, and swapping argument orders.
@@ -480,6 +700,7 @@ Style/TrailingCommaInArguments:
480
700
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
481
701
  Style/TrailingCommaInArrayLiteral:
482
702
  Details: |
703
+
483
704
  Always use trailing commas for multiline arrays. This makes git diffs
484
705
  easier to read by cutting down on noise when commas are appended. It also
485
706
  simplifies adding, removing, and re-arranging the elements.
@@ -492,6 +713,7 @@ Style/TrailingCommaInArrayLiteral:
492
713
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
493
714
  Style/TrailingCommaInHashLiteral:
494
715
  Details: |
716
+
495
717
  Always use trailing commas for multiline hashes. This makes git diffs
496
718
  easier to read by cutting down on noise when commas are appended. It also
497
719
  simplifies adding, removing, and re-arranging the elements.